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: c++03, c++11, c++14, c++17, c++20, c++23 |
10 | |
11 | // <functional> |
12 | |
13 | // class reference_wrapper |
14 | |
15 | // [refwrap.comparisons], comparisons |
16 | |
17 | // friend constexpr bool operator==(reference_wrapper, const T&); // Since C++26 |
18 | |
19 | #include <cassert> |
20 | #include <concepts> |
21 | #include <functional> |
22 | |
23 | #include "test_comparisons.h" |
24 | #include "test_macros.h" |
25 | |
26 | #include "helper_concepts.h" |
27 | #include "helper_types.h" |
28 | |
29 | // Test SFINAE. |
30 | |
31 | static_assert(HasEqualityOperatorWithInt<std::reference_wrapper<EqualityComparable>>); |
32 | |
33 | static_assert(!HasEqualityOperatorWithInt<std::reference_wrapper<NonComparable>>); |
34 | |
35 | // Test equality. |
36 | |
37 | template <typename T> |
38 | constexpr void test() { |
39 | T i{92}; |
40 | T j{84}; |
41 | |
42 | std::reference_wrapper<T> rw1{i}; |
43 | |
44 | // refwrap, const& |
45 | AssertEqualityReturnBool<decltype(rw1), decltype(i)>(); |
46 | assert(testEquality(rw1, i, true)); |
47 | assert(testEquality(rw1, j, false)); |
48 | } |
49 | |
50 | constexpr bool test() { |
51 | test<int>(); |
52 | test<EqualityComparable>(); |
53 | |
54 | return true; |
55 | } |
56 | |
57 | int main(int, char**) { |
58 | test(); |
59 | static_assert(test()); |
60 | |
61 | return 0; |
62 | } |
63 | |