title: function creation from lambda, argument to function call
body: <p>Why do I get the following compiler error</p>
  
  <blockquote>
    <p>error: no matching function for call to 'memo(drawConnections_nicer2(const RangeVector&amp;, std::function)::__lambda13)'
                                                         });</p>
  </blockquote>
  
  <p>with this code?</p>
  
  <pre><code>template&lt;typename R, typename ... Args&gt;
  shared_ptr&lt;function&lt;R(Args...)&gt; &gt; memo(function&lt;R(Args...)&gt; fn)
  {
      map&lt;tuple&lt;Args...&gt;,R&gt; table;
      return make_shared&lt;function&lt;R(Args...)&gt; &gt;([fn,table](Args... args) mutable -&gt;
              R {
          auto argt = make_tuple(args...);
          auto memoized = table.find(argt);
          if(memoized==table.end())
          {
              auto result = fn(args...);
              table[argt]=result;
              return result;
          }
          else
          {
              return memoized-&gt;second;
          }
      });
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>shared_ptr&lt;function&lt;int(Range,int)&gt; &gt;  calculate_level = memo([&amp;](Range current, int pos) -&gt;
  int {
      auto max_level = 0;
      for(auto i=pos;i&gt;=0;i--)
      {
          auto other = drawn[i];
          if ( !(other.second&lt;current.first || other.first&gt;current.second) ) // intersects
          {
              max_level = max(max_level, (*calculate_level)(other,i-1)+1);
          }
      }
      return max_level;
  });
  </code></pre>
  
  <p>I thought that the lambda should be wrapped in a function object automatically here? Why is this not the case? Can I make do without the function parameter in memo?</p>