Debian Codegraph @

libcxx/test/std/atomics/atomics.ref/exchange.pass.cpp

raw
1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // XFAIL: !has-64-bit-atomics
10 // XFAIL: !has-1024-bit-atomics
11
12 // T exchange(T, memory_order = memory_order::seq_cst) const noexcept;
13
14 #include <atomic>
15 #include <cassert>
16 #include <concepts>
17 #include <type_traits>
18
19 #include "atomic_helpers.h"
20 #include "test_macros.h"
21
22 template <typename T>
23 struct TestExchange {
24 void operator()() const {
25 T x(T(1));
26 std::atomic_ref<T> const a(x);
27
28 {
29 std::same_as<T> decltype(auto) y = a.exchange(T(2));
30 assert(y == T(1));
31 ASSERT_NOEXCEPT(a.exchange(T(2)));
32 }
33
34 {
35 std::same_as<T> decltype(auto) y = a.exchange(T(3), std::memory_order_seq_cst);
36 assert(y == T(2));
37 ASSERT_NOEXCEPT(a.exchange(T(3), std::memory_order_seq_cst));
38 }
39 }
40 };
41
42 int main(int, char**) {
43 TestEachAtomicType<TestExchange>()();
44 return 0;
45 }