Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2004-03-06 05:10:03


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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk