Anybody have any ideas?
no plus ones
Shared publicly•View activity
- 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:
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);Nov 27, 2012