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