brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 45531fa Raw
132 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& operator=(const stop_source& rhs) noexcept;13 14#include <cassert>15#include <concepts>16#include <stop_token>17#include <type_traits>18 19#include "test_macros.h"20 21static_assert(std::is_nothrow_copy_assignable_v<std::stop_source>);22 23int main(int, char**) {24  // have two different states25  {26    std::stop_source ss1;27    std::stop_source ss2;28 29    assert(ss1 != ss2);30 31    ss2.request_stop();32 33    assert(!ss1.stop_requested());34    assert(ss2.stop_requested());35 36    std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2;37    assert(&ref == &ss1);38 39    assert(ss1 == ss2);40    assert(ss1.stop_requested());41    assert(ss2.stop_requested());42  }43 44  // this has no state45  {46    std::stop_source ss1{std::nostopstate};47    std::stop_source ss2;48 49    assert(ss1 != ss2);50 51    ss2.request_stop();52 53    assert(!ss1.stop_requested());54    assert(!ss1.stop_possible());55    assert(ss2.stop_requested());56    assert(ss2.stop_possible());57 58    std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2;59    assert(&ref == &ss1);60 61    assert(ss1 == ss2);62    assert(ss1.stop_requested());63    assert(ss1.stop_possible());64    assert(ss2.stop_requested());65    assert(ss2.stop_possible());66  }67 68  // other has no state69  {70    std::stop_source ss1;71    std::stop_source ss2{std::nostopstate};72 73    assert(ss1 != ss2);74 75    ss1.request_stop();76 77    assert(ss1.stop_requested());78    assert(ss1.stop_possible());79    assert(!ss2.stop_requested());80    assert(!ss2.stop_possible());81 82    std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2;83    assert(&ref == &ss1);84 85    assert(ss1 == ss2);86    assert(!ss1.stop_requested());87    assert(!ss1.stop_possible());88    assert(!ss2.stop_requested());89    assert(!ss2.stop_possible());90  }91 92  // both no state93  {94    std::stop_source ss1{std::nostopstate};95    std::stop_source ss2{std::nostopstate};96 97    assert(ss1 == ss2);98 99    assert(!ss1.stop_requested());100    assert(!ss1.stop_possible());101    assert(!ss2.stop_requested());102    assert(!ss2.stop_possible());103 104    std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2;105    assert(&ref == &ss1);106 107    assert(ss1 == ss2);108    assert(!ss1.stop_requested());109    assert(!ss1.stop_possible());110    assert(!ss2.stop_requested());111    assert(!ss2.stop_possible());112  }113 114  // self assignment115  {116    std::stop_source ss;117    auto& self = ss;118 119    assert(!ss.stop_requested());120 121    std::same_as<std::stop_source&> decltype(auto) ref = ss = self;122    assert(&ref == &ss);123 124    assert(!ss.stop_requested());125 126    ss.request_stop();127    assert(ss.stop_requested());128  }129 130  return 0;131}132