[Boost-bugs] [Boost C++ Libraries] #5645: Problem passing lambda functor to boost::bind - code does not compile

Subject: [Boost-bugs] [Boost C++ Libraries] #5645: Problem passing lambda functor to boost::bind - code does not compile
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-06-27 13:08:29


#5645: Problem passing lambda functor to boost::bind - code does not compile
------------------------------+---------------------------------------------
 Reporter: anonymous | Owner: pdimov
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: bind
  Version: Boost 1.45.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 I want to create lambda functor for function with more that 3 parameters.
 I need to access 1 param only, so I decided to use helper functor created
 wih boost::bind. Unfortunately code does not compile. But when I stored
 created lambda functor in boost::function object, it compiles fine.
 {{{
 #include <boost/lambda/lambda.hpp>
 #include <boost/lambda/bind.hpp>
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
 #include <iostream>

 using namespace boost::lambda;

 boost::lambda::placeholder1_type _l1;
 boost::lambda::placeholder2_type _l2;

 boost::arg<1> _b1;
 boost::arg<4> _b4;

 class IFoo
 {
 public:
     virtual ~IFoo() {}
     virtual void bar(int a, int b, int c, int d) = 0;
 };

 class Foo : public IFoo
 {
 public:
     boost::function<void(int, int, int, int)> bar_hook;

     void bar(int a, int b, int c, int d)
     {
         if (bar_hook)
             bar_hook(a, b, c, d);
     }
 };

 int main()
 {
     Foo foo;
     int a = -1;

     // This works fine
     boost::function<void(int, int)> tmp_func = (_l2, var(a) = _l1);
     foo.bar_hook = boost::bind(tmp_func, _b1, _b4);

     // This fails to compile
     //foo.bar_hook = boost::bind( (_l2, var(a) = _l1), _b1, _b4 );

     foo.bar(1, 2, 3, 4);
     std::cout << "a = " << a << std::endl;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5645>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC