namespace std {
template<class T> struct atomic {
using value_type = T;
static constexpr bool is_always_lock_free = *implementation-defined*;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
// [atomics.types.operations], operations on atomic types
constexpr atomic() noexcept(is_nothrow_default_constructible_v<T>);
constexpr atomic(T) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
T load(memory_order = memory_order::seq_cst) const volatile noexcept;
T load(memory_order = memory_order::seq_cst) const noexcept;
operator T() const volatile noexcept;
operator T() const noexcept;
void store(T, memory_order = memory_order::seq_cst) volatile noexcept;
void store(T, memory_order = memory_order::seq_cst) noexcept;
T operator=(T) volatile noexcept;
T operator=(T) noexcept;
T exchange(T, memory_order = memory_order::seq_cst) volatile noexcept;
T exchange(T, memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_weak(T&, T, memory_order, memory_order) volatile noexcept;
bool compare_exchange_weak(T&, T, memory_order, memory_order) noexcept;
bool compare_exchange_strong(T&, T, memory_order, memory_order) volatile noexcept;
bool compare_exchange_strong(T&, T, memory_order, memory_order) noexcept;
bool compare_exchange_weak(T&, T, memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_weak(T&, T, memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(T&, T, memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_strong(T&, T, memory_order = memory_order::seq_cst) noexcept;
void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept;
void wait(T, memory_order = memory_order::seq_cst) const noexcept;
void notify_one() volatile noexcept;
void notify_one() noexcept;
void notify_all() volatile noexcept;
void notify_all() noexcept;
};
}

The template argument for T shall meet the
*Cpp17CopyConstructible* and *Cpp17CopyAssignable* requirements.

The program is ill-formed if any of

- is_trivially_copyable_v<T>,
- is_copy_constructible_v<T>,
- is_move_constructible_v<T>,
- is_copy_assignable_v<T>, or
- is_move_assignable_v<T>

```
constexpr atomic() noexcept(is_nothrow_default_constructible_v<T>);
```

Initialization is not an atomic operation ([intro.multithread]).

```
constexpr atomic(T desired) noexcept;
```

Initialization is not an atomic operation ([intro.multithread]).

[*Note 1*: *end note*]

It is possible to have an access to an atomic object A
race with its construction, for example by communicating the address of the
just-constructed object A to another thread via
memory_order::relaxed operations on a suitable atomic pointer
variable, and then immediately accessing A in the receiving thread.

This results in undefined behavior.

â€” ```
void store(T desired, memory_order order = memory_order::seq_cst) volatile noexcept;
void store(T desired, memory_order order = memory_order::seq_cst) noexcept;
```

```
T operator=(T desired) volatile noexcept;
T operator=(T desired) noexcept;
```

```
T load(memory_order order = memory_order::seq_cst) const volatile noexcept;
T load(memory_order order = memory_order::seq_cst) const noexcept;
```

```
operator T() const volatile noexcept;
operator T() const noexcept;
```

```
T exchange(T desired, memory_order order = memory_order::seq_cst) volatile noexcept;
T exchange(T desired, memory_order order = memory_order::seq_cst) noexcept;
```

Memory is affected according to the value of order.

These operations are atomic read-modify-write operations ([intro.multithread]).

```
bool compare_exchange_weak(T& expected, T desired,
memory_order success, memory_order failure) volatile noexcept;
bool compare_exchange_weak(T& expected, T desired,
memory_order success, memory_order failure) noexcept;
bool compare_exchange_strong(T& expected, T desired,
memory_order success, memory_order failure) volatile noexcept;
bool compare_exchange_strong(T& expected, T desired,
memory_order success, memory_order failure) noexcept;
bool compare_exchange_weak(T& expected, T desired,
memory_order order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_weak(T& expected, T desired,
memory_order order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(T& expected, T desired,
memory_order order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_strong(T& expected, T desired,
memory_order order = memory_order::seq_cst) noexcept;
```

It then atomically
compares the value representation of the value pointed to by this
for equality with that previously retrieved from expected,
and if true, replaces the value pointed to
by this with that in desired.

If and only if the comparison is true, memory is affected according to the
value of success, and if the comparison is false, memory is affected according
to the value of failure.

When only one memory_order argument is
supplied, the value of success is order, and the value of
failure is order except that a value of memory_order::acq_rel
shall be replaced by the value memory_order::acquire and a value of
memory_order::release shall be replaced by the value
memory_order::relaxed.

If and only if the comparison is false then, after the atomic operation,
the value in expected is replaced by the value
pointed to by this during the atomic comparison.

If the operation returns true, these
operations are atomic read-modify-write
operations ([intro.multithread]) on the memory
pointed to by this.

Otherwise, these operations are atomic load operations on that memory.

[*Note 4*: *end note*]

For example, the effect of
compare_exchange_strong
on objects without padding bits ([basic.types.general]) is
if (memcmp(this, &expected, sizeof(*this)) == 0)
memcpy(this, &desired, sizeof(*this));
else
memcpy(&expected, this, sizeof(*this));

â€” [*Example 1*: *end example*]

The expected use of the compare-and-exchange operations is as follows.

The
compare-and-exchange operations will update expected when another iteration of
the loop is needed.

expected = current.load();
do {
desired = function(expected);
} while (!current.compare_exchange_weak(expected, desired));
â€” [*Example 2*: *end example*]

Because the expected value is updated only on failure,
code releasing the memory containing the expected value on success will work.

For example, list head insertion will act atomically and would not introduce a
data race in the following code:
do {
p->next = head; // make new list node point to the current head
} while (!head.compare_exchange_weak(p->next, p)); // try to insert

â€” That is, even when
the contents of memory referred to by expected and this are
equal, it may return false and store back to expected the same memory
contents that were originally there.

[*Note 5*: *end note*]

This
spurious failure enables implementation of compare-and-exchange on a broader class of
machines, e.g., load-locked store-conditional machines.

A
consequence of spurious failure is that nearly all uses of weak compare-and-exchange
will be in a loop.

When a compare-and-exchange is in a loop, the weak version will yield better performance
on some platforms.

When a weak compare-and-exchange would require a loop and a strong one
would not, the strong one is preferable.

â€” [*Note 6*: *end note*]

Under cases where the memcpy and memcmp semantics of the compare-and-exchange
operations apply, the comparisons can fail for values that compare equal with
operator== if the value representation has trap bits or alternate
representations of the same value.

Notably, on implementations conforming to
ISO/IEC 60559, floating-point -0.0 and +0.0
will not compare equal with memcmp but will compare equal with operator==,
and NaNs with the same payload will compare equal with memcmp but will not
compare equal with operator==.

â€” [*Note 7*: *end note*]

Because compare-and-exchange acts on an object's value representation,
padding bits that never participate in the object's value representation
are ignored.

As a consequence, the following code is guaranteed to avoid
spurious failure:
struct padded {
char clank = 0x42;
// Padding here.
unsigned biff = 0xC0DEFEFE;
};
atomic<padded> pad = {};
bool zap() {
padded expected, desired{0, 0};
return pad.compare_exchange_strong(expected, desired);
}

â€” [*Note 8*: *end note*]

For a union with bits that participate in the value representation
of some members but not others, compare-and-exchange might always fail.

This is because such padding bits have an indeterminate value when they
do not participate in the value representation of the active member.

As a consequence, the following code is not guaranteed to ever succeed:
union pony {
double celestia = 0.;
short luna; // padded
};
atomic<pony> princesses = {};
bool party(pony desired) {
pony expected;
return princesses.compare_exchange_strong(expected, desired);
}

â€” ```
void wait(T old, memory_order order = memory_order::seq_cst) const volatile noexcept;
void wait(T old, memory_order order = memory_order::seq_cst) const noexcept;
```

```
void notify_one() volatile noexcept;
void notify_one() noexcept;
```

```
void notify_all() volatile noexcept;
void notify_all() noexcept;
```

There are specializations of the atomic
class template for the integral types
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
char8_t,
char16_t,
char32_t,
wchar_t,
and any other types needed by the typedefs in the header <cstdint>.

For each such type *integral-type*, the specialization
atomic<*integral-type*> provides additional atomic operations appropriate to integral types.

namespace std {
template<> struct atomic<*integral-type*> {
using value_type = *integral-type*;
using difference_type = value_type;
static constexpr bool is_always_lock_free = *implementation-defined*;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
constexpr atomic() noexcept;
constexpr atomic(*integral-type*) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
void store(*integral-type*, memory_order = memory_order::seq_cst) volatile noexcept;
void store(*integral-type*, memory_order = memory_order::seq_cst) noexcept;
*integral-type* operator=(*integral-type*) volatile noexcept;
*integral-type* operator=(*integral-type*) noexcept;
*integral-type* load(memory_order = memory_order::seq_cst) const volatile noexcept;
*integral-type* load(memory_order = memory_order::seq_cst) const noexcept;
operator *integral-type*() const volatile noexcept;
operator *integral-type*() const noexcept;
*integral-type* exchange(*integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* exchange(*integral-type*,
memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_weak(*integral-type*&, *integral-type*,
memory_order, memory_order) volatile noexcept;
bool compare_exchange_weak(*integral-type*&, *integral-type*,
memory_order, memory_order) noexcept;
bool compare_exchange_strong(*integral-type*&, *integral-type*,
memory_order, memory_order) volatile noexcept;
bool compare_exchange_strong(*integral-type*&, *integral-type*,
memory_order, memory_order) noexcept;
bool compare_exchange_weak(*integral-type*&, *integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_weak(*integral-type*&, *integral-type*,
memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(*integral-type*&, *integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_strong(*integral-type*&, *integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_add(*integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_add(*integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_sub(*integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_sub(*integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_and(*integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_and(*integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_or(*integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_or(*integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_xor(*integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_xor(*integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_max( *integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_max( *integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* fetch_min( *integral-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*integral-type* fetch_min( *integral-type*,
memory_order = memory_order::seq_cst) noexcept;
*integral-type* operator++(int) volatile noexcept;
*integral-type* operator++(int) noexcept;
*integral-type* operator--(int) volatile noexcept;
*integral-type* operator--(int) noexcept;
*integral-type* operator++() volatile noexcept;
*integral-type* operator++() noexcept;
*integral-type* operator--() volatile noexcept;
*integral-type* operator--() noexcept;
*integral-type* operator+=(*integral-type*) volatile noexcept;
*integral-type* operator+=(*integral-type*) noexcept;
*integral-type* operator-=(*integral-type*) volatile noexcept;
*integral-type* operator-=(*integral-type*) noexcept;
*integral-type* operator&=(*integral-type*) volatile noexcept;
*integral-type* operator&=(*integral-type*) noexcept;
*integral-type* operator|=(*integral-type*) volatile noexcept;
*integral-type* operator|=(*integral-type*) noexcept;
*integral-type* operator^=(*integral-type*) volatile noexcept;
*integral-type* operator^=(*integral-type*) noexcept;
void wait(*integral-type*, memory_order = memory_order::seq_cst) const volatile noexcept;
void wait(*integral-type*, memory_order = memory_order::seq_cst) const noexcept;
void notify_one() volatile noexcept;
void notify_one() noexcept;
void notify_all() volatile noexcept;
void notify_all() noexcept;
};
}

The following operations perform arithmetic computations.

`T fetch_`*key*(T operand, memory_order order = memory_order::seq_cst) volatile noexcept;
T fetch_*key*(T operand, memory_order order = memory_order::seq_cst) noexcept;

Memory is affected according to the value of order.

These operations are atomic read-modify-write operations ([intro.multithread]).

For fetch_max and fetch_min, the maximum and minimum
computation is performed as if by max and min algorithms
([alg.min.max]), respectively, with the object value and the first parameter
as the arguments.

`T operator `*op*=(T operand) volatile noexcept;
T operator *op*=(T operand) noexcept;

There are specializations of the atomic
class template for all cv-unqualified floating-point types.

For each such type *floating-point-type*,
the specialization atomic<*floating-point-type*>
provides additional atomic operations appropriate to floating-point types.

namespace std {
template<> struct atomic<*floating-point-type*> {
using value_type = *floating-point-type*;
using difference_type = value_type;
static constexpr bool is_always_lock_free = *implementation-defined*;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
constexpr atomic() noexcept;
constexpr atomic(*floating-point-type*) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
void store(*floating-point-type*, memory_order = memory_order::seq_cst) volatile noexcept;
void store(*floating-point-type*, memory_order = memory_order::seq_cst) noexcept;
*floating-point-type* operator=(*floating-point-type*) volatile noexcept;
*floating-point-type* operator=(*floating-point-type*) noexcept;
*floating-point-type* load(memory_order = memory_order::seq_cst) volatile noexcept;
*floating-point-type* load(memory_order = memory_order::seq_cst) noexcept;
operator *floating-point-type*() volatile noexcept;
operator *floating-point-type*() noexcept;
*floating-point-type* exchange(*floating-point-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*floating-point-type* exchange(*floating-point-type*,
memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
memory_order, memory_order) volatile noexcept;
bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
memory_order, memory_order) noexcept;
bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
memory_order, memory_order) volatile noexcept;
bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
memory_order, memory_order) noexcept;
bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_weak(*floating-point-type*&, *floating-point-type*,
memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_strong(*floating-point-type*&, *floating-point-type*,
memory_order = memory_order::seq_cst) noexcept;
*floating-point-type* fetch_add(*floating-point-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*floating-point-type* fetch_add(*floating-point-type*,
memory_order = memory_order::seq_cst) noexcept;
*floating-point-type* fetch_sub(*floating-point-type*,
memory_order = memory_order::seq_cst) volatile noexcept;
*floating-point-type* fetch_sub(*floating-point-type*,
memory_order = memory_order::seq_cst) noexcept;
*floating-point-type* operator+=(*floating-point-type*) volatile noexcept;
*floating-point-type* operator+=(*floating-point-type*) noexcept;
*floating-point-type* operator-=(*floating-point-type*) volatile noexcept;
*floating-point-type* operator-=(*floating-point-type*) noexcept;
void wait(*floating-point-type*, memory_order = memory_order::seq_cst) const volatile noexcept;
void wait(*floating-point-type*, memory_order = memory_order::seq_cst) const noexcept;
void notify_one() volatile noexcept;
void notify_one() noexcept;
void notify_all() volatile noexcept;
void notify_all() noexcept;
};
}

`T fetch_`*key*(T operand, memory_order order = memory_order::seq_cst) volatile noexcept;
T fetch_*key*(T operand, memory_order order = memory_order::seq_cst) noexcept;

Memory is affected according to the value of order.

These operations are atomic read-modify-write operations ([intro.multithread]).

Atomic arithmetic operations on *floating-point-type*
should conform to the std::numeric_limits<*floating-point-type*>
traits associated with the floating-point type ([limits.syn]).

`T operator `*op*=(T operand) volatile noexcept;
T operator *op*=(T operand) noexcept;

Atomic arithmetic operations on *floating-point-type*
should conform to the std::numeric_limits<*floating-point-type*>
traits associated with the floating-point type ([limits.syn]).

namespace std {
template<class T> struct atomic<T*> {
using value_type = T*;
using difference_type = ptrdiff_t;
static constexpr bool is_always_lock_free = *implementation-defined*;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
constexpr atomic() noexcept;
constexpr atomic(T*) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
void store(T*, memory_order = memory_order::seq_cst) volatile noexcept;
void store(T*, memory_order = memory_order::seq_cst) noexcept;
T* operator=(T*) volatile noexcept;
T* operator=(T*) noexcept;
T* load(memory_order = memory_order::seq_cst) const volatile noexcept;
T* load(memory_order = memory_order::seq_cst) const noexcept;
operator T*() const volatile noexcept;
operator T*() const noexcept;
T* exchange(T*, memory_order = memory_order::seq_cst) volatile noexcept;
T* exchange(T*, memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_weak(T*&, T*, memory_order, memory_order) volatile noexcept;
bool compare_exchange_weak(T*&, T*, memory_order, memory_order) noexcept;
bool compare_exchange_strong(T*&, T*, memory_order, memory_order) volatile noexcept;
bool compare_exchange_strong(T*&, T*, memory_order, memory_order) noexcept;
bool compare_exchange_weak(T*&, T*,
memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_weak(T*&, T*,
memory_order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(T*&, T*,
memory_order = memory_order::seq_cst) volatile noexcept;
bool compare_exchange_strong(T*&, T*,
memory_order = memory_order::seq_cst) noexcept;
T* fetch_add(ptrdiff_t, memory_order = memory_order::seq_cst) volatile noexcept;
T* fetch_add(ptrdiff_t, memory_order = memory_order::seq_cst) noexcept;
T* fetch_sub(ptrdiff_t, memory_order = memory_order::seq_cst) volatile noexcept;
T* fetch_sub(ptrdiff_t, memory_order = memory_order::seq_cst) noexcept;
T* fetch_max(T*, memory_order = memory_order::seq_cst) volatile noexcept;
T* fetch_max(T*, memory_order = memory_order::seq_cst) noexcept;
T* fetch_min(T*, memory_order = memory_order::seq_cst) volatile noexcept;
T* fetch_min(T*, memory_order = memory_order::seq_cst) noexcept;
T* operator++(int) volatile noexcept;
T* operator++(int) noexcept;
T* operator--(int) volatile noexcept;
T* operator--(int) noexcept;
T* operator++() volatile noexcept;
T* operator++() noexcept;
T* operator--() volatile noexcept;
T* operator--() noexcept;
T* operator+=(ptrdiff_t) volatile noexcept;
T* operator+=(ptrdiff_t) noexcept;
T* operator-=(ptrdiff_t) volatile noexcept;
T* operator-=(ptrdiff_t) noexcept;
void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept;
void wait(T*, memory_order = memory_order::seq_cst) const noexcept;
void notify_one() volatile noexcept;
void notify_one() noexcept;
void notify_all() volatile noexcept;
void notify_all() noexcept;
};
}

The following operations perform pointer arithmetic.

Table 150: Atomic pointer computations [tab:atomic.types.pointer.comp]

key | Op | Computation | key | Op | Computation | |

add | + | addition | sub | - | subtraction | |

max | maximum | min | minimum |

`T* fetch_`*key*(ptrdiff_t operand, memory_order order = memory_order::seq_cst) volatile noexcept;
T* fetch_*key*(ptrdiff_t operand, memory_order order = memory_order::seq_cst) noexcept;

Memory is affected according to the value of order.

These operations are atomic read-modify-write operations ([intro.multithread]).

For fetch_max and fetch_min, the maximum and minimum
computation is performed as if by max and min
algorithms ([alg.min.max]), respectively, with the object value and the first
parameter as the arguments.

[*Note 2*: *end note*]

If the pointers point to different complete objects (or subobjects thereof),
the < operator does not establish a strict weak ordering
(Table 29, [expr.rel]).

â€” `T* operator `*op*=(ptrdiff_t operand) volatile noexcept;
T* operator *op*=(ptrdiff_t operand) noexcept;

```
value_type operator++(int) volatile noexcept;
value_type operator++(int) noexcept;
```

```
value_type operator--(int) volatile noexcept;
value_type operator--(int) noexcept;
```

```
value_type operator++() volatile noexcept;
value_type operator++() noexcept;
```

```
value_type operator--() volatile noexcept;
value_type operator--() noexcept;
```

The library provides partial specializations of the atomic template
for shared-ownership smart pointers ([util.sharedptr]).

The behavior of all operations is as specified in [atomics.types.generic],
unless specified otherwise.

The template parameter T of these partial specializations
may be an incomplete type.

All changes to an atomic smart pointer in [util.smartptr.atomic], and
all associated use_count increments,
are guaranteed to be performed atomically.

Associated use_count decrements
are sequenced after the atomic operation,
but are not required to be part of it.

Any associated deletion and deallocation
are sequenced after the atomic update step and
are not part of the atomic operation.

[*Example 1*: template<typename T> class atomic_list {
struct node {
T t;
shared_ptr<node> next;
};
atomic<shared_ptr<node>> head;
public:
shared_ptr<node> find(T t) const {
auto p = head.load();
while (p && p->t != t)
p = p->next;
return p;
}
void push_front(T t) {
auto p = make_shared<node>();
p->t = t;
p->next = head;
while (!head.compare_exchange_weak(p->next, p)) {}
}
};
â€” *end example*]

namespace std {
template<class T> struct atomic<weak_ptr<T>> {
using value_type = weak_ptr<T>;
static constexpr bool is_always_lock_free = *implementation-defined*;
bool is_lock_free() const noexcept;
constexpr atomic() noexcept;
atomic(weak_ptr<T> desired) noexcept;
atomic(const atomic&) = delete;
void operator=(const atomic&) = delete;
weak_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;
operator weak_ptr<T>() const noexcept;
void store(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
void operator=(weak_ptr<T> desired) noexcept;
weak_ptr<T> exchange(weak_ptr<T> desired,
memory_order order = memory_order::seq_cst) noexcept;
bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order success, memory_order failure) noexcept;
bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order success, memory_order failure) noexcept;
bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order order = memory_order::seq_cst) noexcept;
bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order order = memory_order::seq_cst) noexcept;
void wait(weak_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;
void notify_one() noexcept;
void notify_all() noexcept;
private:
weak_ptr<T> p; // *exposition only*
};
}

```
constexpr atomic() noexcept;
```

```
atomic(weak_ptr<T> desired) noexcept;
```

Initialization is not an atomic operation ([intro.multithread]).

[*Note 1*: *end note*]

It is possible to have an access to
an atomic object A race with its construction,
for example,
by communicating the address of the just-constructed object A
to another thread via memory_order::relaxed operations
on a suitable atomic pointer variable, and
then immediately accessing A in the receiving thread.

This results in undefined behavior.

â€” ```
void store(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
```

```
void operator=(weak_ptr<T> desired) noexcept;
```

```
weak_ptr<T> load(memory_order order = memory_order::seq_cst) const noexcept;
```

```
operator weak_ptr<T>() const noexcept;
```

```
weak_ptr<T> exchange(weak_ptr<T> desired, memory_order order = memory_order::seq_cst) noexcept;
```

Memory is affected according to the value of order.

This is an atomic read-modify-write operation ([intro.races]).

```
bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order success, memory_order failure) noexcept;
bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order success, memory_order failure) noexcept;
```

If the operation returns true,
expected is not accessed after the atomic update and
the operation is an atomic read-modify-write operation ([intro.multithread])
on the memory pointed to by this.

Otherwise, the operation is an atomic load operation on that memory, and
expected is updated with the existing value
read from the atomic object in the attempted atomic update.

The write to expected itself
is not required to be part of the atomic operation.

```
bool compare_exchange_weak(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order order = memory_order::seq_cst) noexcept;
```

```
bool compare_exchange_strong(weak_ptr<T>& expected, weak_ptr<T> desired,
memory_order order = memory_order::seq_cst) noexcept;
```

```
void wait(weak_ptr<T> old, memory_order order = memory_order::seq_cst) const noexcept;
```

This function is an atomic waiting operation ([atomics.wait]).

```
void notify_one() noexcept;
```

```
void notify_all() noexcept;
```