Connecting Tech Pros Worldwide Help | Site Map

std::map::iterator with STL algorithms

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 04:45 PM
rg
Guest
 
Posts: n/a
Default 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



  #2  
Old July 22nd, 2005, 04:45 PM
tom_usenet
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.