template (integral) (1)
template <class T> T atomic_fetch_add (volatile atomic<T>* obj, T val) noexcept;
template <class T> T atomic_fetch_add (atomic<T>* obj, T val) noexcept;
template (pointer) (2)
template <class U> U* atomic_fetch_add (volatile atomic<U*>* obj, ptrdiff_t val) noexcept;
template <class U> U* atomic_fetch_add (atomic<U*>* obj, ptrdiff_t val) noexcept;
overloads (3)
T atomic_fetch_add (volatile A* obj, M val) noexcept;
T atomic_fetch_add (A* obj, M val) noexcept;
Add to contained value
Adds val to the value contained in obj.

The entire operation is atomic: the value cannot be modified between the instant its value is read (to be returned) and the moment it is modified by this function.

The function synchronizes using sequential consistency (memory_order_seq_cst). To modify the value with a different memory ordering, see atomic_fetch_add_explicit.

See atomic::fetch_add and atomic::operator+= for equivalent member functions of atomic.


Pointer to an atomic object that contains either an integral or a pointer value.
Type A represents other overloaded atomic types (in case the library does not implement the C-style atomic types as instantiations of atomic).
Value to add.
T is the type of the value contained by the atomic object (atomic's template parameter).
ptrdiff_t is a signed integral type.
M is T if T is an integral type, or ptrdiff_t if T is a pointer.

Return value

The contained value before the call.
T (or U*) is the type of the value contained by the atomic object (atomic's template parameter).

Data races

No data races (atomic operation). The operation uses sequential consistency (memory_order_seq_cst).

Exception safety

No-throw guarantee: never throws exceptions.

See also