Boost logo

Boost Users :

Subject: [Boost-users] [Lambda] Handling Bind/Lambda name clashes.
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-04-05 08:06:41

Im compiling in an environment which #includes <boost::bind.hpp>, so I can't
away from it! I'd like to use Boost.Lambda sometimes, but run into namespace

This code snippet works...

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/range.hpp>
#include <vector>
#include <numeric>

// and also this...
#include <boost/bind.hpp>

struct X
    int f( ) const { return 1; }

int sum( int a, int b ) { return a + b; }

int main( )
    boost::lambda::placeholder1_type x;
    boost::lambda::placeholder2_type y;

    std::vector<X> v;

    std::accumulate( boost::begin( v ), boost::end( v ), 0, bind( sum, x,
bind( &X::f, y ) ) );

but as soon as I extract the innermost bind into a Boost.Function, I seem to
need to fully
qualify all the binds, ie

int main( )
    boost::lambda::placeholder1_type x;
    boost::lambda::placeholder2_type y;

    std::vector<X> v;

    boost::function<int(int, int)> my_sum = bind( sum, x, y );

    std::accumulate( boost::begin( v ), boost::end( v ), 0,
boost::lambda::bind( my_sum, x, bind( &X::f, y ) ) );

Is there any easy way around this? It would be nice to able to name my inner
binds in a meaningful way, but all the
explicit qualification gets a bit cumbersome!


- Rob.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at