Namespaces
Variants
Views
Actions

std::experimental::ranges::exchange

From cppreference.com
< cpp‎ | experimental‎ | ranges
 
 
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
 
 
General utilities library
Utility components
exchange
Function objects
Metaprogramming and type traits
Tagged pairs and tuples
                          
tag specifiers
                                      
                          
 
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<U>(new_value);
return old_value;

Contents

[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

noexcept specification:  
noexcept(std::is_nothrow_move_constructible<T>::value &&
         std::is_nothrow_assignable<T&, U>::value)

[edit] Example

[edit] See also

(C++14)
replaces the argument with a new value and returns its previous value
(function template) [edit]