Boost logo

Boost Users :

Subject: Re: [Boost-users] [range] for_each and std::map of std::list
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-04-06 13:55:20


Den 06-04-2011 16:03, Mark Snelling skrev:
> Hi,
>
> Consider a map defined as...
>
> std::map< int, std::list< std::string > > my_map;
>
> I'm wondering if/how it's possible to use Boost.Range to call a function
> on each std::string in each of the lists contained in the map. I have an
> implementation below which works using a C++0x lambda function but am
> curious if this can be done purely using Boost.Range?
>
> boost::for_each(
> boost::adaptors::values( my_map),
> []( const std::list< std::string >& my_list ) { boost::for_each(
> my_list, some_func ); } );
>
> ideas anyone?

What we need is a generic range adaptor that can make a container of
containers look like a "flat" sequence.

I suggest the syntax

   rngOfContainers | boost::adaptors::flattened

and the underlying iterator should be up to bidirectional (if the
underlying two container types support it).

Anyone interested in implementing this?

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net