TargetParser: AArch64: Add part numbers for Apple CPUs.
[llvm-project.git] / libcxx / test / std / thread / thread.jthread / swap.member.pass.cpp
blob9a14ecf4fb7d0fb402c9a8e482af2d555ac7c0f5
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // XFAIL: availability-synchronization_library-missing
13 // void swap(jthread& x) noexcept;
15 #include <cassert>
16 #include <thread>
17 #include <type_traits>
19 #include "make_test_thread.h"
20 #include "test_macros.h"
22 template <class T>
23 concept IsMemberSwapNoexcept = requires(T& a, T& b) {
24 { a.swap(b) } noexcept;
27 static_assert(IsMemberSwapNoexcept<std::jthread>);
29 int main(int, char**) {
30 // this is default constructed
32 std::jthread t1;
33 std::jthread t2 = support::make_test_jthread([] {});
34 const auto originalId2 = t2.get_id();
35 t1.swap(t2);
37 assert(t1.get_id() == originalId2);
38 assert(t2.get_id() == std::jthread::id());
41 // that is default constructed
43 std::jthread t1 = support::make_test_jthread([] {});
44 std::jthread t2{};
45 const auto originalId1 = t1.get_id();
46 t1.swap(t2);
48 assert(t1.get_id() == std::jthread::id());
49 assert(t2.get_id() == originalId1);
52 // both not default constructed
54 std::jthread t1 = support::make_test_jthread([] {});
55 std::jthread t2 = support::make_test_jthread([] {});
56 const auto originalId1 = t1.get_id();
57 const auto originalId2 = t2.get_id();
58 t1.swap(t2);
60 assert(t1.get_id() == originalId2);
61 assert(t2.get_id() == originalId1);
64 // both default constructed
66 std::jthread t1;
67 std::jthread t2;
68 t1.swap(t2);
70 assert(t1.get_id() == std::jthread::id());
71 assert(t2.get_id() == std::jthread::id());
74 return 0;