File: totally_ordered.pass.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-6~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,418,812 kB
  • sloc: cpp: 5,290,827; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,900; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,892; xml: 953; cs: 573; fortran: 539
file content (175 lines) | stat: -rw-r--r-- 7,878 bytes parent folder | download | duplicates (6)
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
//===----------------------------------------------------------------------===//
//
// 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>
// concept totally_ordered;

#include <concepts>

#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

// `models_totally_ordered` checks that `std::totally_ordered` subsumes
// `std::equality_comparable`. This overload should *never* be called.
template <std::equality_comparable T>
constexpr bool models_totally_ordered() noexcept {
  return false;
}

template <std::totally_ordered T>
constexpr bool models_totally_ordered() noexcept {
  return true;
}

namespace fundamentals {
static_assert(models_totally_ordered<int>());
static_assert(models_totally_ordered<double>());
static_assert(models_totally_ordered<void*>());
static_assert(models_totally_ordered<char*>());
static_assert(models_totally_ordered<char const*>());
static_assert(models_totally_ordered<char volatile*>());
static_assert(models_totally_ordered<char const volatile*>());
static_assert(models_totally_ordered<wchar_t&>());
static_assert(models_totally_ordered<char8_t const&>());
static_assert(models_totally_ordered<char16_t volatile&>());
static_assert(models_totally_ordered<char32_t const volatile&>());
static_assert(models_totally_ordered<unsigned char&&>());
static_assert(models_totally_ordered<unsigned short const&&>());
static_assert(models_totally_ordered<unsigned int volatile&&>());
static_assert(models_totally_ordered<unsigned long const volatile&&>());
static_assert(models_totally_ordered<int[5]>());
static_assert(models_totally_ordered<int (*)(int)>());
static_assert(models_totally_ordered<int (&)(int)>());
static_assert(models_totally_ordered<int (*)(int) noexcept>());
static_assert(models_totally_ordered<int (&)(int) noexcept>());

#ifndef TEST_COMPILER_GCC
static_assert(!std::totally_ordered<std::nullptr_t>);
#endif

struct S {};
static_assert(!std::totally_ordered<S>);
static_assert(!std::totally_ordered<int S::*>);
static_assert(!std::totally_ordered<int (S::*)()>);
static_assert(!std::totally_ordered<int (S::*)() noexcept>);
static_assert(!std::totally_ordered<int (S::*)() &>);
static_assert(!std::totally_ordered<int (S::*)() & noexcept>);
static_assert(!std::totally_ordered<int (S::*)() &&>);
static_assert(!std::totally_ordered < int (S::*)() && noexcept >);
static_assert(!std::totally_ordered<int (S::*)() const>);
static_assert(!std::totally_ordered<int (S::*)() const noexcept>);
static_assert(!std::totally_ordered<int (S::*)() const&>);
static_assert(!std::totally_ordered<int (S::*)() const & noexcept>);
static_assert(!std::totally_ordered<int (S::*)() const&&>);
static_assert(!std::totally_ordered < int (S::*)() const&& noexcept >);
static_assert(!std::totally_ordered<int (S::*)() volatile>);
static_assert(!std::totally_ordered<int (S::*)() volatile noexcept>);
static_assert(!std::totally_ordered<int (S::*)() volatile&>);
static_assert(!std::totally_ordered<int (S::*)() volatile & noexcept>);
static_assert(!std::totally_ordered<int (S::*)() volatile&&>);
static_assert(!std::totally_ordered < int (S::*)() volatile&& noexcept >);
static_assert(!std::totally_ordered<int (S::*)() const volatile>);
static_assert(!std::totally_ordered<int (S::*)() const volatile noexcept>);
static_assert(!std::totally_ordered<int (S::*)() const volatile&>);
static_assert(!std::totally_ordered<int (S::*)() const volatile & noexcept>);
static_assert(!std::totally_ordered<int (S::*)() const volatile&&>);
static_assert(!std::totally_ordered < int (S::*)() const volatile&& noexcept >);

static_assert(!std::totally_ordered<void>);
} // namespace fundamentals

