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// void swap(stop_token& rhs) noexcept;
14
15#include <cassert>
16#include <concepts>
17#include <stop_token>
18#include <type_traits>
19
20#include "test_macros.h"
21
22template <class T>
23concept IsNoThrowMemberSwappable = requires(T& t) {
24 { t.swap(t) } noexcept;
25};
26
27static_assert(IsNoThrowMemberSwappable<std::stop_token>);
28
29int main(int, char**) {
30 {
31 std::stop_token st1;
32
33 std::stop_source source;
34 auto st2 = source.get_token();
35
36 assert(st1 != st2);
37
38 source.request_stop();
39
40 assert(!st1.stop_requested());
41 assert(st2.stop_requested());
42
43 st1.swap(st2);
44
45 assert(st1 != st2);
46 assert(st1.stop_requested());
47 assert(!st2.stop_requested());
48 }
49
50 return 0;
51}
52

source code of libcxx/test/std/thread/thread.stoptoken/stoptoken/swap.member.pass.cpp