[utility.exchange] # 22 General utilities library [[utilities]](./#utilities) ## 22.2 Utility components [[utility]](utility#exchange) ### 22.2.3 exchange [utility.exchange] [🔗](#lib:exchange) `template constexpr T exchange(T& obj, U&& new_val) noexcept(see below); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L308) *Effects*: Equivalent to:T old_val = std::move(obj); obj = std::forward(new_val);return old_val; [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L317) *Remarks*: The exception specification is equivalent to:is_nothrow_move_constructible_v && is_nothrow_assignable_v