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, 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(std::equality_comparable_with<std::reference_wrapper<EqualityComparable>,
32                                             std::reference_wrapper<const EqualityComparable>>);
33 
34 static_assert(!std::equality_comparable_with<std::reference_wrapper<EqualityComparable>,
35                                              std::reference_wrapper<const NonComparable>>);
36 
37 // Test equality.
38 
39 template <typename T>
test()40 constexpr void test() {
41   T i{92};
42   T j{84};
43 
44   std::reference_wrapper<T> rw1{i};
45 
46   std::reference_wrapper<T> rw3{j};
47   std::reference_wrapper<const T> crw1{i};
48   std::reference_wrapper<const T> crw3{j};
49 
50   AssertEqualityReturnBool<decltype(rw1), decltype(crw1)>();
51   assert(testEquality(rw1, crw1, true));
52   assert(testEquality(rw1, crw3, false));
53 }
54 
test()55 constexpr bool test() {
56   test<int>();
57   test<EqualityComparable>();
58 
59   return true;
60 }
61 
main(int,char **)62 int main(int, char**) {
63   test();
64   static_assert(test());
65 
66   return 0;
67 }
68