[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.jthread / swap.member.pass.cpp
blob8ae17f435aa31b1398ddee3ffb290f05ef0b502e
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: libcpp-has-no-experimental-stop_token
11 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // XFAIL: availability-synchronization_library-missing
14 // void swap(jthread& x) noexcept;
16 #include <cassert>
17 #include <thread>
18 #include <type_traits>
20 #include "make_test_thread.h"
21 #include "test_macros.h"
23 template <class T>
24 concept IsMemberSwapNoexcept = requires(T& a, T& b) {
25 { a.swap(b) } noexcept;
28 static_assert(IsMemberSwapNoexcept<std::jthread>);
30 int main(int, char**) {
31 // this is default constructed
33 std::jthread t1;
34 std::jthread t2 = support::make_test_jthread([] {});
35 const auto originalId2 = t2.get_id();
36 t1.swap(t2);
38 assert(t1.get_id() == originalId2);
39 assert(t2.get_id() == std::jthread::id());
42 // that is default constructed
44 std::jthread t1 = support::make_test_jthread([] {});
45 std::jthread t2{};
46 const auto originalId1 = t1.get_id();
47 t1.swap(t2);
49 assert(t1.get_id() == std::jthread::id());
50 assert(t2.get_id() == originalId1);
53 // both not default constructed
55 std::jthread t1 = support::make_test_jthread([] {});
56 std::jthread t2 = support::make_test_jthread([] {});
57 const auto originalId1 = t1.get_id();
58 const auto originalId2 = t2.get_id();
59 t1.swap(t2);
61 assert(t1.get_id() == originalId2);
62 assert(t2.get_id() == originalId1);
65 // both default constructed
67 std::jthread t1;
68 std::jthread t2;
69 t1.swap(t2);
71 assert(t1.get_id() == std::jthread::id());
72 assert(t2.get_id() == std::jthread::id());
75 return 0;