title: C++ templated functor in lambda expression
body: <p>This first piece has been solved by Eric's comments below but has led onto a secondary issue that I describe after the horizontal rule. Thanks Eric!</p>
  
  <p>I'm trying to pass a functor that is a templated class to the create_thread method of boost thread_group class along with two parameters to the functor. However I can't seem to get beyond my current compile error. With the below code:</p>
  
  <pre><code>#include &lt;boost/lambda/lambda.hpp&gt;
  #include &lt;boost/lambda/bind.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  #include &lt;vector&gt;
  
  using namespace boost::lambda;
  using namespace std;
  
  namespace bl = boost::lambda;
  
  template&lt;typename ftor, typename data&gt;
  class Foo
  {
  public:
      explicit Foo()
      {
      }
      void doFtor ()
      {
          _threads.create_thread(bind(&amp;Foo&lt;ftor, data&gt;::_ftor, _list.begin(), _list.end()));
          //_threads.create_thread(bind(_ftor, _list.begin(), _list.end()));
          _threads.join_all();
      }
  
  private:
      boost::thread_group _threads;
      ftor _ftor;
      vector&lt;data&gt; _list;
  };
  
  template&lt;typename data&gt;
  class Ftor
  {
  public:
      //template &lt;class Args&gt; struct sig { typedef void type; }
  
      explicit Ftor () {}
  
      void operator() (typename vector&lt;data&gt;::iterator &amp;startItr, typename vector&lt;data&gt;::iterator &amp;endItr)
      {
          for_each(startItr, endItr, cout &lt;&lt; bl::_1 &lt;&lt; constant("."));
      }
  }
  </code></pre>
  
  <p>I also tried typedef-ing 'type' as I thought my problem might have something to do with the Sig Template as the functor itself is templated. </p>
  
  <p>The error I am getting is:</p>
  
  <pre><code>error: no matching function for call to ‘boost::lambda::function_adaptor&lt;Ftor&lt;int&gt; Foo&lt;Ftor&lt;int&gt;, int&gt;::*&gt;::apply(Ftor&lt;int&gt; Foo&lt;Ftor&lt;int&gt;, int&gt;::* const&amp;, const __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt;&gt; &gt;&amp;, const __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;&amp;)’
  </code></pre>
  
  <p>with a bunch of preamble beforehand. </p>
  
  <p>Thanks in advance for any help!</p>
  
  <hr>
  
  <p>Okay I've modified the code taking in Eric's suggestions below resulting in the following code:</p>
  
  <pre><code>#include &lt;boost/lambda/lambda.hpp&gt;
  #include &lt;boost/lambda/bind.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  #include &lt;vector&gt;
  
  using namespace boost::lambda;
  using namespace std;
  
  namespace bl = boost::lambda;
  
  template&lt;typename ftor, typename data&gt;
  class Foo
  {
  public:
      explicit Foo()
      {
      }
      void doFtor ()
      {
          _threads.create_thread(bl::bind(boost::ref(_ftor), _list.begin(), _list.end()));
          _threads.join_all();
      }
  
  private:
      boost::thread_group _threads;
      ftor _ftor;
      vector&lt;data&gt; _list;
  };
  
  template&lt;typename data&gt;
  class Ftor
  {
  public:
      typedef void result_type;
  
      explicit Ftor () {}
  
      result_type operator() (typename vector&lt;data&gt;::iterator &amp;startItr, typename vector&lt;data&gt;::iterator &amp;endItr)
      {
          for_each(startItr, endItr, cout &lt;&lt; bl::_1 &lt;&lt; constant("."));
          return ;
      }
  };
  </code></pre>
  
  <p>However this results in another compile error:</p>
  
  <pre><code>/usr/local/include/boost/lambda/detail/function_adaptors.hpp:45: error: no match for call to ‘(Ftor&lt;int&gt;) (const __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;&amp;, const __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;&amp;)’
  ftor.h:41: note: candidates are: void Ftor&lt;data&gt;::operator()(typename std::vector&lt;data, std::allocator&lt;_CharT&gt; &gt;::iterator&amp;, typename std::vector&lt;data, std::allocator&lt;_CharT&gt; &gt;::iterator&amp;) [with data = int]
  /usr/local/include/boost/lambda/detail/function_adaptors.hpp:45: error: return-statement with a value, in function returning 'void'
  </code></pre>
  
  <p>It seems having defined void as a result_type it is now expecting the operator() to return something. I tried returning result_type from within the function but this also generated errors. Any ideas?</p>