title: C++ how to infer the Callable's type (arguments list & return value) in a template
body: <p>Basically what I want to do, is to make a function template, that takes any Callable (function type / lambda / Functor) and returns a lambda-taking-the-similar-args-list and returning the type of original's return type</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int func(int a,float b) {
      return a+b;
  }
  
  struct callable {
      int operator() (int a, float b) {
          return a+b;
      }
  };
  
  template &lt;typename RV, typename... Args&gt;
  auto getLambdaFromCallable(RV(&amp;func)(Args...)) {
      auto l = [&amp;](Args... args) -&gt; RV {
          return func(args...);
      };
  
      return l;
  }
  
  int main() {
      auto f = getLambdaFromCallable(func);
      std::cout &lt;&lt; f(1,2.f);
      std::cout &lt;&lt; " " &lt;&lt; typeid(f).name();
  
      auto f2 = getLambdaFromCallable(callable{}); // doesn't work
      callable{}(1,2); // works
  
      auto lambdaTest = [](int a, float b) -&gt; int {
          return a+b;
      };
      auto f3 = getLambdaFromCallable(lambdaTest);
  }
  </code></pre>