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 ;
(C++26부터 constexpr)

참조된 객체의 값을 원자적으로 desired 로 교체합니다. 이 연산은 읽기-수정-쓰기 연산입니다. 메모리는 order 값에 따라 영향을 받습니다.

이 오버로드는 std:: is_const_v < T > false 인 경우에만 오버로드 해결에 참여합니다.

매개변수

desired - 할당할 값
order - 적용할 메모리 순서 제약 조건

반환값

호출 전 참조된 객체의 값.

결함 보고서

다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 3508
( P3323R1 )
C++20 exchange const T 에 대해 무의미했음 비-const T 만 수용하도록 제약됨