1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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;
17 #include <type_traits>
19 #include "make_test_thread.h"
20 #include "test_macros.h"
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
33 std::jthread t2
= support::make_test_jthread([] {});
34 const auto originalId2
= t2
.get_id();
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([] {});
45 const auto originalId1
= t1
.get_id();
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();
60 assert(t1
.get_id() == originalId2
);
61 assert(t2
.get_id() == originalId1
);
64 // both default constructed
70 assert(t1
.get_id() == std::jthread::id());
71 assert(t2
.get_id() == std::jthread::id());