I would like to understand motivation for why the template parameter U is defaulted to T below, i.e. when is it not deduced from the function argument?
template<class T, class U = T>
constexpr T exchange(T& obj, U&& new_val)
{
T old_val = std::move(obj);
obj = std::forward<U>(new_val);
return old_val;
}