namespace standard_types {
static_assert(models_totally_ordered<std::array<int, 10> >());
static_assert(models_totally_ordered<std::deque<int> >());
static_assert(models_totally_ordered<std::forward_list<int> >());
static_assert(models_totally_ordered<std::list<int> >());
static_assert(models_totally_ordered<std::optional<int> >());
static_assert(models_totally_ordered<std::set<int> >());
static_assert(models_totally_ordered<std::vector<bool> >());
static_assert(models_totally_ordered<std::vector<int> >());

static_assert(!std::totally_ordered<std::unordered_map<int, void*> >);
static_assert(!std::totally_ordered<std::unordered_set<int> >);

struct A {};
// FIXME(cjdb): uncomment when operator<=> is implemented for each of these types.
// static_assert(!std::totally_ordered<std::array<A, 10> >);
// static_assert(!std::totally_ordered<std::deque<A> >);
// static_assert(!std::totally_ordered<std::forward_list<A> >);
// static_assert(!std::totally_ordered<std::list<A> >);
static_assert(!std::totally_ordered<std::optional<A> >);
// static_assert(!std::totally_ordered<std::set<A> >);
// static_assert(!std::totally_ordered<std::vector<A> >);
} // namespace standard_types

namespace types_fit_for_purpose {
static_assert(models_totally_ordered<member_three_way_comparable>());
static_assert(models_totally_ordered<friend_three_way_comparable>());
static_assert(models_totally_ordered<explicit_operators>());
static_assert(models_totally_ordered<different_return_types>());
static_assert(!std::totally_ordered<cxx20_member_eq>);
static_assert(!std::totally_ordered<cxx20_friend_eq>);
static_assert(!std::totally_ordered<one_member_one_friend>);
static_assert(!std::totally_ordered<equality_comparable_with_ec1>);

static_assert(!std::totally_ordered<no_eq>);
static_assert(!std::totally_ordered<no_neq>);
static_assert(!std::totally_ordered<no_lt>);
static_assert(!std::totally_ordered<no_gt>);
static_assert(!std::totally_ordered<no_le>);
static_assert(!std::totally_ordered<no_ge>);

static_assert(!std::totally_ordered<wrong_return_type_eq>);
static_assert(!std::totally_ordered<wrong_return_type_ne>);
static_assert(!std::totally_ordered<wrong_return_type_lt>);
static_assert(!std::totally_ordered<wrong_return_type_gt>);
static_assert(!std::totally_ordered<wrong_return_type_le>);
static_assert(!std::totally_ordered<wrong_return_type_ge>);
static_assert(!std::totally_ordered<wrong_return_type>);

static_assert(!std::totally_ordered<cxx20_member_eq_operator_with_deleted_ne>);
static_assert(!std::totally_ordered<cxx20_friend_eq_operator_with_deleted_ne>);
static_assert(
    !std::totally_ordered<member_three_way_comparable_with_deleted_eq>);
static_assert(
    !std::totally_ordered<member_three_way_comparable_with_deleted_ne>);
static_assert(
    !std::totally_ordered<friend_three_way_comparable_with_deleted_eq>);
static_assert(
    !std::totally_ordered<friend_three_way_comparable_with_deleted_ne>);

static_assert(!std::totally_ordered<eq_returns_explicit_bool>);
static_assert(!std::totally_ordered<ne_returns_explicit_bool>);
static_assert(!std::totally_ordered<lt_returns_explicit_bool>);
static_assert(!std::totally_ordered<gt_returns_explicit_bool>);
static_assert(!std::totally_ordered<le_returns_explicit_bool>);
static_assert(!std::totally_ordered<ge_returns_explicit_bool>);
static_assert(std::totally_ordered<returns_true_type>);
static_assert(std::totally_ordered<returns_int_ptr>);

static_assert(std::totally_ordered<partial_ordering_totally_ordered_with>);
static_assert(std::totally_ordered<weak_ordering_totally_ordered_with>);
static_assert(std::totally_ordered<strong_ordering_totally_ordered_with>);
} // namespace types_fit_for_purpose

int main(int, char**) { return 0; }