33#ifndef _GLIBCXX_UTILITY_H
34#define _GLIBCXX_UTILITY_H 1
37#pragma GCC system_header
40#if __cplusplus >= 201103L
45#ifdef __glibcxx_constant_wrapper
49namespace std _GLIBCXX_VISIBILITY(default)
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
54 template<
typename _Tp>
61 template<
typename _Tp,
62 typename _Up =
typename remove_cv<_Tp>::type,
65 using __enable_if_has_tuple_size = _Tp;
67 template<
typename _Tp>
68 struct tuple_size<const __enable_if_has_tuple_size<_Tp>>
71 template<
typename _Tp>
72 struct tuple_size<volatile __enable_if_has_tuple_size<_Tp>>
75 template<
typename _Tp>
76 struct tuple_size<const volatile __enable_if_has_tuple_size<_Tp>>
77 :
public tuple_size<_Tp> { };
79#if __cplusplus >= 201703L
80 template<
typename _Tp>
85 template<
size_t __i,
typename _Tp>
89 template<
size_t __i,
typename _Tp>
92 template<
size_t __i,
typename _Tp>
95 using type =
const __tuple_element_t<__i, _Tp>;
98 template<
size_t __i,
typename _Tp>
101 using type =
volatile __tuple_element_t<__i, _Tp>;
104 template<
size_t __i,
typename _Tp>
105 struct tuple_element<__i, const volatile _Tp>
107 using type =
const volatile __tuple_element_t<__i, _Tp>;
110#if __cplusplus >= 201402L
114 template<
typename _Tp,
typename... _Types>
116 __find_uniq_type_in_pack()
118 constexpr size_t __sz =
sizeof...(_Types);
119 constexpr bool __found[__sz] = { __is_same(_Tp, _Types) ... };
121 for (
size_t __i = 0; __i < __sz; ++__i)
139#ifdef __glibcxx_tuple_element_t
140 template<
size_t __i,
typename _Tp>
144#ifdef __glibcxx_constant_wrapper
146 template<auto _Xv,
typename _Vt = remove_cvref_t<decltype(_Xv)>>
147 struct constant_wrapper;
149 template<
typename _Tp>
150 concept _ConstExprParam =
requires
152 typename constant_wrapper<_Tp::value>;
157 template<_ConstExprParam _Tp>
158 friend constexpr auto
159 operator+(_Tp)
noexcept -> constant_wrapper<(+_Tp::value)>
162 template<_ConstExprParam _Tp>
163 friend constexpr auto
164 operator-(_Tp)
noexcept -> constant_wrapper<(-_Tp::value)>
167 template<_ConstExprParam _Tp>
168 friend constexpr auto
169 operator~(_Tp)
noexcept -> constant_wrapper<(~_Tp::value)>
172 template<_ConstExprParam _Tp>
173 friend constexpr auto
174 operator!(_Tp)
noexcept -> constant_wrapper<(!_Tp::value)>
177 template<_ConstExprParam _Tp>
178 friend constexpr auto
179 operator&(_Tp)
noexcept -> constant_wrapper<(&_Tp::value)>
182 template<_ConstExprParam _Tp>
183 friend constexpr auto
184 operator*(_Tp)
noexcept -> constant_wrapper<(*_Tp::value)>
187 template<_ConstExprParam _Left, _ConstExprParam _Right>
188 friend constexpr auto
189 operator+(_Left, _Right)
noexcept
190 -> constant_wrapper<(_Left::value + _Right::value)>
193 template<_ConstExprParam _Left, _ConstExprParam _Right>
194 friend constexpr auto
195 operator-(_Left, _Right)
noexcept
196 -> constant_wrapper<(_Left::value - _Right::value)>
199 template<_ConstExprParam _Left, _ConstExprParam _Right>
200 friend constexpr auto
201 operator*(_Left, _Right)
noexcept
202 -> constant_wrapper<(_Left::value * _Right::value)>
205 template<_ConstExprParam _Left, _ConstExprParam _Right>
206 friend constexpr auto
207 operator/(_Left, _Right)
noexcept
208 -> constant_wrapper<(_Left::value / _Right::value)>
211 template<_ConstExprParam _Left, _ConstExprParam _Right>
212 friend constexpr auto
213 operator%(_Left, _Right)
noexcept
214 -> constant_wrapper<(_Left::value % _Right::value)>
217 template<_ConstExprParam _Left, _ConstExprParam _Right>
218 friend constexpr auto
219 operator<<(_Left, _Right)
noexcept
220 -> constant_wrapper<(_Left::value << _Right::value)>
223 template<_ConstExprParam _Left, _ConstExprParam _Right>
224 friend constexpr auto
225 operator>>(_Left, _Right)
noexcept
226 -> constant_wrapper<(_Left::value >> _Right::value)>
229 template<_ConstExprParam _Left, _ConstExprParam _Right>
230 friend constexpr auto
231 operator&(_Left, _Right)
noexcept
232 -> constant_wrapper<(_Left::value & _Right::value)>
235 template<_ConstExprParam _Left, _ConstExprParam _Right>
236 friend constexpr auto
237 operator|(_Left, _Right)
noexcept
238 -> constant_wrapper<(_Left::value | _Right::value)>
241 template<_ConstExprParam _Left, _ConstExprParam _Right>
242 friend constexpr auto
243 operator^(_Left, _Right)
noexcept
244 -> constant_wrapper<(_Left::value ^ _Right::value)>
247 template<_ConstExprParam _Left, _ConstExprParam _Right>
248 requires (!is_constructible_v<bool,
decltype(_Left::value)>
249 || !is_constructible_v<bool,
decltype(_Right::value)>)
250 friend constexpr auto
251 operator&&(_Left, _Right)
noexcept
252 -> constant_wrapper<(_Left::value && _Right::value)>
255 template<_ConstExprParam _Left, _ConstExprParam _Right>
256 requires (!is_constructible_v<bool,
decltype(_Left::value)>
257 || !is_constructible_v<bool,
decltype(_Right::value)>)
258 friend constexpr auto
259 operator||(_Left, _Right)
noexcept
260 -> constant_wrapper<(_Left::value || _Right::value)>
263 template<_ConstExprParam _Left, _ConstExprParam _Right>
264 friend constexpr auto
265 operator<=>(_Left, _Right)
noexcept
266 -> constant_wrapper<(_Left::value <=> _Right::value)>
269 template<_ConstExprParam _Left, _ConstExprParam _Right>
270 friend constexpr auto
271 operator<(_Left, _Right)
noexcept
272 -> constant_wrapper<(_Left::value < _Right::value)>
275 template<_ConstExprParam _Left, _ConstExprParam _Right>
276 friend constexpr auto
277 operator<=(_Left, _Right)
noexcept
278 -> constant_wrapper<(_Left::value <= _Right::value)>
281 template<_ConstExprParam _Left, _ConstExprParam _Right>
282 friend constexpr auto
283 operator==(_Left, _Right)
noexcept
284 -> constant_wrapper<(_Left::value == _Right::value)>
287 template<_ConstExprParam _Left, _ConstExprParam _Right>
288 friend constexpr auto
289 operator!=(_Left, _Right)
noexcept
290 -> constant_wrapper<(_Left::value != _Right::value)>
293 template<_ConstExprParam _Left, _ConstExprParam _Right>
294 friend constexpr auto
295 operator>(_Left, _Right)
noexcept
296 -> constant_wrapper<(_Left::value > _Right::value)>
299 template<_ConstExprParam _Left, _ConstExprParam _Right>
300 friend constexpr auto
301 operator>=(_Left, _Right)
noexcept
302 -> constant_wrapper<(_Left::value >= _Right::value)>
305 template<_ConstExprParam _Left, _ConstExprParam _Right>
306 friend constexpr auto
307 operator,(_Left, _Right)
noexcept =
delete;
309 template<_ConstExprParam _Left, _ConstExprParam _Right>
310 friend constexpr auto
311 operator->*(_Left, _Right)
noexcept
312 -> constant_wrapper<_Left::value->*(_Right::value)>
315 template<_ConstExprParam _Tp>
317 operator++(
this _Tp)
noexcept
318 -> constant_wrapper<(++_Tp::value)>
321 template<_ConstExprParam _Tp>
323 operator++(
this _Tp,
int)
noexcept
324 -> constant_wrapper<(_Tp::value++)>
327 template<_ConstExprParam _Tp>
329 operator--(
this _Tp)
noexcept
330 -> constant_wrapper<(--_Tp::value)>
333 template<_ConstExprParam _Tp>
335 operator--(
this _Tp,
int)
noexcept
336 -> constant_wrapper<(_Tp::value--)>
339 template<_ConstExprParam _Tp, _ConstExprParam _Right>
341 operator+=(
this _Tp, _Right)
noexcept
342 -> constant_wrapper<(_Tp::value += _Right::value)>
345 template<_ConstExprParam _Tp, _ConstExprParam _Right>
347 operator-=(
this _Tp, _Right)
noexcept
348 -> constant_wrapper<(_Tp::value -= _Right::value)>
351 template<_ConstExprParam _Tp, _ConstExprParam _Right>
353 operator*=(
this _Tp, _Right)
noexcept
354 -> constant_wrapper<(_Tp::value *= _Right::value)>
357 template<_ConstExprParam _Tp, _ConstExprParam _Right>
359 operator/=(
this _Tp, _Right)
noexcept
360 -> constant_wrapper<(_Tp::value /= _Right::value)>
363 template<_ConstExprParam _Tp, _ConstExprParam _Right>
365 operator%=(
this _Tp, _Right)
noexcept
366 -> constant_wrapper<(_Tp::value %= _Right::value)>
369 template<_ConstExprParam _Tp, _ConstExprParam _Right>
371 operator&=(
this _Tp, _Right)
noexcept
372 -> constant_wrapper<(_Tp::value &= _Right::value)>
375 template<_ConstExprParam _Tp, _ConstExprParam _Right>
377 operator|=(
this _Tp, _Right)
noexcept
378 -> constant_wrapper<(_Tp::value |= _Right::value)>
381 template<_ConstExprParam _Tp, _ConstExprParam _Right>
383 operator^=(
this _Tp, _Right)
noexcept
384 -> constant_wrapper<(_Tp::value ^= _Right::value)>
387 template<_ConstExprParam _Tp, _ConstExprParam _Right>
389 operator<<=(
this _Tp, _Right)
noexcept
390 -> constant_wrapper<(_Tp::value <<= _Right::value)>
393 template<_ConstExprParam _Tp, _ConstExprParam _Right>
395 operator>>=(
this _Tp, _Right)
noexcept
396 -> constant_wrapper<(_Tp::value >>= _Right::value)>
400 template<auto _Xv,
typename _Vt>
401 struct constant_wrapper : _CwOperators
404 static constexpr decltype((_Xv)) value = (_Xv);
405 using type = constant_wrapper;
406 using value_type =
decltype(_Xv);
407 static_assert(is_same_v<value_type, _Vt>);
409 template<_ConstExprParam _Right>
411 operator=(_Right)
const noexcept
412 -> constant_wrapper<(value = _Right::value)>
415 template<
typename... _Args,
416 bool _ConstExprInvocable =
requires {
417 requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);
418 typename constant_wrapper<
std::__invoke(value, remove_cvref_t<_Args>::value...)>;
420 requires _ConstExprInvocable || is_invocable_v<
const value_type&, _Args...>
421 static constexpr decltype(
auto)
422 operator()(_Args&&... __args)
424 requires _ConstExprInvocable || is_nothrow_invocable_v<
const value_type&, _Args...>;
427 if constexpr (_ConstExprInvocable)
428 return constant_wrapper<
std::__invoke(value, remove_cvref_t<_Args>::value...)>{};
433 template<
typename... _Args,
434 bool _ConstExprSubscriptable =
requires {
435 requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);
436 typename constant_wrapper<value[remove_cvref_t<_Args>::value...]>;
439 static constexpr decltype(
auto)
440 operator[](_Args&&... __args)
445 if constexpr (_ConstExprSubscriptable)
446 return constant_wrapper<value[remove_cvref_t<_Args>::value...]>{};
452 operator decltype(value)()
const noexcept
457 constexpr bool __is_constant_wrapper_v =
false;
459 template<auto __cw,
typename _Fn>
460 constexpr bool __is_constant_wrapper_v<constant_wrapper<__cw, _Fn>> =
true;
463 constexpr auto cw = constant_wrapper<_Xv>{};
466#ifdef __glibcxx_integer_sequence
469 template<
typename _Tp, _Tp... _Idx>
472#if __cplusplus >= 202002L
473 static_assert(is_integral_v<_Tp>);
475 typedef _Tp value_type;
476 static constexpr size_t size()
noexcept {
return sizeof...(_Idx); }
479#if __glibcxx_integer_sequence >= 202511L
486 template<
typename _Tp, _Tp... _Idx>
490 template<
size_t __i,
class _Tp, _Tp... _Idx>
491 struct tuple_element<__i, integer_sequence<_Tp, _Idx...>>
493 static_assert(__i <
sizeof...(_Idx));
497 template<
size_t __i,
class _Tp, _Tp... _Idx>
500 static_assert(__i <
sizeof...(_Idx));
504 template<
size_t __i,
class _Tp, _Tp... _Idx>
509 static_assert(__i <
sizeof...(_Idx));
516 template<
typename _Tp, _Tp _Num>
518#if __has_builtin(__make_integer_seq)
519 = __make_integer_seq<integer_sequence, _Tp, _Num>;
525 template<
size_t... _Idx>
529 template<
size_t _Num>
533 template<
typename... _Types>
537#if __cpp_structured_bindings >= 202411L
538#if __has_builtin(__integer_pack)
539 template <auto _Num,
typename _Tp = decltype(_Num)>
541 _IotaArray[_Num] = {__integer_pack(_Tp(_Num))...};
542#elif defined __glibcxx_integer_sequence
543 template <auto _Num,
typename _Tp = decltype(_Num),
typename = make_
integer_sequence<_Tp, _Num>>
547 template <
auto _Num,
typename _Tp, _Tp... _Is>
549 _IotaArray<_Num, _Tp, integer_sequence<_Tp, _Is...>>[_Num] = {_Is...};
553#if _GLIBCXX_USE_BUILTIN_TRAIT(__type_pack_element)
554 template<
size_t _Np,
typename... _Types>
556 {
using type = __type_pack_element<_Np, _Types...>; };
558 template<
size_t _Np,
typename... _Types>
562 template<
typename _Tp0,
typename... _Rest>
563 struct _Nth_type<0, _Tp0, _Rest...>
564 {
using type = _Tp0; };
566 template<
typename _Tp0,
typename _Tp1,
typename... _Rest>
567 struct _Nth_type<1, _Tp0, _Tp1, _Rest...>
568 {
using type = _Tp1; };
570 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
571 struct _Nth_type<2, _Tp0, _Tp1, _Tp2, _Rest...>
572 {
using type = _Tp2; };
574 template<
size_t _Np,
typename _Tp0,
typename _Tp1,
typename _Tp2,
579 struct _Nth_type<_Np, _Tp0, _Tp1, _Tp2, _Rest...>
580 : _Nth_type<_Np - 3, _Rest...>
584 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
585 struct _Nth_type<0, _Tp0, _Tp1, _Tp2, _Rest...>
586 {
using type = _Tp0; };
588 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
589 struct _Nth_type<1, _Tp0, _Tp1, _Tp2, _Rest...>
590 {
using type = _Tp1; };
595 namespace ranges::__detail
597 template<
typename _Range>
598 inline constexpr bool __is_subrange =
false;
604 struct _Swallow_assign
607 constexpr const _Swallow_assign&
608 operator=(
const _Tp&)
const noexcept
629 _GLIBCXX17_INLINE
constexpr _Swallow_assign
ignore{};
631#if __glibcxx_flat_map || __glibcxx_flat_set
632 struct sorted_unique_t {
explicit sorted_unique_t() =
default; };
633 inline constexpr sorted_unique_t sorted_unique{};
635 struct sorted_equivalent_t {
explicit sorted_equivalent_t() =
default; };
636 inline constexpr sorted_equivalent_t sorted_equivalent{};
639_GLIBCXX_END_NAMESPACE_VERSION
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
integer_sequence< size_t, _Idx... > index_sequence
Alias template index_sequence.
__make_integer_seq< integer_sequence, _Tp, _Num > make_integer_sequence
Alias template make_integer_sequence.
constexpr _Swallow_assign ignore
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
Define a member typedef type only if a boolean constant is true.
Finds the size of a given tuple type.
Gives the type of the ith element of a given tuple type.
Class template integer_sequence.