std::atomic_ref::fetch_sub(3)
std::atomic_ref::fetch_sub(3) π β¨
okay bestie, welcome to the C++ Standard Libary man page for std::atomic_ref::fetch_sub β yes, that's the manual name, and yes, we're respecting the iconic spelling. this page is giving atomic arithmetic realness, so grab your emotional support iced coffee. π¦
πΈ NAME πΈ
std::atomic_ref::fetch_sub β std::atomic_ref::fetch_sub (the page says it twice, so we're saying it twice, periodt π
)
β¨ Synopsis β¨
okay so first thing: this function is member only of certain specializations. don't try to make it fetch_sub outside its lane, bestie. π
here's the exact synopsis energy:
member only of atomic_ref<Integral> and atomic_ref<Floating>
template specializations
T fetch_sub( 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_sub( std::ptrdiff_t arg,
std::memory_order order = std::memory_order_seq_cst
(2) (since C++20)
) const noexcept;
so what does it do? atomically, it replaces the current value of the referenced object with the result of arithmetic subtraction of the value and arg. this operation is a read-modify-write operation. memory is affected according to the value of order. it's doing the most in one go. π₯
for signed integral types, arithmetic is defined to use twoβs complement representation. there are no undefined results. slay, no cursed UB 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. so: unspecified? yes. UB? no. got it? π«Ά
for T* types, the result may be an undefined address, but the operation otherwise has no undefined behavior. and heads up: the program is ill-formed if T is not an object type. that's a hard no, not a vibe. π
π Parameters π
argβ the other argument of arithmetic subtraction. it's the thing getting subtracted, bestie. πorderβ memory order constraints to enforce. this is the memory-ordering vibe check. π
π Return value π
the value of the referenced object, immediately preceding the effects of this function. so it's the before picture, not the after. iconic. πΈ
π§ Example π§
This section is incomplete Reason: no example
not me crying because there's no example π we move, though. π
π Category π
- Todo no example
xoxo, bestie π«Ά this page is sourced from http://cppreference.com, version/date 2024.06.10, and it's the std::atomic_ref::fetch_sub(3) page. now go subtract atomically and stay hydrated. πβ¨
π¦ 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