std::map::iterator with STL algorithms

R

rg

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
 
T

tom_usenet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top