title: How to write boost::lambda expression as function callback argument
body: <p>Suppose I have the following code:</p>
  
  <pre><code>    #include &lt;boost/lambda/lambda.hpp&gt;
      #include &lt;boost/lambda/bind.hpp&gt;
      #include &lt;boost/function.hpp&gt;
      #include &lt;list&gt;                                                                                                                                                         
  
      class MyListChild
      {
      };
  
      struct Filter
      {
        bool matches(MyListChild&amp; child){ return true;}
      };
  
  
      class MyList 
      {
        public:
          typedef boost::function&lt;bool(MyListChild&amp;)&gt; FilterCallback;
          // A common function that using any callback
          void filterChild(FilterCallback filter, std::list&lt;MyListChild&gt; list)
          {
            //... loop in children element
            MyListChild child;
            //filtering the child
            if(filter(child)) list.push_back(child);
          }
          // A specific function that using a custom filter
          void filterChild(const Filter&amp; filter, std::list&lt;MyListChild&gt; list)
          {
            using namespace boost::lambda;
            //Trying to use the common function above
            filterChild(bind(&amp;Filter::matches, filter, _1), list); //This will not compile.
          }
      };
      int main()
      {
  
        return 0;
      }
  </code></pre>
  
  <p>And the compiler errors are:</p>
  
  <pre><code>    || /usr/include/boost/lambda/detail/actions.hpp: In instantiation of ‘static RET boost::lambda::function_action&lt;3, T&gt;::apply(A1&amp;, A2&amp;, A3&amp;) [with RET = bool; A1 = bool (Filter::* const)(MyListChild&amp;); A2 = const Filter; A3 = MyListChild; T = boost::lambda::detail::unspecified]’:
      /usr/include/boost/lambda/detail/lambda_functor_base.hpp|441 col 5| required from ‘RET boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, Act&gt;, Args&gt;::        call(A&amp;, B&amp;, C&amp;, Env&amp;) const [with RET = bool; A = MyListChild; B = const boost::tuples::null_type; C = const boost::tuples::null_type; Env = const boost::tuples::null_type;   Act = boost::lambda::function_action&lt;3&gt;; Args = boost::tuples::tuple&lt;bool (Filter::* const)(MyListChild&amp;), const Filter, const boost::lambda::lambda_functor&lt;boost::lambda::    placeholder&lt;1&gt; &gt;, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,   boost::tuples::null_type&gt;]’
      /usr/include/boost/lambda/detail/lambda_functors.hpp|195 col 50| required from ‘typename boost::lambda::lambda_functor&lt;Base&gt;::inherited::sig&lt;boost::tuples::tuple&lt;A&amp;&gt;   &gt;::type boost::lambda::lambda_functor&lt;Base&gt;::operator()(A&amp;) const [with A = MyListChild; T = boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::        function_action&lt;3&gt; &gt;, boost::tuples::tuple&lt;bool (Filter::* const)(MyListChild&amp;), const Filter, const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;1&gt; &gt;, boost::     tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type&gt;  &gt;; typename boost::lambda::lambda_functor&lt;Base&gt;::inherited::sig&lt;boost::tuples::tuple&lt;A&amp;&gt; &gt;::type = bool]’                                                                       
      /usr/include/boost/function/function_template.hpp|132 col 42| required from ‘static R boost::detail::function::function_obj_invoker1&lt;FunctionObj, R, T0&gt;::invoke(boost::detail::function::function_buffer&amp;, T0) [with FunctionObj = boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::           function_action&lt;3&gt; &gt;, boost::tuples::tuple&lt;bool (Filter::* const)(MyListChild&amp;), const Filter, const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;1&gt; &gt;, boost::     tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type&gt;  &gt; &gt;; R = bool; T0 = MyListChild&amp;]’
      /usr/include/boost/function/function_template.hpp|934 col 38| required from ‘void boost::function1&lt;R, T1&gt;::assign_to(Functor) [with Functor = boost::lambda::           lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3&gt; &gt;, boost::tuples::tuple&lt;bool (Filter::* const)(MyListChild&amp;),      const Filter, const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;1&gt; &gt;, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type&gt; &gt; &gt;; R = bool; T0 = MyListChild&amp;]’
      /usr/include/boost/function/function_template.hpp|722 col 7| required from ‘boost::function1&lt;R, T1&gt;::function1(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3,       boost::lambda::function_action&lt;3&gt; &gt;, boost::tuples::tuple&lt;bool (Filter::* const)(MyListChild&amp;), const Filter, const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;1&gt; &gt;, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::  null_type&gt; &gt; &gt;; R = bool; T0 = MyListChild&amp;; typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’
      /usr/include/boost/function/function_template.hpp|1069 col 16| required from ‘boost::function&lt;R(T0)&gt;::function(Functor, typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type) [with Functor = boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3,       boost::lambda::function_action&lt;3&gt; &gt;, boost::tuples::tuple&lt;bool (Filter::* const)(MyListChild&amp;), const Filter, const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;1&gt; &gt;, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::  null_type&gt; &gt; &gt;; R = bool; T0 = MyListChild&amp;; typename boost::enable_if_c&lt;boost::type_traits::ice_not&lt;boost::is_integral&lt;Functor&gt;::value&gt;::value, int&gt;::type = int]’
      test.cc|33 col 59| required from here
      /usr/include/boost/lambda/detail/actions.hpp|96 col 37| error: no matching function for call to ‘boost::lambda::function_adaptor&lt;bool (Filter::*)(MyListChild&amp;)&gt;::      apply(bool (Filter::* const&amp;)(MyListChild&amp;), const Filter&amp;, MyListChild&amp;)’
      ||        template apply&lt;RET&gt;(a1, a2, a3);
      ||                                      ^
      /usr/include/boost/lambda/detail/actions.hpp|96 col 37| note: candidates are:
      /usr/include/boost/lambda/detail/function_adaptors.hpp|394 col 17| note: template&lt;class RET, class A1&gt; static Result boost::lambda::function_adaptor&lt;Result (Object::*  )(Arg1)&gt;::apply(Result (Object::*)(Arg1), Object*, A1&amp;) [with RET = RET; A1 = A1; Object = Filter; Arg1 = MyListChild&amp;; Result = bool]
      ||    static Result apply( Result (Object::*func)(Arg1), Object* o, A1&amp; a1) {
      ||                  ^
      /usr/include/boost/lambda/detail/function_adaptors.hpp|394 col 17| note:   template argument deduction/substitution failed:
      /usr/include/boost/lambda/detail/actions.hpp|96 col 37| note:   cannot convert ‘a2’ (type ‘const Filter’) to type ‘Filter*’
      ||        template apply&lt;RET&gt;(a1, a2, a3);
      ||                                      ^
      /usr/include/boost/lambda/detail/function_adaptors.hpp|398 col 17| note: template&lt;class RET, class A1&gt; static Result boost::lambda::function_adaptor&lt;Result (Object::*  )(Arg1)&gt;::apply(Result (Object::*)(Arg1), Object&amp;, A1&amp;) [with RET = RET; A1 = A1; Object = Filter; Arg1 = MyListChild&amp;; Result = bool]
      ||    static Result apply( Result (Object::*func)(Arg1), Object&amp; o, A1&amp; a1) {
      ||                  ^
      /usr/include/boost/lambda/detail/function_adaptors.hpp|398 col 17| note:   template argument deduction/substitution failed:
      /usr/include/boost/lambda/detail/actions.hpp|96 col 37| note:   cannot convert ‘a2’ (type ‘const Filter’) to type ‘Filter&amp;’
      ||        template apply&lt;RET&gt;(a1, a2, a3);
  </code></pre>
  
  <p>What is the right way to write a boost lambda expression in my case? </p>