member only of `atomic<` (C++11) and `atomic<` (C++20) template specializations | ||

(1) | ||

T operator+=( T arg ) noexcept; | ||

T operator+=( T arg ) volatile noexcept; | ||

member only of `atomic<T*>` template specialization | ||

(1) | ||

T* operator+=( std::ptrdiff_t arg ) noexcept; | ||

T* operator+=( std::ptrdiff_t arg ) volatile noexcept; | ||

member only of `atomic<` (C++11) and `atomic<` (C++20) template specializations | ||

(2) | ||

T operator-=( T arg ) noexcept; | ||

T operator-=( T arg ) volatile noexcept; | ||

member only of `atomic<T*>` template specialization | ||

(2) | ||

T* operator-=( std::ptrdiff_t arg ) noexcept; | ||

T* operator-=( std::ptrdiff_t arg ) volatile noexcept; | ||

member only of `atomic<` template specialization | ||

(3) | ||

T operator&=( T arg ) noexcept; | ||

T operator&=( T arg ) volatile noexcept; | ||

(4) | ||

T operator|=( T arg ) noexcept; | ||

T operator|=( T arg ) volatile noexcept; | ||

(5) | ||

T operator^=( T arg ) noexcept; | ||

T operator^=( T arg ) volatile noexcept; |

Atomically replaces the current value with the result of computation involving the previous value and `arg`

. The operation is read-modify-write operation.

1) Performs atomic addition. Equivalent to

`fetch_add(arg)`

+ arg.
2) Performs atomic subtraction. Equivalent to

`fetch_sub(arg)`

- arg.
3) Performs atomic bitwise and. Equivalent to

`fetch_and(arg)`

& arg.
4) Performs atomic bitwise or. Equivalent to

`fetch_or(arg)`

| arg.
5) Performs atomic bitwise exclusive or. Equivalent to

`fetch_xor(arg)`

^ arg.For signed `Integral`

types, arithmetic is defined to use two’s complement representation. There are no undefined results.

For `T*`

types, the result may be an undefined address, but the operations otherwise have no undefined behavior. The program is ill-formed if `T`

is not an object type.

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 The volatile-qualified versions are deprecated if | (since C++20) |

arg | - | the argument for the arithmetic operation |

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 in the modification order of `*this`

).

Unlike most compound assignment operators, the compound assignment operators for atomic types do not return a reference to their left-hand arguments. They return a copy of the stored value instead.

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|

P0558R1 | C++11 | arithmetic permitted on pointers to cv void or function | made ill-formed |

increments or decrements the atomic value by one (public member function) |

© cppreference.com

Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.

https://en.cppreference.com/w/cpp/atomic/atomic/operator_arith2