[utility.exchange] (original) (raw)

22 General utilities library [utilities]

22.2 Utility components [utility]

22.2.3 exchange [utility.exchange]

🔗

template<class T, class U = T> constexpr T exchange(T& obj, U&& new_val) noexcept(_see below_);

1

#

Effects: Equivalent to:T old_val = std::move(obj); obj = std::forward<U>(new_val);return old_val;

2

#

Remarks: The exception specification is equivalent to:is_nothrow_move_constructible_v<T> && is_nothrow_assignable_v<T&, U>