Let's suppose I have a template function which takes an argument, which is a function (it can be a std::function, or a lambda, or actual function pointer). A silly example that illustrates the problem:
template<typename F,typename A,typename B = typename std::result_of<F(A)>::type>
B blabla(F &&f)
{
return f(A())/3;
}
I can reference the return type of f with std::result_of::typename, given I have the type of A, but I would like the compiler to deduce type A from F's first argument.
(If I write
template<typename A,typename B>
B blabla(const std::function<B(A)> &f)
{
return f(A())/3;
}
the compiler have problems deducing A and B (especially if it's not an std::function but a lambda), so this is not the right way to do it.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…