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
10
11// template<class T>
12// concept equality_comparable = // see below
13
14#include <concepts>
15
16#include <array>
17#include <deque>
18#include <forward_list>
19#include <list>
20#include <map>
21#include <memory>
22#include <optional>
23#include <set>
24#include <unordered_map>
25#include <unordered_set>
26#include <vector>
27
28#include "compare_types.h"
29
30namespace fundamentals {
31static_assert(std::equality_comparable<int>);
32static_assert(std::equality_comparable<double>);
33static_assert(std::equality_comparable<void*>);
34static_assert(std::equality_comparable<char*>);
35static_assert(std::equality_comparable<char const*>);
36static_assert(std::equality_comparable<char volatile*>);
37static_assert(std::equality_comparable<char const volatile*>);
38static_assert(std::equality_comparable<wchar_t&>);
39static_assert(std::equality_comparable<char8_t const&>);
40static_assert(std::equality_comparable<char16_t volatile&>);
41static_assert(std::equality_comparable<char32_t const volatile&>);
42static_assert(std::equality_comparable<unsigned char&&>);
43static_assert(std::equality_comparable<unsigned short const&&>);
44static_assert(std::equality_comparable<unsigned int volatile&&>);
45static_assert(std::equality_comparable<unsigned long const volatile&&>);
46static_assert(std::equality_comparable<int[5]>);
47static_assert(std::equality_comparable<int (*)(int)>);
48static_assert(std::equality_comparable<int (&)(int)>);
49static_assert(std::equality_comparable<int (*)(int) noexcept>);
50static_assert(std::equality_comparable<int (&)(int) noexcept>);
51static_assert(std::equality_comparable<std::nullptr_t>);
52
53struct S {};
54static_assert(std::equality_comparable<int S::*>);
55static_assert(std::equality_comparable<int (S::*)()>);
56static_assert(std::equality_comparable<int (S::*)() noexcept>);
57static_assert(std::equality_comparable<int (S::*)() &>);
58static_assert(std::equality_comparable<int (S::*)() & noexcept>);
59static_assert(std::equality_comparable<int (S::*)() &&>);
60static_assert(std::equality_comparable<int (S::*)() && noexcept>);
61static_assert(std::equality_comparable<int (S::*)() const>);
62static_assert(std::equality_comparable<int (S::*)() const noexcept>);
63static_assert(std::equality_comparable<int (S::*)() const&>);
64static_assert(std::equality_comparable<int (S::*)() const & noexcept>);
65static_assert(std::equality_comparable<int (S::*)() const&&>);
66static_assert(std::equality_comparable<int (S::*)() const && noexcept>);
67static_assert(std::equality_comparable<int (S::*)() volatile>);
68static_assert(std::equality_comparable<int (S::*)() volatile noexcept>);
69static_assert(std::equality_comparable<int (S::*)() volatile&>);
70static_assert(std::equality_comparable<int (S::*)() volatile & noexcept>);
71static_assert(std::equality_comparable<int (S::*)() volatile&&>);
72static_assert(std::equality_comparable<int (S::*)() volatile && noexcept>);
73static_assert(std::equality_comparable<int (S::*)() const volatile>);
74static_assert(std::equality_comparable<int (S::*)() const volatile noexcept>);
75static_assert(std::equality_comparable<int (S::*)() const volatile&>);
76static_assert(std::equality_comparable<int (S::*)() const volatile & noexcept>);
77static_assert(std::equality_comparable<int (S::*)() const volatile&&>);
78static_assert(
79 std::equality_comparable<int (S::*)() const volatile && noexcept>);
80
81static_assert(!std::equality_comparable<void>);
82} // namespace fundamentals
83
84namespace standard_types {
85static_assert(std::equality_comparable<std::array<int, 10>>);
86static_assert(std::equality_comparable<std::deque<int>>);
87static_assert(std::equality_comparable<std::forward_list<int>>);
88static_assert(std::equality_comparable<std::list<int>>);
89static_assert(std::equality_comparable<std::map<int, void*>>);
90static_assert(std::equality_comparable<std::optional<int>>);
91static_assert(std::equality_comparable<std::set<int>>);
92static_assert(std::equality_comparable<std::unordered_map<int, void*>>);
93static_assert(std::equality_comparable<std::unordered_set<int>>);
94static_assert(std::equality_comparable<std::vector<bool>>);
95static_assert(std::equality_comparable<std::vector<int>>);
96} // namespace standard_types
97
98namespace types_fit_for_purpose {
99static_assert(std::equality_comparable<cxx20_member_eq>);
100static_assert(std::equality_comparable<cxx20_friend_eq>);
101static_assert(std::equality_comparable<member_three_way_comparable>);
102static_assert(std::equality_comparable<friend_three_way_comparable>);
103static_assert(std::equality_comparable<explicit_operators>);
104static_assert(std::equality_comparable<different_return_types>);
105static_assert(std::equality_comparable<one_member_one_friend>);
106static_assert(std::equality_comparable<equality_comparable_with_ec1>);
107
108static_assert(!std::equality_comparable<no_eq>);
109static_assert(!std::equality_comparable<no_neq>);
110static_assert(std::equality_comparable<no_lt>);
111static_assert(std::equality_comparable<no_gt>);
112static_assert(std::equality_comparable<no_le>);
113static_assert(std::equality_comparable<no_ge>);
114
115static_assert(!std::equality_comparable<wrong_return_type_eq>);
116static_assert(!std::equality_comparable<wrong_return_type_ne>);
117static_assert(std::equality_comparable<wrong_return_type_lt>);
118static_assert(std::equality_comparable<wrong_return_type_gt>);
119static_assert(std::equality_comparable<wrong_return_type_le>);
120static_assert(std::equality_comparable<wrong_return_type_ge>);
121static_assert(!std::equality_comparable<wrong_return_type>);
122static_assert(
123 !std::equality_comparable<cxx20_member_eq_operator_with_deleted_ne>);
124static_assert(
125 !std::equality_comparable<cxx20_friend_eq_operator_with_deleted_ne>);
126static_assert(
127 !std::equality_comparable<member_three_way_comparable_with_deleted_eq>);
128static_assert(
129 !std::equality_comparable<member_three_way_comparable_with_deleted_ne>);
130static_assert(
131 !std::equality_comparable<friend_three_way_comparable_with_deleted_eq>);
132static_assert(
133 !std::equality_comparable<friend_three_way_comparable_with_deleted_ne>);
134
135static_assert(!std::equality_comparable<eq_returns_explicit_bool>);
136static_assert(!std::equality_comparable<ne_returns_explicit_bool>);
137static_assert(std::equality_comparable<lt_returns_explicit_bool>);
138static_assert(std::equality_comparable<gt_returns_explicit_bool>);
139static_assert(std::equality_comparable<le_returns_explicit_bool>);
140static_assert(std::equality_comparable<ge_returns_explicit_bool>);
141static_assert(std::equality_comparable<returns_true_type>);
142static_assert(std::equality_comparable<returns_int_ptr>);
143} // namespace types_fit_for_purpose
144

source code of libcxx/test/std/concepts/concepts.compare/concept.equalitycomparable/equality_comparable.compile.pass.cpp