public member function
<atomic>

std::atomic::operator (comp. assign.)

if T is integral (1)
T operator+= (T val) volatile noexcept;
T operator+= (T val) noexcept;
T operator-= (T val) volatile noexcept;
T operator-= (T val) noexcept;
T operator&= (T val) volatile noexcept;
T operator&= (T val) noexcept;
T operator|= (T val) volatile noexcept;
T operator|= (T val) noexcept;
T operator^= (T val) volatile noexcept;
T operator^= (T val) noexcept;
if T is pointer (2)
T operator+= (ptrdiff_t val) volatile noexcept;
T operator+= (ptrdiff_t val) noexcept;
T operator-= (ptrdiff_t val) volatile noexcept;
T operator-= (ptrdiff_t val) noexcept;
Compound assignments
atomic specializations for integral (1) and pointer (2) types support compound assignments:

Each of these functions accesses the contained value, apply the proper operator and return the value the contained value had immediately before the operation; all in a single atomic operation that cannot be affected by other threads.

These functions behave as if the proper fetch_* member function was called with memory_order_seq_cst as second argument:
operatormember functionssupported for
comp. assign.equivalentintegral typespointer typesother types
+atomic::operator+=atomic::fetch_addyesyesno
-atomic::operator-=atomic::fetch_subyesyesno
&atomic::operator&=atomic::fetch_andyesnono
|atomic::operator|=atomic::fetch_oryesnono
^atomic::operator^=atomic::fetch_xoryesnono

Parameters

val
Value to apply.
T is atomic's template parameter (the type of the contained value).
ptrdiff_t is a signed integral type.

Return value

The value contained after applying the operation.
T is atomic's template parameter (the type of the contained value).

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