1*b77e50e6SHui //===----------------------------------------------------------------------===// 2*b77e50e6SHui // 3*b77e50e6SHui // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*b77e50e6SHui // See https://llvm.org/LICENSE.txt for license information. 5*b77e50e6SHui // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*b77e50e6SHui // 7*b77e50e6SHui //===----------------------------------------------------------------------===// 8*b77e50e6SHui // 9*b77e50e6SHui // UNSUPPORTED: no-threads 10*b77e50e6SHui // UNSUPPORTED: c++03, c++11, c++14, c++17 11*b77e50e6SHui // XFAIL: availability-synchronization_library-missing 12*b77e50e6SHui 13*b77e50e6SHui // [[nodiscard]] bool operator==(const stop_source& lhs, const stop_source& rhs) noexcept; 14*b77e50e6SHui // 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. 15*b77e50e6SHui 16*b77e50e6SHui #include <cassert> 17*b77e50e6SHui #include <concepts> 18*b77e50e6SHui #include <stop_token> 19*b77e50e6SHui #include <type_traits> 20*b77e50e6SHui 21*b77e50e6SHui #include "test_macros.h" 22*b77e50e6SHui 23*b77e50e6SHui template <class T> 24*b77e50e6SHui concept IsNoThrowEqualityComparable = requires(const T& t1, const T& t2) { 25*b77e50e6SHui { t1 == t2 } noexcept; 26*b77e50e6SHui }; 27*b77e50e6SHui 28*b77e50e6SHui static_assert(IsNoThrowEqualityComparable<std::stop_source>); 29*b77e50e6SHui 30*b77e50e6SHui int main(int, char**) { 31*b77e50e6SHui // both no state 32*b77e50e6SHui { 33*b77e50e6SHui const std::stop_source ss1(std::nostopstate); 34*b77e50e6SHui const std::stop_source ss2(std::nostopstate); 35*b77e50e6SHui assert(ss1 == ss2); 36*b77e50e6SHui assert(!(ss1 != ss2)); 37*b77e50e6SHui } 38*b77e50e6SHui 39*b77e50e6SHui // only one has no state 40*b77e50e6SHui { 41*b77e50e6SHui const std::stop_source ss1(std::nostopstate); 42*b77e50e6SHui const std::stop_source ss2; 43*b77e50e6SHui assert(!(ss1 == ss2)); 44*b77e50e6SHui assert(ss1 != ss2); 45*b77e50e6SHui } 46*b77e50e6SHui 47*b77e50e6SHui // both has states. same state 48*b77e50e6SHui { 49*b77e50e6SHui const std::stop_source ss1; 50*b77e50e6SHui const std::stop_source ss2(ss1); 51*b77e50e6SHui assert(ss1 == ss2); 52*b77e50e6SHui assert(!(ss1 != ss2)); 53*b77e50e6SHui } 54*b77e50e6SHui 55*b77e50e6SHui // both has states. different states 56*b77e50e6SHui { 57*b77e50e6SHui const std::stop_source ss1; 58*b77e50e6SHui const std::stop_source ss2; 59*b77e50e6SHui assert(!(ss1 == ss2)); 60*b77e50e6SHui assert(ss1 != ss2); 61*b77e50e6SHui } 62*b77e50e6SHui 63*b77e50e6SHui return 0; 64*b77e50e6SHui } 65