I am new to template-metaprogramming. The second parameter will be the same as the function parameter passed. I want to deduce the second parameter type from Func.
template<typename Func>
void execute(Func func, decltype(Func) t)
{
std::cout << func(t) << std::endl;
}
int main()
{
std::function<int(float)> func1 = [](float f) { return int(f); };
execute(func1,1.5);
return 0;
}
This works, but I don't want to declare additional typenameme T since the info is already available in Func, so why not deduce.
template<typename Func, typename T>
void execute(Func func, T t)
{
std::cout << func(t) << std::endl;
}