Consider the following function in C++11:
template<class Function, class... Args, typename ReturnType = /*SOMETHING*/>
inline ReturnType apply(Function&& f, const Args&... args);
I want ReturnType to be equal to the result type of f(args...)
What do I have to write instead of /*SOMETHING*/ ?
I think you should rewrite your function template using trailing-return-type as:
Note that if you pass
argsasArgs&&...instead ofconst Args&..., then it is better to usestd::forwardinfas:When you use
const Args&..., thenstd::forwarddoesn’t make much sense (at least to me).It is better to pass
argsasArgs&&...called universal-reference and usestd::forwardwith it.