std::atomic_ref::exchange(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ std::atomic_ref::exchange β€” C++ Standard Libary ✨

okay so bestie, we’re in the C++ Standard Libary β€” yes, that’s how the header spells it, don’t come for me πŸ’€ β€” and this page is all about std::atomic_ref::exchange(3). It’s giving atomic read-modify-write realness and I’m lowkey obsessed. 🫢


🌸 NAME 🌸

std::atomic_ref::exchange - std::atomic_ref::exchange. That’s it. That’s the name. Yes, twice. Slay. πŸ’…

✨ Synopsis ✨

Here’s the signature, copied exactly, including the (since C++20) marker chilling in the middle:

T exchange( T desired, std::memory_order order =
(since C++20)
std::memory_order_seq_cst ) const noexcept;

Atomically replaces the value of the referenced object with desired. The operation is a read-modify-write operation. Memory is affected according to the value of order. That’s the whole tea, and it’s honestly such a main character move. πŸ’…

πŸŽ€ Parameters πŸŽ€

  • desired β€” value to assign. Give it what you want the referenced object to become, bestie. πŸ’–
  • order β€” memory order constraints to enforce. This is the vibe check for how memory gets affected. ✨

πŸ’– Return value πŸ’–

The value of the referenced object before the call. So it hands you the old value on the way out β€” iconic behavior, no cap. πŸŽ€


Okay bye bestie β€” this page is from http://cppreference.com, dated 2024.06.10, and it’s std::atomic_ref::exchange(3) signing off. Mwah πŸ’‹

πŸ“¦ where this page comes from