Boost logo

Boost Users :

Subject: Re: [Boost-users] [Lambda] Handling Bind/Lambda name clashes.
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2011-04-05 09:19:22


On Tue, Apr 5, 2011 at 2:06 PM, Robert Jones <robertgbjones_at_[hidden]> wrote:
> Im compiling in an environment which #includes <boost::bind.hpp>, so I can't
> get
> away from it! I'd like to use Boost.Lambda sometimes, but run into namespace
> clashes.
> 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!
> Thx
> - Rob.

Your testcase works me.
Do you have a "using namespace boost;" somewhere in your headers?
Putting a "using boost::lambda::bind;" before your calls to bind works
for me, if you answered the previous question with yes.


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