std::experi...r::exchange(3)
π NAME π
okay so bestie, this page is from the C++ Standard Library and itβs filed under std::experi...r::exchange(3) β the actual star of the show is std::experimental::atomic_shared_ptr::exchange. And yes, the NAME section is literally std::experimental::atomic_shared_ptr::exchange β std::experimental::atomic_shared_ptr::exchange. iconic, no notes π
β¨ Synopsis β¨
hereβs the signature, bestie:
shared_ptr<T> exchange( shared_ptr<T> desired, std::memory_order order = std::memory_order_seq_cst ) noexcept;
It atomically replaces the underlying shared_ptr with desired. This is a read-modify-write operation, and memory is affected according to the value of order. π«Ά
π Parameters π
desiredβ value to assign. literally the newshared_ptrgoing in.orderβ memory order constraints to enforce. the signature has it defaulting tostd::memory_order_seq_cst.
π Return value π
The value of the atomic variable before the call. thatβs the return value, periodt π
π§ Remarks π§
- All changes to the
atomic_shared_ptrobject itself, and all associateduse_countincrements, are guaranteed to be performed atomically. - Associated
use_countdecrements take place after the atomic operation, but are not required to be part of it. - Any associated destruction or deallocation operations take place after the atomic operation and are not part of it.
ngl this is the important caveat: the atomicity covers changes to theatomic_shared_ptrobject itself and all associateduse_countincrements. The decrements happen after the atomic operation but arenβt required to be part of it, and any associated destruction or deallocation happens after the atomic operation too β not part of it. π
π See also π
the page note says specializes atomic operations for std::shared_ptr (function template), and hereβs the whole squad:
std::atomic_is_lock_free(std::shared_ptr)std::atomic_load(std::shared_ptr)std::atomic_load_explicit(std::shared_ptr)std::atomic_store(std::shared_ptr)std::atomic_store_explicit(std::shared_ptr)std::atomic_exchange(std::shared_ptr)std::atomic_exchange_explicit(std::shared_ptr)std::atomic_compare_exchange_weak(std::shared_ptr)std::atomic_compare_exchange_strong(std::shared_ptr)std::atomic_compare_exchange_weak_explicit(std::shared_ptr)std::atomic_compare_exchange_strong_explicit(std::shared_ptr)
also on the page: (deprecated in C++20) and (removed in C++26). so yeah, keep that in mind, bestie π
okay bye! source/version: http://cppreference.com, date: 2024.06.10, page: std::experi...r::exchange(3). slay π
β¨
π¦ 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