brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 98df0a4 Raw
50 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++03, c++11, c++14, c++1711 12// [[nodiscard]] stop_token get_token() const noexcept;13 14#include <cassert>15#include <concepts>16#include <stop_token>17#include <type_traits>18 19#include "test_macros.h"20 21template <class T>22concept IsGetTokenNoexcept = requires(const T& t) {23  { t.get_token() } noexcept;24};25 26static_assert(IsGetTokenNoexcept<std::stop_source>);27 28int main(int, char**) {29  // no state30  {31    std::stop_source ss{std::nostopstate};32    std::same_as<std::stop_token> decltype(auto) st = ss.get_token();33    assert(!st.stop_possible());34    assert(!st.stop_requested());35  }36 37  // with state38  {39    std::stop_source ss;40    std::same_as<std::stop_token> decltype(auto) st = ss.get_token();41    assert(st.stop_possible());42    assert(!st.stop_requested());43 44    ss.request_stop();45    assert(st.stop_requested());46  }47 48  return 0;49}50