title: Get input/output type of callable
body: <p>I have the following problem:</p>
  
  <pre><code>template&lt;typename Func, typename T_in = /*input type of Func */, typename T_out = /*output type of Func */&gt;
  std::vector&lt;T_out&gt; foo( Func f, const std::vector&lt;T_in&gt;&amp; input)
  {
    std::vector&lt;T_out&gt; res( input.size() );
  
    for( size_t i = 0 ; i &lt; input.size() ; ++i )
      res[ i ] = f( input[ i ] );
  
    return res;
  }
  
  
  int main()
  {
    // example for f(x) = x*x
    std::vector&lt;float&gt; input = { /* ... */ };
    auto res = foo( [](float in){ return in*in; }, input );
  
    return 0;
  }
  </code></pre>
  
  <p>As you can see above, I try to implement a function <code>foo</code> which maps a function <code>f</code> to each element of an input vector <code>input</code>. My problem is the following: I want the elements of the input vector <code>input</code> to have the input type of <code>f</code> (i.e., <code>T_in</code>) and the elements of the output vector the output type of <code>f</code> (i.e., <code>T_out</code>) but without passing the input/output type of <code>f</code> explicitly to <code>foo</code> (due to a better readability of the code). Has anyone an idea how the input/output type of <code>f</code> can be deduced automatically at compile time?</p>
  
  <p>Many thanks in advance.</p>