title: Inferring type from argument's return type
body: <p>I understand that a template cannot infer a type from assignment, i.e.</p>
  
  <pre><code>template &lt;typename T&gt;
  T aFunction (int a) { /*...*/ }; // This obviously won't work
  </code></pre>
  
  <p>And it's pretty evident why. But this <em>will</em> work:</p>
  
  <pre><code>template &lt;typename T&gt;
  T aFunction (T a, T b) { return a + b; }; // a-ok
  </code></pre>
  
  <p>'cause <code>T</code> will be inferred from the arguments. I want to kinda extrapolate from that:</p>
  
  <pre><code>template &lt;typename T&gt;
  T aFunction (std::function&lt;T(int)&gt; a) { return a(3);};
                             ^
                             |
    I specified it! ----------
  </code></pre>
  
  <p>so that when used, there's no ambiguity on what the function should do:</p>
  
  <pre><code>std::function&lt;double(int)&gt; blah = [](int x){ return x / 2.0f; };
  aFunction(blah);
  </code></pre>
  
  <p>Alas, the compiler won't cooperate with me:</p>
  
  <blockquote>
    <p>No matching member function for call to 'aFunction'</p>
    
    <p>Candidate template ignored: could not match
    'function' against '(lambda at
    file.hpp:274:16)'</p>
  </blockquote>
  
  <p>Is there a way to make this happen?, short of template specialization (this is a <strong>very</strong> generic class), or a dummy argument (I'm not that desperate yet).</p>
  
  <hr>
  
  <p><strong>P.D.:</strong></p>
  
  <p>Full disclosure: Above was just a simplification of the problem, exactly what I need is:</p>
  
  <pre><code>template &lt;typename T&gt;
  class MyStuff {
  
      template &lt;typename ReturnType&gt;
      MyStuff&lt;ReturnType&gt; aFunction(std::function&lt;ReturnType(T)&gt; a){ 
          /*for each stuff in MyStuff do a(stuff)*/ 
      }
  }
  </code></pre>
  
  <p>Where <code>MyStuff</code> contains properties of type <code>T</code> and a bunch of <code>inline</code> functions, such as <code>aFunction</code>.</p>