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