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