In looking at std::apply references from cpprefrence we can see that function templates cannot be passed as callable object of std::apply. Let's consider the following function template:
template<typename T> T add_generic(T first, T second) { return first + second; } So as the function template can't be deduced in std::apply call, we can't use the follwing code:
std::apply(add_generic, std::make_pair(2.0f, 3.0f)); // Error: can't deduce the function type Please note that this is not the same question as this question. In that answer, the author writes a lambda expression without explicit template parameters.
std::cout << std::apply( [](auto first, auto second) { return add_generic(first, second); }, std::make_tuple(2.0f,3.0f)) << '\n'; but as you know in c++20 you can have lambda expressions with explicit template parameter list. So I tried this feature to the case and surprisingly the compiler did not raise any errors.
std::apply([]<typename T>(T first,T second){ return first+second; },std::make_pair(2.0,3.0)); Why will the compiler be able to deduce type in the last case? Is there any difference between the two?