brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · e9651e7 Raw
41 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]] id get_id() const noexcept;13 14#include <cassert>15#include <concepts>16#include <thread>17#include <type_traits>18 19#include "make_test_thread.h"20#include "test_macros.h"21 22static_assert(noexcept(std::declval<const std::jthread&>().get_id()));23 24int main(int, char**) {25  // Does not represent a thread26  {27    const std::jthread jt;28    std::same_as<std::jthread::id> decltype(auto) result = jt.get_id();29    assert(result == std::jthread::id());30  }31 32  // Represents a thread33  {34    const std::jthread jt                                = support::make_test_jthread([] {});35    std::same_as<std::jthread::id> decltype(auto) result = jt.get_id();36    assert(result != std::jthread::id());37  }38 39  return 0;40}41