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, 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(HasOperatorEqual<std::reference_wrapper<EqualityComparable>>);
29static_assert(HasOperatorEqual<std::reference_wrapper<EqualityComparable>, int>);
30
31static_assert(!HasOperatorEqual<std::reference_wrapper<NonComparable>>);
32static_assert(!HasOperatorEqual<std::reference_wrapper<NonComparable>, int>);
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 // refwrap, const&
44 AssertEqualityReturnBool<decltype(rw1), decltype(i)>();
45 assert(testEquality(rw1, i, true));
46 assert(testEquality(rw1, j, false));
47}
48
49constexpr bool test() {
50 test<int>();
51 test<EqualityComparable>();
52
53 return true;
54}
55
56int main(int, char**) {
57 test();
58 static_assert(test());
59
60 return 0;
61}
62

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