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// REQUIRES: std-at-least-c++26
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// Test SFINAE.
27
28static_assert(
29 HasOperatorEqual<std::reference_wrapper<EqualityComparable>, std::reference_wrapper<const EqualityComparable>>);
30
31static_assert(
32 !HasOperatorEqual<std::reference_wrapper<EqualityComparable>, std::reference_wrapper<const NonComparable>>);
33
34// Test equality.
35
36template <typename T>
37constexpr void test() {
38 T i{92};
39 T j{84};
40
41 std::reference_wrapper<T> rw1{i};
42
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(crw1)>();
48 assert(testEquality(rw1, crw1, true));
49 assert(testEquality(rw1, crw3, false));
50}
51
52constexpr bool test() {
53 test<int>();
54 test<EqualityComparable>();
55
56 return true;
57}
58
59int main(int, char**) {
60 test();
61 static_assert(test());
62
63 return 0;
64}
65

source code of libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp