xref: /llvm-project/libcxx/test/std/thread/thread.stoptoken/stoptoken/assign.move.pass.cpp (revision 121ed5c1985356436d0040dbe81bca26992b1fae)
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
12 
13 // stop_token& operator=(stop_token&& rhs) noexcept;
14 
15 #include <cassert>
16 #include <concepts>
17 #include <stop_token>
18 #include <type_traits>
19 #include <utility>
20 
21 #include "test_macros.h"
22 
23 static_assert(std::is_nothrow_move_assignable_v<std::stop_token>);
24 
25 int main(int, char**) {
26   {
27     std::stop_token st1;
28 
29     std::stop_source source;
30     auto st2 = source.get_token();
31 
32     assert(st1 != st2);
33 
34     source.request_stop();
35 
36     assert(!st1.stop_requested());
37     assert(st2.stop_requested());
38 
39     std::same_as<std::stop_token&> decltype(auto) ref = st1 = std::move(st2);
40     assert(&ref == &st1);
41 
42     assert(st1 != st2);
43     assert(st1.stop_requested());
44     assert(!st2.stop_requested());
45   }
46 
47   return 0;
48 }
49