std::atomic_ref::fetch_add(3)
๐ std::atomic_ref::fetch_add โ C++ Standard Libary, section 3 ๐
๐ธ NAME ๐ธ
std::atomic_ref::fetch_add โ std::atomic_ref::fetch_add
Yes bestie, the name is literally the same on both sides. Itโs giving mirror selfie energy ๐.
โจ Synopsis โจ
okay so hereโs the signature situation, and every line matters:
member only of atomic_ref<Integral> and atomic_ref<Floating>
template specializations
T fetch_add( T arg,
std::memory_order order = std::memory_order_seq_cst )
(1) (since C++20)
const noexcept;
member only of atomic_ref<T*> template specialization
T* fetch_add( std::ptrdiff_t arg,
std::memory_order order = std::memory_order_seq_cst
(2) (since C++20)
) const noexcept;
No cap: overload (1) is only for the atomic_ref<Integral> and atomic_ref<Floating> specializations, and overload (2) is only for the atomic_ref<T*> specialization. Both are (since C++20) and both are const noexcept era. Periodt โจ.
๐งฎ Parameters ๐งฎ
argโ the other argument of arithmetic addition. Itโs the little number/pointer-ish bestie getting added in ๐ซถ.orderโ memory order constraints to enforce. This is the vibe check for memory ordering ๐ .
๐ Return value ๐
The value of the referenced object, immediately preceding the effects of this function. Like, the old value right before the add did its main character thing ๐.
๐งช Example ๐งช
This section is incomplete ๐ญ.
Reason: no example.
bestie, the manpage really said โno exampleโ and dipped ๐.
๐๏ธ Category ๐๏ธ
Todo no example
okay so what does this function actually do? It atomically replaces the current value of the referenced object with the result of arithmetic addition of the value and arg. This operation is a read-modify-write operation, no cap ๐ฅ. Memory is affected according to the value of order โจ.
For signed integral types, arithmetic is defined to use twoโs complement representation. There are no undefined results. Slay, no undefined-result jumpscare here ๐.
For floating-point types, the floating-point environment in effect may be different from the calling thread's floating-point environment. The operation need not be conform to the corresponding std::numeric_limits traits but is encouraged to do so. If the result is not a representable value for its type, the result is unspecified but the operation otherwise has no undefined behavior ๐ซถ.
For T* types, the result may be an undefined address, but the operation otherwise has no undefined behavior. The program is ill-formed if T is not an object type. Thatโs the serious caveat, bestie โ do not skip it ๐
.
okay bye bestie, this page came from http://cppreference.com, dated 2024.06.10, and itโs the std::atomic_ref::fetch_add(3) page ๐๐ซถโจ
๐ฆ 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