30 #ifndef _GLIBCXX_CONCEPTS
31 #define _GLIBCXX_CONCEPTS 1
33 #if __cplusplus > 201703L && __cpp_concepts >= 201907L
35 #pragma GCC system_header
44 #include <type_traits>
46 namespace std _GLIBCXX_VISIBILITY(default)
48 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 #define __cpp_lib_concepts 202002L
56 template<
typename _Tp,
typename _Up>
57 concept __same_as = std::is_same_v<_Tp, _Up>;
61 template<
typename _Tp,
typename _Up>
63 = __detail::__same_as<_Tp, _Up> && __detail::__same_as<_Up, _Tp>;
66 template<
typename _Derived,
typename _Base>
67 concept derived_from = __is_base_of(_Base, _Derived)
68 && is_convertible_v<const volatile _Derived*, const volatile _Base*>;
71 template<
typename _From,
typename _To>
72 concept convertible_to = is_convertible_v<_From, _To>
73 && requires(add_rvalue_reference_t<_From> (&__f)()) {
74 static_cast<_To
>(__f());
78 template<
typename _Tp,
typename _Up>
79 concept common_reference_with
80 = same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>>
81 && convertible_to<_Tp, common_reference_t<_Tp, _Up>>
82 && convertible_to<_Up, common_reference_t<_Tp, _Up>>;
85 template<
typename _Tp,
typename _Up>
87 = same_as<common_type_t<_Tp, _Up>, common_type_t<_Up, _Tp>>
89 static_cast<common_type_t<_Tp, _Up>
>(std::declval<_Tp>());
90 static_cast<common_type_t<_Tp, _Up>
>(std::declval<_Up>());
92 && common_reference_with<add_lvalue_reference_t<const _Tp>,
93 add_lvalue_reference_t<const _Up>>
94 && common_reference_with<add_lvalue_reference_t<common_type_t<_Tp, _Up>>,
96 add_lvalue_reference_t<const _Tp>,
97 add_lvalue_reference_t<const _Up>>>;
101 template<
typename _Tp>
102 concept integral = is_integral_v<_Tp>;
104 template<
typename _Tp>
105 concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
107 template<
typename _Tp>
108 concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
110 template<
typename _Tp>
111 concept floating_point = is_floating_point_v<_Tp>;
115 template<
typename _Tp>
116 using __cref =
const remove_reference_t<_Tp>&;
118 template<
typename _Tp>
119 concept __class_or_enum
120 = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
124 template<
typename _Lhs,
typename _Rhs>
125 concept assignable_from
126 = is_lvalue_reference_v<_Lhs>
127 && common_reference_with<__detail::__cref<_Lhs>, __detail::__cref<_Rhs>>
128 && requires(_Lhs __lhs, _Rhs&& __rhs) {
129 { __lhs =
static_cast<_Rhs&&
>(__rhs) } -> same_as<_Lhs>;
133 template<
typename _Tp>
134 concept destructible = is_nothrow_destructible_v<_Tp>;
137 template<
typename _Tp,
typename... _Args>
138 concept constructible_from
139 = destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
142 template<
typename _Tp>
143 concept default_initializable = constructible_from<_Tp>
151 template<
typename _Tp>
152 concept move_constructible
153 = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
156 template<
typename _Tp>
157 concept copy_constructible
158 = move_constructible<_Tp>
159 && constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp>
160 && constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp>
161 && constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
167 namespace __cust_swap
169 template<
typename _Tp>
void swap(_Tp&, _Tp&) =
delete;
171 template<
typename _Tp,
typename _Up>
173 = (__detail::__class_or_enum<remove_reference_t<_Tp>>
174 || __detail::__class_or_enum<remove_reference_t<_Up>>)
175 && requires(_Tp&& __t, _Up&& __u) {
176 swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u));
182 template<
typename _Tp,
typename _Up>
183 static constexpr
bool
186 if constexpr (__adl_swap<_Tp, _Up>)
187 return noexcept(swap(std::declval<_Tp>(), std::declval<_Up>()));
194 template<typename _Tp, typename _Up>
195 requires __adl_swap<_Tp, _Up>
196 || (same_as<_Tp, _Up> && is_lvalue_reference_v<_Tp>
200 operator()(_Tp&& __t, _Up&& __u) const
201 noexcept(_S_noexcept<_Tp, _Up>())
203 if constexpr (__adl_swap<_Tp, _Up>)
204 swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u));
207 auto __tmp =
static_cast<remove_reference_t<_Tp>&&
>(__t);
208 __t =
static_cast<remove_reference_t<_Tp>&&
>(__u);
209 __u =
static_cast<remove_reference_t<_Tp>&&
>(__tmp);
213 template<
typename _Tp,
typename _Up,
size_t _Num>
214 requires requires(
const _Swap& __swap, _Tp& __e1, _Up& __e2) {
218 operator()(_Tp (&__e1)[_Num], _Up (&__e2)[_Num])
const
219 noexcept(noexcept(std::declval<const _Swap&>()(*__e1, *__e2)))
221 for (
size_t __n = 0; __n < _Num; ++__n)
222 (*
this)(__e1[__n], __e2[__n]);
227 inline namespace __cust
229 inline constexpr __cust_swap::_Swap swap{};
233 template<
typename _Tp>
235 = requires(_Tp& __a, _Tp& __b) { ranges::swap(__a, __b); };
237 template<
typename _Tp,
typename _Up>
238 concept swappable_with = common_reference_with<_Tp, _Up>
239 && requires(_Tp&& __t, _Up&& __u) {
240 ranges::swap(static_cast<_Tp&&>(__t), static_cast<_Tp&&>(__t));
241 ranges::swap(static_cast<_Up&&>(__u), static_cast<_Up&&>(__u));
242 ranges::swap(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u));
243 ranges::swap(static_cast<_Up&&>(__u), static_cast<_Tp&&>(__t));
248 template<
typename _Tp>
249 concept movable = is_object_v<_Tp> && move_constructible<_Tp>
250 && assignable_from<_Tp&, _Tp> && swappable<_Tp>;
252 template<
typename _Tp>
253 concept copyable = copy_constructible<_Tp> && movable<_Tp>
254 && assignable_from<_Tp&, _Tp&> && assignable_from<_Tp&, const _Tp&>
255 && assignable_from<_Tp&, const _Tp>;
257 template<
typename _Tp>
258 concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
265 template<
typename _Tp>
266 concept __boolean_testable_impl = convertible_to<_Tp, bool>;
268 template<
typename _Tp>
269 concept __boolean_testable
270 = __boolean_testable_impl<_Tp>
271 && requires(_Tp&& __t)
272 { { !
static_cast<_Tp&&
>(__t) } -> __boolean_testable_impl; };
279 template<
typename _Tp,
typename _Up>
280 concept __weakly_eq_cmp_with
281 = requires(__detail::__cref<_Tp> __t, __detail::__cref<_Up> __u) {
282 { __t == __u } -> __boolean_testable;
283 { __t != __u } -> __boolean_testable;
284 { __u == __t } -> __boolean_testable;
285 { __u != __t } -> __boolean_testable;
289 template<
typename _Tp>
290 concept equality_comparable = __detail::__weakly_eq_cmp_with<_Tp, _Tp>;
292 template<
typename _Tp,
typename _Up>
293 concept equality_comparable_with
294 = equality_comparable<_Tp> && equality_comparable<_Up>
295 && common_reference_with<__detail::__cref<_Tp>, __detail::__cref<_Up>>
296 && equality_comparable<common_reference_t<__detail::__cref<_Tp>,
297 __detail::__cref<_Up>>>
298 && __detail::__weakly_eq_cmp_with<_Tp, _Up>;
302 template<
typename _Tp,
typename _Up>
303 concept __partially_ordered_with
304 = requires(
const remove_reference_t<_Tp>& __t,
305 const remove_reference_t<_Up>& __u) {
306 { __t < __u } -> __boolean_testable;
307 { __t > __u } -> __boolean_testable;
308 { __t <= __u } -> __boolean_testable;
309 { __t >= __u } -> __boolean_testable;
310 { __u < __t } -> __boolean_testable;
311 { __u > __t } -> __boolean_testable;
312 { __u <= __t } -> __boolean_testable;
313 { __u >= __t } -> __boolean_testable;
318 template<
typename _Tp>
319 concept totally_ordered
320 = equality_comparable<_Tp>
321 && __detail::__partially_ordered_with<_Tp, _Tp>;
323 template<
typename _Tp,
typename _Up>
324 concept totally_ordered_with
325 = totally_ordered<_Tp> && totally_ordered<_Up>
326 && equality_comparable_with<_Tp, _Up>
327 && totally_ordered<common_reference_t<__detail::__cref<_Tp>,
328 __detail::__cref<_Up>>>
329 && __detail::__partially_ordered_with<_Tp, _Up>;
331 template<
typename _Tp>
332 concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
337 template<
typename _Fn,
typename... _Args>
338 concept invocable = is_invocable_v<_Fn, _Args...>;
341 template<
typename _Fn,
typename... _Args>
342 concept regular_invocable = invocable<_Fn, _Args...>;
345 template<
typename _Fn,
typename... _Args>
346 concept predicate = regular_invocable<_Fn, _Args...>
347 && __detail::__boolean_testable<invoke_result_t<_Fn, _Args...>>;
350 template<
typename _Rel,
typename _Tp,
typename _Up>
352 = predicate<_Rel, _Tp, _Tp> && predicate<_Rel, _Up, _Up>
353 && predicate<_Rel, _Tp, _Up> && predicate<_Rel, _Up, _Tp>;
356 template<
typename _Rel,
typename _Tp,
typename _Up>
357 concept equivalence_relation = relation<_Rel, _Tp, _Up>;
360 template<
typename _Rel,
typename _Tp,
typename _Up>
361 concept strict_weak_order = relation<_Rel, _Tp, _Up>;
363 _GLIBCXX_END_NAMESPACE_VERSION
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.