std::experimental::ranges::exchange - cppreference.com (original) (raw)

| | | | | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | ----------- | | template< MoveConstructible T, class U = T > requires Assignable<T&, U> constexpr T exchange( T& obj, U&& new_val ) noexcept(/* see below */); | | (ranges TS) |

Replaces the value of obj with new_value and returns the old value of obj, as if by

T old_value = std::move(obj); obj = std::forward(new_value); return old_value;

[edit] Parameters

obj - object whose value to replace
new_value - the value to assign to obj

[edit] Return value

The old value of obj.

[edit] Exceptions

[edit] Example

[edit] See also

| | replaces the argument with a new value and returns its previous value (function template) [edit] | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |