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.)
This won't work for generic lambdas or arbitrary functors whose
operator()
is overloaded or is a template.Then
Replace 0 with the desired number as needed, or write a separate alias that also take an index. Demo.
#include <boost/type_traits.hpp>