
Aleksey Gurtovoy wrote:
David Abrahams wrote:
I just tried using the lambda library for the first time. Here's what came out of it, after some struggle:
#include <boost/lambda/lambda.hpp> #include <vector> #include <numeric>
using namespace boost::lambda;
struct X { X() : count(1) {}
unsigned long count; };
std::vector<X> xs(10); unsigned long n = std::accumulate( xs.begin(), xs.end(), 0UL, _1 + (&_2) ->* &X::count);
Views make it much cleaner, both conceptually and syntactically:
unsigned long n = accumulate( transform_view( xs, mem_fn(&X::count) ) , 0UL );
Indeed ;) Using views/ranges makes the code much simpler/clearer. In time, I've accepted the fact that there's not much point in using in-place functions (like _1 + _2, etc.), since in real-life they just complicate the code. So I just create a new function (in anonymous namespace), and that's it. And I use boost::bind, which rocks big time :D My $0.02 Best, John