I have been trying to fill a vector from a map. I know how to do this in a more conventional way, but I was trying to achive it with STL algorithms (a one liner) as some kind of a training :).
the origin map type is :
std::map< std::string, boost::shared_ptr< Element > >
the destination vector is :
std::vector< Element > theVector;
what I have so far is this:
std::transform( theMap.begin(), theMap.end(),
std::back_inserter( theVector ),
boost::bind( &map_type::value_type::second_type::get, _1 )
);
But this is trying to insert a pointer in the vector which doesn't work. I have also tried this:
using namespace boost::lambda;
using boost::lambda::_1;
std::transform( theMap.begin(), theMap.end(),
std::back_inserter( theVector ),
boost::bind( &map_type::value_type::second_type::get, *_1 )
);
But it's not working either.
Edit:
I've got this working solution but I find it less impressive :)
std::for_each( theMap.begin(), theMap.end(),
[&](map_type::value_type& pair)
{
theVector.push_back( *pair.second );
} );
Edit2: The thing I'm the less comfortable with here is bind(), so bind() solutions are welcome!