using transform_iterator to iterate through the values of a std::map
Hi, This is probably a very newbie question. I'd like to iterate through the values of a std::map. I searched through the archives, and found this thread on this mailing list about it: http://lists.boost.org/boost-users/2007/11/32374.php Unfortunately I can't put the partial recommendations together from that thread to work for me. While this is most probably due to my lack of experience with boost, can someone point to a sort-of complete usage solution to this question? Would be really appreciated. Akos
Note that the serialization library uses the transform iterator in "real world" code. And there are test of the iterators used by the library which might serve as examples on how to user them. Robert Ramey Ákos Maróy wrote:
Hi,
This is probably a very newbie question. I'd like to iterate through the values of a std::map. I searched through the archives, and found this thread on this mailing list about it:
http://lists.boost.org/boost-users/2007/11/32374.php
Unfortunately I can't put the partial recommendations together from that thread to work for me. While this is most probably due to my lack of experience with boost, can someone point to a sort-of complete usage solution to this question? Would be really appreciated.
Akos
Robert Ramey wrote:
Note that the serialization library uses the transform iterator in "real world" code. And there are test of the iterators used by the library which might serve as examples on how to user them.
hm, I did a search within /usr/include/boost/serialization, and did not find any references to transform_iterator. anyway, if there would be a complete example somewhere, I'd be extremely greatful... the example on the transform_iterator documentation page is partial, for example, it does not define a complet example. when I try to use the sample given here: http://lists.boost.org/boost-users/2007/11/32410.php , I get the following error: no type named ‘result_type’ in 'struct get_pair_value' I complete working example would really be appreciated. Akos
Ákos Maróy wrote:
Robert Ramey wrote:
Note that the serialization library uses the transform iterator in "real world" code. And there are test of the iterators used by the library which might serve as examples on how to user them.
hm, I did a search within /usr/include/boost/serialization, and did not find any references to transform_iterator.
anyway, if there would be a complete example somewhere, I'd be extremely greatful... the example on the transform_iterator documentation page is partial, for example, it does not define a complet example. when I try to use the sample given here: http://lists.boost.org/boost-users/2007/11/32410.php , I get the following error:
no type named ‘result_type’ in 'struct get_pair_value'
I complete working example would really be appreciated.
As described in http://www.boost.org/doc/libs/1_35_0/libs/iterator/doc/transform_iterator.ht..., your UnaryFunction needs to support result_of // untested #include "boost/type_traits/remove_reference.hpp" #include "boost/type_traits/remove_const.hpp" struct get_pair_value { template < class P > struct result { typedef typename boost::remove_const< typename boost::remove_reference<P>::type >::type::second_type type; }; template< typename K, typename V > V operator()( std::pair< K, V > const& pr ) { return pr.second; } }; Sorry that's so complicated; result_of ought to be easier to use than it is. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (4)
-
Alan M. Carroll
-
David Abrahams
-
Robert Ramey
-
Ákos Maróy