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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
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 |
13 | |
14 | // [[nodiscard]] bool operator==(const stop_source& lhs, const stop_source& 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. |
16 | |
17 | #include <cassert> |
18 | #include <concepts> |
19 | #include <stop_token> |
20 | #include <type_traits> |
21 | |
22 | #include "test_macros.h" |
23 | |
24 | template <class T> |
25 | concept IsNoThrowEqualityComparable = requires(const T& t1, const T& t2) { |
26 | { t1 == t2 } noexcept; |
27 | }; |
28 | |
29 | static_assert(IsNoThrowEqualityComparable<std::stop_source>); |
30 | |
31 | int main(int, char**) { |
32 | // both no state |
33 | { |
34 | const std::stop_source ss1(std::nostopstate); |
35 | const std::stop_source ss2(std::nostopstate); |
36 | assert(ss1 == ss2); |
37 | assert(!(ss1 != ss2)); |
38 | } |
39 | |
40 | // only one has no state |
41 | { |
42 | const std::stop_source ss1(std::nostopstate); |
43 | const std::stop_source ss2; |
44 | assert(!(ss1 == ss2)); |
45 | assert(ss1 != ss2); |
46 | } |
47 | |
48 | // both has states. same state |
49 | { |
50 | const std::stop_source ss1; |
51 | const std::stop_source ss2(ss1); |
52 | assert(ss1 == ss2); |
53 | assert(!(ss1 != ss2)); |
54 | } |
55 | |
56 | // both has states. different states |
57 | { |
58 | const std::stop_source ss1; |
59 | const std::stop_source ss2; |
60 | assert(!(ss1 == ss2)); |
61 | assert(ss1 != ss2); |
62 | } |
63 | |
64 | return 0; |
65 | } |
66 | |