42 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_source get_stop_source() noexcept;13 14#include <cassert>15#include <concepts>16#include <stop_token>17#include <thread>18#include <type_traits>19 20#include "make_test_thread.h"21#include "test_macros.h"22 23static_assert(noexcept(std::declval<std::jthread&>().get_stop_source()));24 25int main(int, char**) {26 // Represents a thread27 {28 std::jthread jt = support::make_test_jthread([] {});29 std::same_as<std::stop_source> decltype(auto) result = jt.get_stop_source();30 assert(result.stop_possible());31 }32 33 // Does not represents a thread34 {35 std::jthread jt{};36 std::same_as<std::stop_source> decltype(auto) result = jt.get_stop_source();37 assert(!result.stop_possible());38 }39 40 return 0;41}42