Namespaces
Variants

std::atomic_ref<T>:: exchange

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
value_type exchange ( value_type desired,

std:: memory_order order =

std:: memory_order_seq_cst ) const noexcept ;
(constexpr since C++26)

参照先オブジェクトの値をアトミックに desired で置き換えます。この操作はread-modify-write操作です。メモリは order の値に従って影響を受けます。

このオーバーロードは、 std:: is_const_v < T > false の場合にのみ、オーバーロード解決に参加します。

パラメータ

desired - 割り当てる値
order - 適用するメモリ順序制約

戻り値

呼び出し前の参照先オブジェクトの値。

不具合報告

以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR 適用対象 公開時の動作 正しい動作
LWG 3508
( P3323R1 )
C++20 exchange const T に対して無意味であった 非constの T のみを受け入れるように制約