Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
comparison_traits.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_COMPARISON_TRAITS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_COMPARISON_TRAITS_HPP_
7
8// IWYU pragma: private, include "arene/base/type_traits.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11#include "arene/base/compiler_support/diagnostics.hpp"
12#include "arene/base/constraints/constraints.hpp"
13#include "arene/base/stdlib_choice/declval.hpp"
14#include "arene/base/stdlib_choice/enable_if.hpp"
15#include "arene/base/stdlib_choice/is_convertible.hpp"
16
17namespace arene {
18namespace base {
19
20/// Type trait to check if an instance of type @c T can be compared to an
21/// instance of type @c U with the less-than operator.
22/// @tparam T The type of the lhs
23/// @tparam U The type of the rhs. Defaults to @c T
24/// @return @c true if an instance of @c T can be compared with an instance of
25/// @c U, @c false otherwise.
26template <typename T, typename U = T, typename = constraints<>>
27extern constexpr bool is_less_than_comparable_v = false;
28
29/// Specialization for the case that @c T and @c U can be compared.
30template <typename T, typename U>
31extern constexpr bool is_less_than_comparable_v<
32 T,
33 U,
34 constraints<std::enable_if_t<std::is_convertible<decltype(std::declval<T>() < std::declval<U>()), bool>::value>>> =
35 true;
36
37/// Type trait to check if an instance of type @c T can be compared to an
38/// instance of type @c U with the less-than operator without throwing an exception.
39/// @tparam T The type of the lhs
40/// @tparam U The type of the rhs. Defaults to @c T
41/// @return @c true if an instance of @c T can be compared with an instance of
42/// @c U without throwing, @c false otherwise.
43template <typename T, typename U = T, typename = constraints<>>
44extern constexpr bool is_nothrow_less_than_comparable_v = false;
45
46/// Specialization for the case that @c T and @c U can be compared.
47template <typename T, typename U>
48extern constexpr bool
50 noexcept(std::declval<T>() < std::declval<U>());
51
52/// Type trait to check if an instance of type @c T can be compared to an
53/// instance of type @c U with the less-than-or-equal operator.
54/// @tparam T The type of the lhs
55/// @tparam U The type of the rhs. Defaults to @c T
56/// @return @c true if an instance of @c T can be compared with an instance of
57/// @c U, @c false otherwise.
58template <typename T, typename U = T, typename = constraints<>>
59extern constexpr bool is_less_than_or_equal_comparable_v = false;
60
61/// Specialization for the case that @c T and @c U can be compared.
62template <typename T, typename U>
63extern constexpr bool is_less_than_or_equal_comparable_v<
64 T,
65 U,
66 constraints<std::enable_if_t<std::is_convertible<decltype(std::declval<T>() <= std::declval<U>()), bool>::value>>> =
67 true;
68
69/// Type trait to check if an instance of type @c T can be compared to an
70/// instance of type @c U with the less-than-or-equal operator without throwing an exception.
71/// @tparam T The type of the lhs
72/// @tparam U The type of the rhs. Defaults to @c T
73/// @return @c true if an instance of @c T can be compared with an instance of
74/// @c U without throwing, @c false otherwise.
75template <typename T, typename U = T, typename = constraints<>>
76extern constexpr bool is_nothrow_less_than_or_equal_comparable_v = false;
77
78/// Specialization for the case that @c T and @c U can be compared.
79template <typename T, typename U>
81 T,
82 U,
84 noexcept(std::declval<T>() <= std::declval<U>());
85
86/// Type trait to check if an instance of type @c T can be compared to an
87/// instance of type @c U with the greater-than operator.
88/// @tparam T The type of the lhs
89/// @tparam U The type of the rhs. Defaults to @c T
90/// @return @c true if an instance of @c T can be compared with an instance of
91/// @c U, @c false otherwise.
92template <typename T, typename U = T, typename = constraints<>>
93extern constexpr bool is_greater_than_comparable_v = false;
94
95/// Specialization for the case that @c T and @c U can be compared.
96template <typename T, typename U>
97extern constexpr bool is_greater_than_comparable_v<
98 T,
99 U,
100 constraints<std::enable_if_t<std::is_convertible<decltype(std::declval<T>() > std::declval<U>()), bool>::value>>> =
101 true;
102
103/// Type trait to check if an instance of type @c T can be compared to an
104/// instance of type @c U with the greater-than operator without throwing an exception.
105/// @tparam T The type of the lhs
106/// @tparam U The type of the rhs. Defaults to @c T
107/// @return @c true if an instance of @c T can be compared with an instance of
108/// @c U without throwing, @c false otherwise.
109template <typename T, typename U = T, typename = constraints<>>
110extern constexpr bool is_nothrow_greater_than_comparable_v = false;
111
112/// Specialization for the case that @c T and @c U can be compared.
113template <typename T, typename U>
114extern constexpr bool
116 noexcept(std::declval<T>() > std::declval<U>());
117
118/// Type trait to check if an instance of type @c T can be compared to an
119/// instance of type @c U with the greater-than-or-equal operator.
120/// @tparam T The type of the lhs
121/// @tparam U The type of the rhs. Defaults to @c T
122/// @return @c true if an instance of @c T can be compared with an instance of
123/// @c U, @c false otherwise.
124template <typename T, typename U = T, typename = constraints<>>
125extern constexpr bool is_greater_than_or_equal_comparable_v = false;
126
127/// Specialization for the case that @c T and @c U can be compared.
128template <typename T, typename U>
129extern constexpr bool is_greater_than_or_equal_comparable_v<
130 T,
131 U,
132 constraints<std::enable_if_t<std::is_convertible<decltype(std::declval<T>() >= std::declval<U>()), bool>::value>>> =
133 true;
134
135/// Type trait to check if an instance of type @c T can be compared to an
136/// instance of type @c U with the greater-than-or-equal operator without throwing an exception.
137/// @tparam T The type of the lhs
138/// @tparam U The type of the rhs. Defaults to @c T
139/// @return @c true if an instance of @c T can be compared with an instance of
140/// @c U without throwing, @c false otherwise.
141template <typename T, typename U = T, typename = constraints<>>
142extern constexpr bool is_nothrow_greater_than_or_equal_comparable_v = false;
143
144/// Specialization for the case that @c T and @c U can be compared.
145template <typename T, typename U>
147 T,
148 U,
150 noexcept(std::declval<T>() >= std::declval<U>());
151
152/// Type trait to check if an instance of type @c T can be compared to an
153/// instance of type @c U with the equality operator.
154/// @tparam T The type of the lhs
155/// @tparam U The type of the rhs. Defaults to @c T
156/// @return @c true if an instance of @c T can be compared with an instance of
157/// @c U, @c false otherwise.
158template <typename T, typename U = T, typename = constraints<>>
159extern constexpr bool is_equality_comparable_v = false;
160
161ARENE_IGNORE_START();
162ARENE_IGNORE_ALL("-Wfloat-equal", "Checking for existence of comparison, not using it");
163/// Specialization for the case that @c T and @c U can be compared.
164template <typename T, typename U>
165extern constexpr bool is_equality_comparable_v<
166 T,
167 U,
168 constraints<std::enable_if_t<std::is_convertible<decltype(std::declval<T>() == std::declval<U>()), bool>::value>>> =
169 true;
170ARENE_IGNORE_END();
171
172/// Type trait to check if an instance of type @c T can be compared to an
173/// instance of type @c U with the equality operator without throwing an exception.
174/// @tparam T The type of the lhs
175/// @tparam U The type of the rhs. Defaults to @c T
176/// @return @c true if an instance of @c T can be compared with an instance of
177/// @c U without throwing, @c false otherwise.
178template <typename T, typename U = T, typename = constraints<>>
179extern constexpr bool is_nothrow_equality_comparable_v = false;
180
181ARENE_IGNORE_START();
182ARENE_IGNORE_ALL("-Wfloat-equal", "Checking for existence of comparison, not using it");
183/// Specialization for the case that @c T and @c U can be compared.
184template <typename T, typename U>
185extern constexpr bool
187 noexcept(std::declval<T>() == std::declval<U>());
188ARENE_IGNORE_END();
189
190/// Type trait to check if an instance of type @c T can be compared to an
191/// instance of type @c U with the inequality operator.
192/// @tparam T The type of the lhs
193/// @tparam U The type of the rhs. Defaults to @c T
194/// @return @c true if an instance of @c T can be compared with an instance of
195/// @c U, @c false otherwise.
196template <typename T, typename U = T, typename = constraints<>>
197extern constexpr bool is_inequality_comparable_v = false;
198
199/// Specialization for the case that @c T and @c U can be compared.
200template <typename T, typename U>
201extern constexpr bool is_inequality_comparable_v<
202 T,
203 U,
204 constraints<std::enable_if_t<std::is_convertible<decltype(std::declval<T>() != std::declval<U>()), bool>::value>>> =
205 true;
206
207/// Type trait to check if an instance of type @c T can be compared to an
208/// instance of type @c U with the inequality operator without throwing an exception.
209/// @tparam T The type of the lhs
210/// @tparam U The type of the rhs. Defaults to @c T
211/// @return @c true if an instance of @c T can be compared with an instance of
212/// @c U without throwing, @c false otherwise.
213template <typename T, typename U = T, typename = constraints<>>
214extern constexpr bool is_nothrow_inequality_comparable_v = false;
215
216/// Specialization for the case that @c T and @c U can be compared.
217template <typename T, typename U>
218extern constexpr bool
220 noexcept(std::declval<T>() != std::declval<U>());
221
222} // namespace base
223} // namespace arene
224
225#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_COMPARISON_TRAITS_HPP_
Definition array_exceptions_disabled.cpp:11
ARENE_IGNORE_ALL("-Wfloat-equal", "Equality is used to check the properties of a single value, not compare two values")
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10