std::exchange, introduced in C++14, is specified as follows:
template< class T, class U = T > T exchange( T& obj, U&& new_value );Replaces the value of
objwithnew_valueand returns the old value ofobj.
Here's a possible implementation from cppreference:
template<class T, class U = T>
T exchange(T& obj, U&& new_value)
{
T old_value = std::move(obj);
obj = std::forward<U>(new_value);
return old_value;
}
As far as I can see, there's nothing preventing std::exchange from being marked as constexpr. Is there a reason I am missing why it cannot be constexpr, or is this just an oversight?