Both of the following code compiles and performs as expected, are they different?
template<typename T, typename ...U>
auto time_function(T&& func, U&& ...args)
{
std::cout << "timing" << std::endl;
auto val = std::forward<T>(func)(std::forward<U...>(args...));
std::cout << "timing over" << std::endl;
return val;
}
template<typename T, typename ...U>
auto time_function(T&& func, U&& ...args)
{
std::cout << "timing" << std::endl;
auto val = std::forward<T>(func)(std::forward<U>(args)...);
std::cout << "timing over" << std::endl;
return val;
}
Looking at SO How would one call std::forward on all arguments in a variadic function?, second seems to be recommended, but doesn't the first do the same thing?