| 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 |
// [[nodiscard]] bool stop_possible() const noexcept; |
| 15 |
// Returns: true if *this has ownership of a stop state; otherwise, false. |
| 16 |
|
| 17 |
#include <cassert> |
| 18 |
#include <stop_token> |
| 19 |
#include <type_traits> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
|
| 23 |
template <class T> |
| 24 |
concept IsStopPossibleNoexcept = requires(const T& t) { |
| 25 |
{ t.stop_possible() } noexcept; |
| 26 |
}; |
| 27 |
|
| 28 |
static_assert(IsStopPossibleNoexcept<std::stop_source>); |
| 29 |
|
| 30 |
int main(int, char**) { |
| 31 |
// no state |
| 32 |
{ |
| 33 |
const std::stop_source st{std::nostopstate}; |
| 34 |
assert(!st.stop_possible()); |
| 35 |
} |
| 36 |
|
| 37 |
// with state |
| 38 |
{ |
| 39 |
const std::stop_source st; |
| 40 |
assert(st.stop_possible()); |
| 41 |
} |
| 42 |
|
| 43 |
return 0; |
| 44 |
} |