Connecting Tech Pros Worldwide Help | Site Map

std::map::iterator with STL algorithms

  #1  
Old July 22nd, 2005, 05:45 PM
rg
Guest
 
Posts: n/a
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


  #2  
Old July 22nd, 2005, 05:45 PM
tom_usenet
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
When is std::list more effective than the other containers? Josh Mcfarlane answers 44 December 16th, 2005 04:55 PM
Problem with distance and STL map tron.thomas@verizon.net answers 2 September 13th, 2005 11:45 PM
Alternatives to the C++ Standard Library? Steven T. Hatton answers 43 July 23rd, 2005 06:52 AM
Nodes with unlimited children. Jeff Relf answers 47 July 22nd, 2005 06:32 PM