[lambda] Boost.Bind works, labmda bind fails to compile
Hello, Could someone please explain the following behavior: #include <boost/lambda/bind.hpp> #include <boost/bind.hpp> struct Functor { void operator()() const {} template<class T> void func(T t) {} }; int main() { Functor f; boost::lambda::bind(&Functor::func<Functor>, &f, f); // doesn't compile boost::bind(&Functor::func<Functor>, &f, f); // compiles well } Thanks!
On Wed, Dec 30, 2009 at 7:14 AM, Igor R <boost.lists@gmail.com> wrote:
Hello,
Could someone please explain the following behavior:
#include <boost/lambda/bind.hpp> #include <boost/bind.hpp>
struct Functor { void operator()() const {} template<class T> void func(T t) {} };
int main() { Functor f; boost::lambda::bind(&Functor::func<Functor>, &f, f); // doesn't compile boost::bind(&Functor::func<Functor>, &f, f); // compiles well }
Does it work with Boost.Phoenix? Boost.Phoenix includes the functionality of both and a great deal more. I have not tried this, but curious if it works for you: #include <boost/spirit/home/phoenix/bind/bind_function.hpp> #include <boost/lambda/bind.hpp> #include <boost/bind.hpp> struct Functor { void operator()() const {} template<class T> void func(T t) {} }; int main() { Functor f; boost::phoenix::bind(&Functor::func<Functor>, &f, f); // Does this compile? boost::lambda::bind(&Functor::func<Functor>, &f, f); // doesn't compile boost::bind(&Functor::func<Functor>, &f, f); // compiles well }
boost::phoenix::bind(&Functor::func<Functor>, &f, f); // Does this compile?
No it doesn't, with errors very similar to those of lambda: error C2780: 'boost::phoenix::actor<as_composite<boost::phoenix::detail::function_eval<9>,boost::phoenix::detail::function_ptr<9,RT,RT(__cdecl *)(T0,T1,T2,T3,T4,T5,T6,T7,T8)>,A0,A1,A2,A3,A4,A5,A6,A7,A8>::type> boost::phoenix::bind(RT (__cdecl *)(T0,T1,T2,T3,T4,T5,T6,T7,T8),const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &,const A6 &,const A7 &,const A8 &)' : expects 10 arguments - 3 provided etc...
Another strange behavior: struct Functor { void func1() const {} }; int main() { boost::shared_ptr<Functor> pf1; Functor *pf2; boost::function<void(void)> f1 = boost::bind(&Functor::func1, pf1); // boost.bind with shared_ptr and store in function - OK boost::lambda::bind(&Functor::func1, pf1); // labmda bind with shared_ptr - OK boost::function<void(void)> f2 = boost::lambda::bind(&Functor::func1, pf2); // lambda bind with regular ptr and store in function - OK boost::function<void(void)> f3 = boost::lambda::bind(&Functor::func1, pf1); // lambda bind with shared_ptr and store in function - FAILS } Phoenix behaves the same way.
Igor R wrote:
Another strange behavior:
...
boost::function<void(void)> f3 = boost::lambda::bind(&Functor::func1, pf1); // lambda bind with shared_ptr and store in function - FAILS
I suspect that you need to dereference the shared_ptr with lambda... *constant(pf1). It doesn't treat smart pointers as a special case in the same way boost::bind does.
AMDG Igor R wrote:
Could someone please explain the following behavior:
#include <boost/lambda/bind.hpp> #include <boost/bind.hpp>
struct Functor { void operator()() const {} template<class T> void func(T t) {} };
int main() { Functor f; boost::lambda::bind(&Functor::func<Functor>, &f, f); // doesn't compile boost::bind(&Functor::func<Functor>, &f, f); // compiles well }
It ICEs in a bizarre way for me with the trunk and msvc 9.0. In Christ, Steven Watanabe
Igor R wrote:
Hello,
Could someone please explain the following behavior:
#include <boost/lambda/bind.hpp> #include <boost/bind.hpp>
struct Functor { void operator()() const {} template<class T> void func(T t) {} };
int main() { Functor f; boost::lambda::bind(&Functor::func<Functor>, &f, f); // doesn't compile boost::bind(&Functor::func<Functor>, &f, f); // compiles well }
Sounds like a bug in MSVC. struct Functor { template<class T> void func(T t) {} }; template<class A1, class A2, class A3> void ll_bind( A1 const & a1, A2 const & a2, A3 const & a3 ) { } int main() { Functor f; ll_bind( &Functor::func<Functor>, &f, f ); // fails }
participants (4)
-
Igor R
-
OvermindDL1
-
Peter Dimov
-
Steven Watanabe