Connecting Tech Pros Worldwide Forums | Help | Site Map

std::map::iterator with STL algorithms

rg
Guest
 
Posts: n/a
#1: Jul 22 '05
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
Guest
 
Posts: n/a
#2: Jul 22 '05

re: std::map::iterator with STL algorithms


On Thu, 22 Jul 2004 07:45:32 +0100, "rg" <rg1117@hotmail.com> wrote:
[color=blue]
>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.[/color]

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
Closed Thread