64 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]] bool operator==(const stop_source& lhs, const stop_source& rhs) noexcept;13// Returns: true if lhs and rhs have ownership of the same stop state or if both lhs and rhs do not have ownership of a stop state; otherwise false.14 15#include <cassert>16#include <concepts>17#include <stop_token>18#include <type_traits>19 20#include "test_macros.h"21 22template <class T>23concept IsNoThrowEqualityComparable = requires(const T& t1, const T& t2) {24 { t1 == t2 } noexcept;25};26 27static_assert(IsNoThrowEqualityComparable<std::stop_source>);28 29int main(int, char**) {30 // both no state31 {32 const std::stop_source ss1(std::nostopstate);33 const std::stop_source ss2(std::nostopstate);34 assert(ss1 == ss2);35 assert(!(ss1 != ss2));36 }37 38 // only one has no state39 {40 const std::stop_source ss1(std::nostopstate);41 const std::stop_source ss2;42 assert(!(ss1 == ss2));43 assert(ss1 != ss2);44 }45 46 // both has states. same state47 {48 const std::stop_source ss1;49 const std::stop_source ss2(ss1);50 assert(ss1 == ss2);51 assert(!(ss1 != ss2));52 }53 54 // both has states. different states55 {56 const std::stop_source ss1;57 const std::stop_source ss2;58 assert(!(ss1 == ss2));59 assert(ss1 != ss2);60 }61 62 return 0;63}64