std::forward
is a template, and you need to provide the type argument explicitly if you want it to work properly. This is how your maximum
function template should be rewritten:
template<class T, class U>
constexpr auto maximum(T&& a, U&& b) ->
decltype( (a > b) ? std::forward<T>(a) : std::forward<U>(b))
{
return (a > b) ? std::forward<T>(a) : std::forward<U>(b);
}
This is how the std::forward
utility is defined:
template<class T>
T&& forward(typename remove_reference<T>::type& a) noexcept
{
return static_cast<S&&>(a);
}
The expression typename remove_reference<T>::type
makes this a non-deduced context, which explains why type deduction fails if you do not explicitly provide the type argument T
.