|
Boost Users : |
Subject: [Boost-users] [Range & c++0x Lambdas] Can this be done?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2012-11-21 08:39:58
Can the last line, labelled NOT Ok, be made to work? I think the lambda does
not publish its result as a bind does, so I suspect it's hopeless. Any
thoughts?
Thx, Rob.
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/bind.hpp>
#include <vector>
#include <algorithm>
struct S { int i; };
void f( std::vector<int> & out, std::vector<S> & in )
{
using boost::adaptors::transformed;
// Ok
std::transform( in.begin( ), in.end( ), std::back_inserter( out ),
bind( & S::i, _1 ) );
// Ok
boost::range::push_back( out, in | transformed( bind( & S::i, _1 ) ) );
// Ok
std::transform( in.begin( ), in.end( ), std::back_inserter( out ), [](
S & s ) { return s.i; } );
// NOT Ok
boost::range::push_back( out, in | transformed( []( S & s ) { return
s.i; } ) );
}
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