std::atomic::operator+=,-=,&=,|=,^= - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::atomic::operator+=,-=,&=,|=,^=

From cppreference.com
< cpp‎ | atomic‎ | atomic

| (1) | (since C++11) (member only of `atomic<Integral>` template specialization)
T operator+=( T arg ); |  |
T operator+=( T arg ) volatile; |  |
| (1) | (since C++11) (member only of `atomic<T*>` template specialization)
T* operator+=( std::ptrdiff_t arg ); |  |
T* operator+=( std::ptrdiff_t arg ) volatile; |  |
| (2) | (since C++11) (member only of `atomic<Integral>` template specialization)
T operator-=( T arg ); |  |
T operator-=( T arg ) volatile; |  |
| (2) | (since C++11) (member only of `atomic<T*>` template specialization)
T* operator-=( std::ptrdiff_t arg ); |  |
T* operator-=( std::ptrdiff_t arg ) volatile; |  |
| (3) | (since C++11) (member only of `atomic<Integral>` template specialization)
T operator&=( T arg ); |  |
T operator&=( T arg ) volatile; |  |
| (4) | (since C++11) (member only of `atomic<Integral>` template specialization)
T operator|=( T arg ); |  |
T operator|=( T arg ) volatile; |  |
| (5) | (since C++11) (member only of `atomic<Integral>` template specialization)
T operator^=( T arg ); |  |
T operator^=( T arg ) volatile; |  |

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.

### [edit] Parameters

arg | - | the argument for the arithmetic operation

### [edit] Return value

The resulting value.

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Notes

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.

### [edit] See also

operator++operator++(int)operator--operator--(int) | increments or decrements the atomic value by one (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/atomic/atomic/operator_arith2&oldid=65814"
Category:

- unconditionally noexcept