Shared publicly  - 
I'm trying to make this program compile properly: #include #include int f(int a, int b) { ::std::cout << "f(" << a << ", " << b << ") == &q...
Kenton Varda's profile photo
The key is to use decltype() to infer the return type of the function (R), since you can't easily pattern-match it.  However, it gets pretty tedious since the decltype()'s parameter tends to be essentially a copy of the function's body.  And in your case you have a multi-statement function, but the parameter to decltype needs to be an expression.

Also complicating this case is that the vector's size is dynamic, so you have to determine the number of expected parameters from the function.  If the function itself is variadic, or is a functor with an overloaded operator(), then there is no correct answer here.

You may have to require that the caller explicitly specifies the arity:

  bind_vec<2>(f, x);

You can also make things a lot easier by having the caller specify the return type, although this is disappointing since it should be inferrable:

  bind_vec<2, int>(f, x);
Add a comment...