On Tue, Apr 5, 2011 at 2:06 PM, Robert Jones
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
#include #include #include <vector> #include <numeric> // and also this... #include 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 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.