brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · eadde8d Raw
68 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// stop_source(const stop_source&) noexcept;13 14#include <cassert>15#include <optional>16#include <stop_token>17#include <type_traits>18 19#include "test_macros.h"20 21static_assert(std::is_nothrow_copy_constructible_v<std::stop_source>);22 23int main(int, char**) {24  {25    std::stop_source source;26    std::stop_source copy{source};27 28    assert(source == copy);29 30    assert(source.stop_possible());31    assert(!source.stop_requested());32 33    assert(copy.stop_possible());34    assert(!copy.stop_requested());35 36    source.request_stop();37    assert(source.stop_possible());38    assert(source.stop_requested());39 40    assert(copy.stop_possible());41    assert(copy.stop_requested());42  }43 44  // source counter incremented45  {46    std::optional<std::stop_source> source(std::in_place);47    auto st = source->get_token();48    assert(st.stop_possible());49 50    std::optional<std::stop_source> copy{source};51    source.reset();52 53    assert(st.stop_possible());54 55    copy.reset();56    assert(!st.stop_possible());57  }58 59  // copy from empty60  {61    std::stop_source ss1{std::nostopstate};62    std::stop_source copy{ss1};63    assert(!copy.stop_possible());64  }65 66  return 0;67}68