std::experi...es::exchange(3)
β¨ NAME β¨
okay so bestie, this page is std::experimental::ranges::exchange β std::experimental::ranges::exchange, yes the name repeats, we love a consistent queen π
β and the header shows it as std::experi...es::exchange(3). It lives in the C++ Standard Libary manual (not me spelling it, thatβs literally the manual name, iykyk). Iconic.
πΈ Synopsis πΈ
Defined in header <experimental/ranges/utility> π
template< MoveConstructible T, class U = T >
requires Assignable<T&, U>
(ranges TS)
constexpr T exchange( T& obj, U&& new_val ) noexcept(/* see below */);
The way this works is lowkey iconic: it 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;
π Parameters π
objβ the object whose value to replace. Main character energy, honestly.new_valueβ the value to assign toobj. Fresh content, slay.
π Return value π
The old value of obj. Periodt. You get the previous value back, no cap.
π₯ Exceptions π₯
Hereβs the noexcept specification, bestie β read it carefully:
noexcept(std::is_nothrow_move_constructible<T>::value &&
std::is_nothrow_assignable<T&, U>::value)
π¦ Example π¦
This section is incomplete Reason: no example
Not me leaving the example section empty, but thatβs literally what it says. π
π See also π
exchangereplaces the argument with a new value and returns its previous value β(C++14)β(function template)
π Categories π
- conditionally noexcept
- Todo no example
okay bye bestie, thatβs the whole page π source/version: http://cppreference.com, date 2024.06.10, and page std::experi...es::exchange(3) β¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms