summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/language.support/cmp/cmp.concept/three_way_comparable.compile.pass.cpp
blob: b65b77e96ef60730ac8f33c53da980d517c23d55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-no-concepts

// template<class T, class Cat = partial_ordering>
// concept three_way_comparable = // see below

#include <compare>

#include "compare_types.h"
#include "test_macros.h"

namespace fundamentals {
// with default ordering
static_assert(std::three_way_comparable<int>);
static_assert(std::three_way_comparable<double>);
static_assert(std::three_way_comparable<void*>);
static_assert(std::three_way_comparable<char*>);
static_assert(std::three_way_comparable<char const*>);
static_assert(std::three_way_comparable<char volatile*>);
static_assert(std::three_way_comparable<char const volatile*>);
static_assert(std::three_way_comparable<wchar_t&>);
#ifndef TEST_HAS_NO_CHAR8_T
static_assert(std::three_way_comparable<char8_t const&>);
#endif
#ifndef TEST_HAS_NO_UNICODE_CHARS
static_assert(std::three_way_comparable<char16_t volatile&>);
static_assert(std::three_way_comparable<char32_t const volatile&>);
#endif
#ifndef TEST_HAS_NO_INT128
static_assert(std::three_way_comparable<__int128_t const&>);
static_assert(std::three_way_comparable<__uint128_t const&>);
#endif
static_assert(std::three_way_comparable<unsigned char&&>);
static_assert(std::three_way_comparable<unsigned short const&&>);
static_assert(std::three_way_comparable<unsigned int volatile&&>);
static_assert(std::three_way_comparable<unsigned long const volatile&&>);

// with explicit ordering
static_assert(std::three_way_comparable<int, std::strong_ordering>);
static_assert(std::three_way_comparable<int, std::weak_ordering>);
static_assert(std::three_way_comparable<double, std::partial_ordering>);
static_assert(!std::three_way_comparable<double, std::weak_ordering>);
static_assert(std::three_way_comparable<void*, std::strong_ordering>);
static_assert(std::three_way_comparable<void*, std::weak_ordering>);
static_assert(std::three_way_comparable<char*, std::strong_ordering>);
static_assert(std::three_way_comparable<char*, std::weak_ordering>);
static_assert(std::three_way_comparable<char const*, std::strong_ordering>);
static_assert(std::three_way_comparable<char const*, std::weak_ordering>);
static_assert(std::three_way_comparable<char volatile*, std::strong_ordering>);
static_assert(std::three_way_comparable<char volatile*, std::weak_ordering>);
static_assert(std::three_way_comparable<char const volatile*, std::strong_ordering>);
static_assert(std::three_way_comparable<char const volatile*, std::weak_ordering>);
static_assert(std::three_way_comparable<wchar_t&, std::strong_ordering>);
static_assert(std::three_way_comparable<wchar_t&, std::weak_ordering>);
static_assert(std::three_way_comparable<char8_t const&, std::strong_ordering>);
static_assert(std::three_way_comparable<char8_t const&, std::weak_ordering>);
static_assert(std::three_way_comparable<char16_t volatile&, std::strong_ordering>);
static_assert(std::three_way_comparable<char16_t volatile&, std::weak_ordering>);
static_assert(std::three_way_comparable<char32_t const volatile&, std::strong_ordering>);
static_assert(std::three_way_comparable<char32_t const volatile&, std::weak_ordering>);
static_assert(std::three_way_comparable<unsigned char&&, std::strong_ordering>);
static_assert(std::three_way_comparable<unsigned char&&, std::weak_ordering>);
static_assert(std::three_way_comparable<unsigned short const&&, std::strong_ordering>);
static_assert(std::three_way_comparable<unsigned short const&&, std::weak_ordering>);
static_assert(std::three_way_comparable<unsigned int volatile&&, std::strong_ordering>);
static_assert(std::three_way_comparable<unsigned int volatile&&, std::weak_ordering>);
static_assert(std::three_way_comparable<unsigned long const volatile&&, std::strong_ordering>);
static_assert(std::three_way_comparable<unsigned long const volatile&&, std::weak_ordering>);

static_assert(!std::three_way_comparable<int[5]>);
static_assert(!std::three_way_comparable<int (*)(int)>);
static_assert(!std::three_way_comparable<int (&)(int)>);
static_assert(!std::three_way_comparable<int (*)(int) noexcept>);
static_assert(!std::three_way_comparable<int (&)(int) noexcept>);
static_assert(!std::three_way_comparable<std::nullptr_t>);
static_assert(!std::three_way_comparable<void>);

struct S {};
static_assert(!std::three_way_comparable<int S::*>);
static_assert(!std::three_way_comparable<int (S::*)()>);
static_assert(!std::three_way_comparable<int (S::*)() noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() &>);
static_assert(!std::three_way_comparable<int (S::*)() & noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() &&>);
static_assert(!std::three_way_comparable<int (S::*)() && noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() const>);
static_assert(!std::three_way_comparable<int (S::*)() const noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() const&>);
static_assert(!std::three_way_comparable<int (S::*)() const & noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() const&&>);
static_assert(!std::three_way_comparable<int (S::*)() const && noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() volatile>);
static_assert(!std::three_way_comparable<int (S::*)() volatile noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() volatile&>);
static_assert(!std::three_way_comparable<int (S::*)() volatile & noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() volatile&&>);
static_assert(!std::three_way_comparable<int (S::*)() volatile && noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() const volatile>);
static_assert(!std::three_way_comparable<int (S::*)() const volatile noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() const volatile&>);
static_assert(!std::three_way_comparable<int (S::*)() const volatile & noexcept>);
static_assert(!std::three_way_comparable<int (S::*)() const volatile&&>);
static_assert(!std::three_way_comparable<int (S::*)() const volatile && noexcept>);
} // namespace fundamentals

namespace user_defined {

struct S {
    auto operator<=>(const S&) const = default;
};

static_assert(std::three_way_comparable<S>);
static_assert(std::three_way_comparable<S, std::strong_ordering>);
static_assert(std::three_way_comparable<S, std::partial_ordering>);

struct SpaceshipNotDeclared {
};

static_assert(!std::three_way_comparable<SpaceshipNotDeclared>);

struct SpaceshipDeleted {
    auto operator<=>(const SpaceshipDeleted&) const = delete;
};

static_assert(!std::three_way_comparable<SpaceshipDeleted>);

struct SpaceshipWithoutEqualityOperator {
    auto operator<=>(const SpaceshipWithoutEqualityOperator&) const;
};

static_assert(!std::three_way_comparable<SpaceshipWithoutEqualityOperator>);

struct EqualityOperatorDeleted {
    bool operator==(const EqualityOperatorDeleted&) const = delete;
};

static_assert(!std::three_way_comparable<EqualityOperatorDeleted>);

struct EqualityOperatorOnly {
    bool operator==(const EqualityOperatorOnly&) const = default;
};

static_assert(!std::three_way_comparable<EqualityOperatorOnly>);

struct SpaceshipDeclaredEqualityOperatorDeleted {
    bool operator==(const SpaceshipDeclaredEqualityOperatorDeleted&) const = delete;
    auto operator<=>(const SpaceshipDeclaredEqualityOperatorDeleted&) const = default;
};

static_assert(!std::three_way_comparable<SpaceshipDeclaredEqualityOperatorDeleted>);

struct AllInequalityOperators {
    bool operator<(const AllInequalityOperators&) const;
    bool operator<=(const AllInequalityOperators&) const;
    bool operator>(const AllInequalityOperators&) const;
    bool operator>=(const AllInequalityOperators&) const;
    bool operator!=(const AllInequalityOperators&) const;
};

static_assert(!std::three_way_comparable<AllInequalityOperators>);

struct AllComparisonOperators {
    bool operator<(const AllComparisonOperators&) const;
    bool operator<=(const AllComparisonOperators&) const;
    bool operator>(const AllComparisonOperators&) const;
    bool operator>=(const AllComparisonOperators&) const;
    bool operator!=(const AllComparisonOperators&) const;
    bool operator==(const AllComparisonOperators&) const;
};

static_assert(!std::three_way_comparable<AllComparisonOperators>);

struct AllButOneInequalityOperators {
    bool operator<(const AllButOneInequalityOperators&) const;
    bool operator<=(const AllButOneInequalityOperators&) const;
    bool operator>(const AllButOneInequalityOperators&) const;
    bool operator!=(const AllButOneInequalityOperators&) const;
};

static_assert(!std::three_way_comparable<AllButOneInequalityOperators>);

struct AllInequalityOperatorsOneDeleted {
    bool operator<(const AllInequalityOperatorsOneDeleted&) const;
    bool operator<=(const AllInequalityOperatorsOneDeleted&) const;
    bool operator>(const AllInequalityOperatorsOneDeleted&) const;
    bool operator>=(const AllInequalityOperatorsOneDeleted&) const = delete;
    bool operator!=(const AllInequalityOperatorsOneDeleted&) const;
};

static_assert(!std::three_way_comparable<AllInequalityOperatorsOneDeleted>);

struct EqualityOperatorWrongReturnType {
    int operator==(const EqualityOperatorWrongReturnType&);
    auto operator<=>(const EqualityOperatorWrongReturnType&) const = default;
};

static_assert(!std::three_way_comparable<EqualityOperatorWrongReturnType>);

struct SpaceshipWrongReturnType {
    bool operator==(const SpaceshipWrongReturnType&) const = default;
    int operator<=>(const SpaceshipWrongReturnType&);
};

static_assert(!std::three_way_comparable<SpaceshipWrongReturnType>);

struct EqualityOperatorNonConstArgument {
    bool operator==(EqualityOperatorNonConstArgument&);
    auto operator<=>(const EqualityOperatorNonConstArgument&) const = default;
};

static_assert(!std::three_way_comparable<EqualityOperatorNonConstArgument>);

struct SpaceshipNonConstArgument {
    bool operator==(const SpaceshipNonConstArgument&) const = default;
    auto operator<=>(SpaceshipNonConstArgument&);
};

static_assert(!std::three_way_comparable<SpaceshipNonConstArgument>);
} // namespace user_defined