In this code (fabricated) sequence, ages_by_bind compiles, but ages_by_lambda
does not.
I believe this is because the lambda version does not publish result_type to its
resultant functors, since the increased generality of lambda makes this difficult
or impossible to do.
Is there any way I can get round this, as it currently makes the lambda/transformed
combination completely unusable AFAICS.
Thx,
- Rob.
#include <map>
#include <vector>
#include <string>
#include <boost/bind.hpp>
#include <boost/range.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
std::vector<int> ages_by_bind( const std::map<std::string, int> & people )
{
using boost::adaptors::transformed;
std::vector<int> result;
boost::range::push_back( result, people | transformed( bind( & std::map<std::string, int>::value_type::second, _1 ) ) );
return result;
}
std::vector<int> ages_by_lambda( const std::map<std::string, int> & people )
{
using boost::adaptors::transformed;
namespace ll = boost::lambda;
std::vector<int> result;
boost::range::push_back( result, people | transformed( ll::bind( & std::map<std::string, int>::value_type::second, ll::_1 ) ) );
return result;
}