std::atomic::operator++,++(int),--,--(int) - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::atomic::operator++,++(int),--,--(int)

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

T operator++(); T operator++() volatile; | (1) | (member only of `atomic<Integral>` template specialization) (since C++11)
T* operator++(); T* operator++() volatile; | (1) | (member only of `atomic<T*>` template specialization) (since C++11)
T operator++( int ); T operator++( int ) volatile; | (2) | (member only of `atomic<Integral>` template specialization) (since C++11)
T* operator++( int ); T* operator++( int ) volatile; | (2) | (member only of `atomic<T*>` template specialization) (since C++11)
T operator--(); T operator--() volatile; | (3) | (member only of `atomic<Integral>` template specialization) (since C++11)
T* operator--(); T* operator--() volatile; | (3) | (member only of `atomic<T*>` template specialization) (since C++11)
T operator--( int ); T operator--( int ) volatile; | (4) | (member only of `atomic<Integral>` template specialization) (since C++11)
T* operator--( int ); T* operator--( int ) volatile; | (4) | (member only of `atomic<T*>` template specialization) (since C++11)

Atomically increments or decrements the current value. The operation is read-modify-write operation.

1) Performs atomic pre-increment. Equivalent to fetch_add(1)+1.
2) Performs atomic post-increment. Equivalent to fetch_add(1).
3) Performs atomic pre-decrement. Equivalent to fetch_sub(1)-1
4) Performs atomic post-decrement. Equivalent to fetch_sub(1).

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

(none)

### [edit] Return value

1,3) The value of the atomic variable after the modification.
2,4) The value of the atomic variable before the modification.

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Notes

Unlike most pre-increment and pre-decrement operators, the pre-increment and pre-decrement operators for atomic types do not return a reference to the modified object. They return a copy of the stored value instead.

### [edit] See also

fetch_add (C++11) | atomically adds the argument to the value stored in the atomic object and obtains the value held previously (public member function) [edit]
fetch_sub (C++11) | atomically subtracts the argument from the value stored in the atomic object and obtains the value held previously (public member function) [edit]
operator+=operator-=operator&=operator|=operator^= | adds, subtracts, or performs bitwise AND, OR, XOR with the atomic value (public member function) [edit]

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

- unconditionally noexcept