std::atomic<T>::operator++,++(int),--,--(int)
T operator++() noexcept; T operator++() volatile noexcept; |
(1) | (member only of atomic<Integral> template specialization)(since C++11) |
T* operator++() noexcept; T* operator++() volatile noexcept; |
(1) | (member only of atomic<T*> template specialization)(since C++11) |
T operator++( int ) noexcept; T operator++( int ) volatile noexcept; |
(2) | (member only of atomic<Integral> template specialization)(since C++11) |
T* operator++( int ) noexcept; T* operator++( int ) volatile noexcept; |
(2) | (member only of atomic<T*> template specialization)(since C++11) |
T operator--() noexcept; T operator--() volatile noexcept; |
(3) | (member only of atomic<Integral> template specialization)(since C++11) |
T* operator--() noexcept; T* operator--() volatile noexcept; |
(3) | (member only of atomic<T*> template specialization)(since C++11) |
T operator--( int ) noexcept; T operator--( int ) volatile noexcept; |
(4) | (member only of atomic<Integral> template specialization)(since C++11) |
T* operator--( int ) noexcept; T* operator--( int ) volatile noexcept; |
(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.
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.
The volatile-qualified versions are deprecated if std::atomic<T>::is_always_lock_free is false. |
(since C++20) |
Parameters
(none)
Return value
*this
.*this
.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.
Defect reports
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 |
See also
atomically adds the argument to the value stored in the atomic object and obtains the value held previously (public member function) | |
atomically subtracts the argument from the value stored in the atomic object and obtains the value held previously (public member function) | |
adds, subtracts, or performs bitwise AND, OR, XOR with the atomic value (public member function) |