Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   std::map::iterator with STL algorithms (http://www.velocityreviews.com/forums/t284527-std-map-iterator-with-stl-algorithms.html)

rg 07-22-2004 06:45 AM

std::map::iterator with STL algorithms
 
Dear all,

I was wondering whether there was a C++ STL compliant way of using std::map
iterators with the standard STL algorithms. I know there is the select1st
and select2nd adaptors but they are not part of the C++ standard.

I'm assuming that people will have met this problem before, what kind of
solutions do you normally use for it?

I could always create custom algorithms to be used specifically with maps
but I want to avoid this so that I can still use my map containers with the
existing supply of C++ algorithms.

Any help would be greatly appreciated. Many Thanks in advance.

RG



tom_usenet 07-22-2004 10:31 AM

Re: std::map::iterator with STL algorithms
 
On Thu, 22 Jul 2004 07:45:32 +0100, "rg" <rg1117@hotmail.com> wrote:

>Dear all,
>
>I was wondering whether there was a C++ STL compliant way of using std::map
>iterators with the standard STL algorithms. I know there is the select1st
>and select2nd adaptors but they are not part of the C++ standard.
>
>I'm assuming that people will have met this problem before, what kind of
>solutions do you normally use for it?
>
>I could always create custom algorithms to be used specifically with maps
>but I want to avoid this so that I can still use my map containers with the
>existing supply of C++ algorithms.
>
>Any help would be greatly appreciated. Many Thanks in advance.


The best approach is to use projection iterators combined with
select1st and select2nd. See transform_iterator at
http://www.boost.org/libs/iterator/doc/index.html. Unfortunately, they
don't include an off the shelf pair_first and pair_second iterator,
even though that is one of the most common needs for this kind of
thing.

Tom


All times are GMT. The time now is 12:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.