std::atomic...ator&=,|=,^=(3)
π
std::atomic...ator&=,|=,^=(3) π
okay so bestie, welcome to the std::atomic...ator&=,|=,^=(3) page from the C++ Standard Libary manual. yes, that spelling is exactly what's on the page β I don't make the rules π. this one is all about std::atomic_ref's compound assignment operators &=, |=, and ^=, and it's giving atomic bitwise main character energy. let's get into it π«Άβ¨
πΈ NAME πΈ
std::atomic_ref::operator&=,|=,^= β std::atomic_ref::operator&=,|=,^=
yes bestie, the name section is literally the same thing twice. iconic, honestly.
β¨ Synopsis β¨
member only of atomic_ref<Integral> specializations
T operator&=( T arg ) const noexcept; (1) (since C++20)
T operator|=( T arg ) const noexcept; (2) (since C++20)
T operator^=( T arg ) const noexcept; (3) (since C++20)
so what's the vibe? it atomically replaces the current value of the referenced object with the result of a computation involving the previous value and arg. these operations are read-modify-write operations, periodt.
here's the breakdown:
operator&=β performs atomic bitwise AND. Equivalent toreturn fetch_and(arg) & arg;.operator!=β performs atomic bitwise OR. Equivalent toreturn fetch_or(arg) | arg;. (yes, the page saysoperator!=, not me π I'm just reporting what's on the sheet.)operator^=β performs atomic bitwise XOR. Equivalent toreturn fetch_xor(arg) ^ arg;.
π Parameters π
argβ the argument for the arithmetic operation.
π Return value π
the resulting value β that is, the result of applying the corresponding binary operator to the value immediately preceding the effects of the corresponding member function. yes, all of that is the return value, bestie π
π Notes π
unlike most compound assignment operators, the compound assignment operators for atomic_ref do not return a reference to their left-hand arguments. they return a copy of the stored value instead. so if you were expecting a reference, surprise π«Ά
π Example π
This section is incomplete
Reason: no example
not the "no example" era π it's fine, we're still slaying.
π See also π
fetch_andβ atomically performs bitwise AND between the argument and the value of the referenced object and obtains the value held previously (public member function)fetch_orβ atomically performs bitwise OR between the argument and the value of the referenced object and obtains the value held previously (public member function)fetch_xorβ atomically performs bitwise XOR between the argument and the value of the referenced object and obtains the value held previously (public member function)operator++,operator++(int),operator--,operator--(int)β atomically increments or decrements the referenced object by one (public member function)operator+=,operator-=β atomically adds to or subtracts from the referenced value (public member function)
π·οΈ Category π·οΈ
- Todo no example
source/version & date check, bestie: shoutout to http://cppreference.com, dated 2024.06.10, page std::atomic...ator&=,|=,^=(3). go atomically slay today πβ¨π¦
π¦ 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