std::atomic::fetch_sub(3)
β¨ NAME β¨
okay bestie, welcome to std::atomic::fetch_sub from the C++ Standard Library manual π
this is the std::atomic::fetch_sub(3) page, and the NAME is std::atomic::fetch_sub β std::atomic::fetch_sub (yes, the name is the name, we love a self-titled icon) β¨
πΈ Synopsis πΈ
Overloads (1) and (2) are member only of atomic<Integral > specializations and atomic<Floating > specializations (since C++20). Both are since C++11.
- (1) β non-volatile:
T fetch_sub( T arg, std::memory_order order = std::memory_order_seq_cst ) noexcept;
- (2) β volatile:
T fetch_sub( T arg, std::memory_order order = std::memory_order_seq_cst ) volatile noexcept;
Overloads (3) and (4) are member only of the atomic<T*> partial specialization. Both are since C++11.
- (3) β non-volatile pointer:
T* fetch_sub( std::ptrdiff_t arg, std::memory_order order = std::memory_order_seq_cst ) noexcept;
- (4) β volatile pointer:
T* fetch_sub( std::ptrdiff_t arg, std::memory_order order = std::memory_order_seq_cst ) volatile noexcept;
Atomically replaces the current value with the result of arithmetic subtraction of the value and arg. That is, it performs atomic post-decrement. The operation is read-modify-write operation. Memory is affected according to the value of order.
For overloads (1) and (2):
- For signed integral types, arithmetic is defined to use twoβs complement representation. There are no undefined results.
- 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 conform to the corresponding
std::numeric_limits(since C++20) 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 overloads (3) and (4):
- The result may be an undefined address, but the operation otherwise has no undefined behavior.
- If
Tis not a complete object type, the program is ill-formed.
β οΈ deprecated-core: it is deprecated ifstd::atomic<T>::is_always_lock_freeis false and (since C++20) overload (2) or (4) participates in overload resolution. Not me delivering bad news π
π Parameters π
argβ the other argument of arithmetic subtraction.orderβ memory order constraints to enforce.
π Return value π
The value immediately preceding the effects of this function in the modification order of *this. π«Ά
π¦ Defect reports π¦
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
P0558R1- Applied to:
C++11 - Behavior as published: arithmetic permitted on pointers to (possibly cv-qualified)
voidor function - Correct behavior: made ill-formed
- Applied to:
π See also π
atomic_fetch_sub,atomic_fetch_sub_explicit(C++11) β function template; subtracts a non-atomic value from an atomic object and obtains the previous value of the atomic.operator++,operator++(int),operator--,operator--(int)β public member function; increments or decrements the atomic value by one.
π source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::atomic::fetch_sub(3) β ok bye bestie, go decrement atomically and 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