title: Template member function argument deduction
body: <p>I'm curious as to why the following template deduction doesn't work (VS2015):</p>
  
  <pre><code>template&lt;typename T&gt;
  class Foo
  {
  public:
    template&lt;typename U&gt;
    U get(U u) { return u; }
  
    // Default constructed U and T for example only.
    template&lt;typename U&gt;
    U get(std::function&lt;U(U, T)&gt; f) { return f(U(), T()); }
  
    template&lt;typename U&gt;
    U get(U u, std::function&lt;U(U,T)&gt; f) { return u; }
  
  };
  </code></pre>
  
  <p>In the example above, the following is successful:</p>
  
  <pre><code>Foo&lt;int&gt; f;
  auto f_asInt = f.get(5);      // f_asInt is of type int
  auto f_asFloat = f.get(5.0f); // f_asFloat is of type float.
  
  auto ff_asInt = f.get([](int, int) { return 5; });
  auto ff_asFloat = f.get([](float, int) { return 5.0f; });
  </code></pre>
  
  <p>The following however fails to compile</p>
  
  <pre><code>Foo&lt;int&gt; f;
  auto f_asInt = f.get(5, [](int, int) { return 5; });
  auto f_asFloat = f.get(5.0f, [](float, int) { return 5.0f; });
  </code></pre>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>error C2784: 'U Foo&lt;int&gt;::get(U,std::function&lt;U(U,T)&gt;)': could not deduce template argument for 'std::function&lt;U(U,T)&gt;' from 'main::&lt;lambda_c4fa8cb1e6fa86997f25b7dabd5d415f&gt;'
  </code></pre>
  
  <p>If I spell out the whole template, it works as expected.</p>
  
  <pre><code>Foo&lt;int&gt; f;
  auto f_asInt = f.get&lt;int&gt;(5, [](int, int) { return 5; });
  auto f_asFloat = f.get&lt;float&gt;(5.0f, [](float, int) { return 5.0f; });
  </code></pre>
  
  <p>I would like for the template arguments to be deduced in this case, is that even possible?</p>