[llvm][Docs] Explain how to handle excessive formatting changes (#126239)
[llvm-project.git] / libcxx / test / std / thread / thread.stoptoken / stopsource / move.copy.pass.cpp
blob09b479611b7fe9d611a6569dc70e5d3fe4f2ad03
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 // stop_source& operator=(stop_source&& rhs) noexcept;
15 #include <cassert>
16 #include <concepts>
17 #include <stop_token>
18 #include <type_traits>
19 #include <utility>
21 #include "test_macros.h"
23 static_assert(std::is_nothrow_move_assignable_v<std::stop_source>);
25 int main(int, char**) {
26 // have two different states
28 std::stop_source ss1;
29 std::stop_source ss2;
31 assert(ss1 != ss2);
33 ss2.request_stop();
35 assert(!ss1.stop_requested());
36 assert(ss2.stop_requested());
38 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = std::move(ss2);
39 assert(&ref == &ss1);
41 assert(ss1.stop_requested());
42 assert(!ss2.stop_possible());
43 assert(!ss2.stop_requested());
46 // this has no state
48 std::stop_source ss1{std::nostopstate};
49 std::stop_source ss2;
51 assert(ss1 != ss2);
53 ss2.request_stop();
55 assert(!ss1.stop_requested());
56 assert(!ss1.stop_possible());
57 assert(ss2.stop_requested());
58 assert(ss2.stop_possible());
60 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = std::move(ss2);
61 assert(&ref == &ss1);
63 assert(ss1.stop_requested());
64 assert(ss1.stop_possible());
65 assert(!ss2.stop_requested());
66 assert(!ss2.stop_possible());
69 // other has no state
71 std::stop_source ss1;
72 std::stop_source ss2{std::nostopstate};
74 assert(ss1 != ss2);
76 ss1.request_stop();
78 assert(ss1.stop_requested());
79 assert(ss1.stop_possible());
80 assert(!ss2.stop_requested());
81 assert(!ss2.stop_possible());
83 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = std::move(ss2);
84 assert(&ref == &ss1);
86 assert(ss1 == ss2);
87 assert(!ss1.stop_requested());
88 assert(!ss1.stop_possible());
89 assert(!ss2.stop_requested());
90 assert(!ss2.stop_possible());
93 // both no state
95 std::stop_source ss1{std::nostopstate};
96 std::stop_source ss2{std::nostopstate};
98 assert(ss1 == ss2);
100 assert(!ss1.stop_requested());
101 assert(!ss1.stop_possible());
102 assert(!ss2.stop_requested());
103 assert(!ss2.stop_possible());
105 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = std::move(ss2);
106 assert(&ref == &ss1);
108 assert(ss1 == ss2);
109 assert(!ss1.stop_requested());
110 assert(!ss1.stop_possible());
111 assert(!ss2.stop_requested());
112 assert(!ss2.stop_possible());
115 // self assignment
117 std::stop_source ss;
118 auto& self = ss;
120 assert(!ss.stop_requested());
122 std::same_as<std::stop_source&> decltype(auto) ref = ss = std::move(self);
123 assert(&ref == &ss);
125 assert(!ss.stop_requested());
127 ss.request_stop();
128 assert(ss.stop_requested());
131 return 0;