std::for_each(M.begin(), M.end(), std::cout << l::bind(select2nd(), l::_1) << " "); Well, that's too complicated ;-) _binding_ to a function or functor is the approach I wanted to avoid. I think that select1st and select2nd (or - to be generic - select<n>) could be directly supported by boost::lambda. It's so common to have a list/vector of tuples or a std::map (yes, its a request for a feature ;-))
Peter suggested a nice solution.
For completeness, below is the ll_select_2nd solution.
There are many ways to do it, but maybe the cleanest is to add a
wrapper function that does the same as bind(select2nd, ...).
That is, you need to write the function object, which was in the
previous posting (I'll repeat it here too), and then a wrapper
function that makes the results of
bind(select2nd, ...) and ll_select_2nd(...) equal.
Cheers, Jaakko
PS. There is very little documentation on the functor conventions.
This will all change in the future, as bind proposal is now part of
the standard TR, and the conventions are spelled out there. They are
different from the current lambda though.
Here's the code:
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
#include <algorithm>
#include <map>
#include <iostream>
// A function object class that takes returns a second argument of a pair.
// This can be used with bind.
namespace boost {
namespace lambda {
struct select2nd {
// Tell LL how to get the return type. Args will be tuple