
6 Mar
2004
6 Mar
'04
10:10 a.m.
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 ); -- Aleksey Gurtovoy MetaCommunications Engineering