1 //===----------------------------------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: libcpp-has-no-experimental-stop_token
11 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // XFAIL: availability-synchronization_library-missing
14 // [[nodiscard]] bool operator==(const stop_token& lhs, const stop_token& rhs) noexcept;
15 // 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.
17 // synthesized operator != also tested.
22 #include <type_traits>
24 #include "test_macros.h"
26 // LWG 3254 is related.
28 concept IsNoThrowEqualityComparable
= requires(const T
& t1
, const T
& t2
) {
29 { t1
== t2
} noexcept
;
33 concept IsNoThrowInequalityComparable
= requires(const T
& t1
, const T
& t2
) {
34 { t1
!= t2
} noexcept
;
37 static_assert(IsNoThrowEqualityComparable
<std::stop_token
>);
38 static_assert(IsNoThrowInequalityComparable
<std::stop_token
>);
40 int main(int, char**) {
43 const std::stop_token st1
;
44 const std::stop_token st2
;
46 assert(!(st1
!= st2
));
49 // only one has no state
52 const std::stop_token st1
;
53 const auto st2
= ss
.get_token();
54 assert(!(st1
== st2
));
58 // both has states. same source
61 const auto st1
= ss
.get_token();
62 const auto st2
= ss
.get_token();
64 assert(!(st1
!= st2
));
67 // both has states. different sources with same states
71 const auto st1
= ss1
.get_token();
72 const auto st2
= ss2
.get_token();
74 assert(!(st1
!= st2
));
77 // both has states. different sources with different states
81 const auto st1
= ss1
.get_token();
82 const auto st2
= ss2
.get_token();
83 assert(!(st1
== st2
));