33 #ifndef _GLIBCXX_UTILITY_H
34 #define _GLIBCXX_UTILITY_H 1
36 #ifdef _GLIBCXX_SYSHDR
37 #pragma GCC system_header
40 #if __cplusplus >= 201103L
44 #ifdef __glibcxx_constant_wrapper
48 namespace std _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 template<
typename _Tp>
60 template<
typename _Tp,
61 typename _Up =
typename remove_cv<_Tp>::type,
64 using __enable_if_has_tuple_size = _Tp;
66 template<
typename _Tp>
67 struct tuple_size<const __enable_if_has_tuple_size<_Tp>>
70 template<
typename _Tp>
71 struct tuple_size<volatile __enable_if_has_tuple_size<_Tp>>
74 template<
typename _Tp>
75 struct tuple_size<const volatile __enable_if_has_tuple_size<_Tp>>
76 :
public tuple_size<_Tp> { };
78 #if __cplusplus >= 201703L
79 template<
typename _Tp>
80 inline constexpr
size_t tuple_size_v = tuple_size<_Tp>::value;
84 template<
size_t __i,
typename _Tp>
88 template<
size_t __i,
typename _Tp>
91 template<
size_t __i,
typename _Tp>
94 using type =
const __tuple_element_t<__i, _Tp>;
97 template<
size_t __i,
typename _Tp>
100 using type =
volatile __tuple_element_t<__i, _Tp>;
103 template<
size_t __i,
typename _Tp>
104 struct tuple_element<__i, const volatile _Tp>
106 using type =
const volatile __tuple_element_t<__i, _Tp>;
109 #if __cplusplus >= 201402L
113 template<
typename _Tp,
typename... _Types>
115 __find_uniq_type_in_pack()
117 constexpr
size_t __sz =
sizeof...(_Types);
118 constexpr
bool __found[__sz] = { __is_same(_Tp, _Types) ... };
120 for (
size_t __i = 0; __i < __sz; ++__i)
138 #ifdef __glibcxx_tuple_element_t
139 template<
size_t __i,
typename _Tp>
140 using tuple_element_t =
typename tuple_element<__i, _Tp>::type;
143 #ifdef __glibcxx_constant_wrapper
145 template<auto _Xv,
typename _Vt = remove_cvref_t<decltype(_Xv)>>
146 struct constant_wrapper;
148 template<
typename _Tp>
151 typename constant_wrapper<_Tp::value>;
156 template<_ConstExprParam _Tp>
157 friend constexpr
auto
158 operator+(_Tp) noexcept -> constant_wrapper<(+_Tp::value)>
161 template<_ConstExprParam _Tp>
162 friend constexpr
auto
163 operator-(_Tp) noexcept -> constant_wrapper<(-_Tp::value)>
166 template<_ConstExprParam _Tp>
167 friend constexpr
auto
168 operator~(_Tp) noexcept -> constant_wrapper<(~_Tp::value)>
171 template<_ConstExprParam _Tp>
172 friend constexpr
auto
173 operator!(_Tp) noexcept -> constant_wrapper<(!_Tp::value)>
176 template<_ConstExprParam _Tp>
177 friend constexpr
auto
178 operator&(_Tp) noexcept -> constant_wrapper<(&_Tp::value)>
181 template<_ConstExprParam _Tp>
182 friend constexpr
auto
183 operator*(_Tp) noexcept -> constant_wrapper<(*_Tp::value)>
186 template<_ConstExprParam _Left, _ConstExprParam _Right>
187 friend constexpr
auto
189 -> constant_wrapper<(_Left::value + _Right::value)>
192 template<_ConstExprParam _Left, _ConstExprParam _Right>
193 friend constexpr
auto
195 -> constant_wrapper<(_Left::value - _Right::value)>
198 template<_ConstExprParam _Left, _ConstExprParam _Right>
199 friend constexpr
auto
201 -> constant_wrapper<(_Left::value * _Right::value)>
204 template<_ConstExprParam _Left, _ConstExprParam _Right>
205 friend constexpr
auto
207 -> constant_wrapper<(_Left::value / _Right::value)>
210 template<_ConstExprParam _Left, _ConstExprParam _Right>
211 friend constexpr
auto
213 -> constant_wrapper<(_Left::value % _Right::value)>
216 template<_ConstExprParam _Left, _ConstExprParam _Right>
217 friend constexpr
auto
219 -> constant_wrapper<(_Left::value << _Right::value)>
222 template<_ConstExprParam _Left, _ConstExprParam _Right>
223 friend constexpr
auto
225 -> constant_wrapper<(_Left::value >> _Right::value)>
228 template<_ConstExprParam _Left, _ConstExprParam _Right>
229 friend constexpr
auto
231 -> constant_wrapper<(_Left::value & _Right::value)>
234 template<_ConstExprParam _Left, _ConstExprParam _Right>
235 friend constexpr
auto
237 -> constant_wrapper<(_Left::value | _Right::value)>
240 template<_ConstExprParam _Left, _ConstExprParam _Right>
241 friend constexpr
auto
243 -> constant_wrapper<(_Left::value ^ _Right::value)>
246 template<_ConstExprParam _Left, _ConstExprParam _Right>
247 requires (!is_constructible_v<
bool, decltype(_Left::value)>
248 || !is_constructible_v<
bool, decltype(_Right::value)>)
249 friend constexpr auto
250 operator&&(_Left, _Right) noexcept
251 -> constant_wrapper<(_Left::value && _Right::value)>
254 template<_ConstExprParam _Left, _ConstExprParam _Right>
255 requires (!is_constructible_v<
bool, decltype(_Left::value)>
256 || !is_constructible_v<
bool, decltype(_Right::value)>)
257 friend constexpr auto
258 operator||(_Left, _Right) noexcept
259 -> constant_wrapper<(_Left::value || _Right::value)>
262 template<_ConstExprParam _Left, _ConstExprParam _Right>
263 friend constexpr
auto
264 operator<=>(_Left, _Right) noexcept
265 -> constant_wrapper<(_Left::value <=> _Right::value)>
268 template<_ConstExprParam _Left, _ConstExprParam _Right>
269 friend constexpr
auto
271 -> constant_wrapper<(_Left::value < _Right::value)>
274 template<_ConstExprParam _Left, _ConstExprParam _Right>
275 friend constexpr
auto
277 -> constant_wrapper<(_Left::value <= _Right::value)>
280 template<_ConstExprParam _Left, _ConstExprParam _Right>
281 friend constexpr
auto
282 operator==(_Left, _Right) noexcept
283 -> constant_wrapper<(_Left::value == _Right::value)>
286 template<_ConstExprParam _Left, _ConstExprParam _Right>
287 friend constexpr
auto
288 operator!=(_Left, _Right) noexcept
289 -> constant_wrapper<(_Left::value != _Right::value)>
292 template<_ConstExprParam _Left, _ConstExprParam _Right>
293 friend constexpr
auto
295 -> constant_wrapper<(_Left::value > _Right::value)>
298 template<_ConstExprParam _Left, _ConstExprParam _Right>
299 friend constexpr
auto
301 -> constant_wrapper<(_Left::value >= _Right::value)>
304 template<_ConstExprParam _Left, _ConstExprParam _Right>
305 friend constexpr
auto
306 operator,(_Left, _Right) noexcept =
delete;
308 template<_ConstExprParam _Left, _ConstExprParam _Right>
309 friend constexpr
auto
310 operator->*(_Left, _Right) noexcept
311 -> constant_wrapper<_Left::value->*(_Right::value)>
314 template<_ConstExprParam _Tp>
316 operator++(
this _Tp) noexcept
317 -> constant_wrapper<(++_Tp::value)>
320 template<_ConstExprParam _Tp>
322 operator++(
this _Tp,
int) noexcept
323 -> constant_wrapper<(_Tp::value++)>
326 template<_ConstExprParam _Tp>
328 operator--(
this _Tp) noexcept
329 -> constant_wrapper<(--_Tp::value)>
332 template<_ConstExprParam _Tp>
334 operator--(
this _Tp,
int) noexcept
335 -> constant_wrapper<(_Tp::value--)>
338 template<_ConstExprParam _Tp, _ConstExprParam _Right>
340 operator+=(
this _Tp, _Right) noexcept
341 -> constant_wrapper<(_Tp::value += _Right::value)>
344 template<_ConstExprParam _Tp, _ConstExprParam _Right>
346 operator-=(
this _Tp, _Right) noexcept
347 -> constant_wrapper<(_Tp::value -= _Right::value)>
350 template<_ConstExprParam _Tp, _ConstExprParam _Right>
352 operator*=(
this _Tp, _Right) noexcept
353 -> constant_wrapper<(_Tp::value *= _Right::value)>
356 template<_ConstExprParam _Tp, _ConstExprParam _Right>
358 operator/=(
this _Tp, _Right) noexcept
359 -> constant_wrapper<(_Tp::value /= _Right::value)>
362 template<_ConstExprParam _Tp, _ConstExprParam _Right>
364 operator%=(
this _Tp, _Right) noexcept
365 -> constant_wrapper<(_Tp::value %= _Right::value)>
368 template<_ConstExprParam _Tp, _ConstExprParam _Right>
370 operator&=(
this _Tp, _Right) noexcept
371 -> constant_wrapper<(_Tp::value &= _Right::value)>
374 template<_ConstExprParam _Tp, _ConstExprParam _Right>
376 operator|=(
this _Tp, _Right) noexcept
377 -> constant_wrapper<(_Tp::value |= _Right::value)>
380 template<_ConstExprParam _Tp, _ConstExprParam _Right>
382 operator^=(
this _Tp, _Right) noexcept
383 -> constant_wrapper<(_Tp::value ^= _Right::value)>
386 template<_ConstExprParam _Tp, _ConstExprParam _Right>
388 operator<<=(
this _Tp, _Right) noexcept
389 -> constant_wrapper<(_Tp::value <<= _Right::value)>
392 template<_ConstExprParam _Tp, _ConstExprParam _Right>
394 operator>>=(
this _Tp, _Right) noexcept
395 -> constant_wrapper<(_Tp::value >>= _Right::value)>
399 template<auto _Xv,
typename _Vt>
400 struct constant_wrapper : _CwOperators
403 static constexpr decltype((_Xv)) value = (_Xv);
404 using type = constant_wrapper;
405 using value_type = decltype(_Xv);
406 static_assert(is_same_v<value_type, _Vt>);
408 template<_ConstExprParam _Right>
410 operator=(_Right)
const noexcept
411 -> constant_wrapper<(value = _Right::value)>
414 template<
typename... _Args,
415 bool _ConstExprInvocable =
requires {
416 requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);
417 typename constant_wrapper<
std::__invoke(value, remove_cvref_t<_Args>::value...)>;
419 requires _ConstExprInvocable || is_invocable_v<
const value_type&, _Args...>
420 static constexpr decltype(
auto)
421 operator()(_Args&&... __args)
423 requires _ConstExprInvocable || is_nothrow_invocable_v<
const value_type&, _Args...>;
426 if constexpr (_ConstExprInvocable)
427 return constant_wrapper<
std::__invoke(value, remove_cvref_t<_Args>::value...)>{};
432 template<
typename... _Args,
433 bool _ConstExprSubscriptable =
requires {
434 requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);
435 typename constant_wrapper<value[remove_cvref_t<_Args>::value...]>;
437 requires _ConstExprSubscriptable ||
requires { value[std::declval<_Args>()...]; }
438 static constexpr decltype(
auto)
439 operator[](_Args&&... __args)
441 requires _ConstExprSubscriptable || noexcept(value[std::declval<_Args>()...]);
444 if constexpr (_ConstExprSubscriptable)
445 return constant_wrapper<value[remove_cvref_t<_Args>::value...]>{};
447 return value[std::forward<_Args>(__args)...];
451 operator decltype(value)()
const noexcept
456 constexpr
bool __is_constant_wrapper_v =
false;
458 template<auto __cw,
typename _Fn>
459 constexpr
bool __is_constant_wrapper_v<constant_wrapper<__cw, _Fn>> =
true;
462 constexpr
auto cw = constant_wrapper<_Xv>{};
465 #ifdef __glibcxx_integer_sequence
468 template<
typename _Tp, _Tp... _Idx>
471 #if __cplusplus >= 202002L
472 static_assert(is_integral_v<_Tp>);
474 typedef _Tp value_type;
475 static constexpr
size_t size() noexcept {
return sizeof...(_Idx); }
478 #if __glibcxx_integer_sequence >= 202511L
485 template<
typename _Tp, _Tp... _Idx>
489 template<
size_t __i,
class _Tp, _Tp... _Idx>
490 struct tuple_element<__i, integer_sequence<_Tp, _Idx...>>
492 static_assert(__i <
sizeof...(_Idx));
496 template<
size_t __i,
class _Tp, _Tp... _Idx>
497 struct tuple_element<__i, const integer_sequence<_Tp, _Idx...>>
499 static_assert(__i <
sizeof...(_Idx));
503 template<
size_t __i,
class _Tp, _Tp... _Idx>
506 get(integer_sequence<_Tp, _Idx...>) noexcept
508 static_assert(__i <
sizeof...(_Idx));
515 template<
typename _Tp, _Tp _Num>
517 #if __has_builtin(__make_integer_seq)
518 = __make_integer_seq<integer_sequence, _Tp, _Num>;
524 template<
size_t... _Idx>
528 template<
size_t _Num>
532 template<
typename... _Types>
536 #if __cpp_structured_bindings >= 202411L
537 #if __has_builtin(__integer_pack)
538 template <auto _Num,
typename _Tp = decltype(_Num)>
540 _IotaArray[_Num] = {__integer_pack(_Tp(_Num))...};
541 #elif defined __glibcxx_integer_sequence
542 template <auto _Num,
typename _Tp = decltype(_Num),
typename = make_
integer_sequence<_Tp, _Num>>
546 template <
auto _Num,
typename _Tp, _Tp... _Is>
548 _IotaArray<_Num, _Tp, integer_sequence<_Tp, _Is...>>[_Num] = {_Is...};
552 #if __cplusplus >= 201703L
555 explicit in_place_t() =
default;
558 inline constexpr in_place_t in_place{};
560 template<
typename _Tp>
struct in_place_type_t
562 explicit in_place_type_t() =
default;
565 template<
typename _Tp>
566 inline constexpr in_place_type_t<_Tp> in_place_type{};
568 template<
size_t _Idx>
struct in_place_index_t
570 explicit in_place_index_t() =
default;
573 template<
size_t _Idx>
574 inline constexpr in_place_index_t<_Idx> in_place_index{};
577 inline constexpr
bool __is_in_place_type_v =
false;
579 template<
typename _Tp>
580 inline constexpr
bool __is_in_place_type_v<in_place_type_t<_Tp>> =
true;
583 inline constexpr
bool __is_in_place_index_v =
false;
586 inline constexpr
bool __is_in_place_index_v<in_place_index_t<_Nm>> =
true;
590 #if _GLIBCXX_USE_BUILTIN_TRAIT(__type_pack_element)
591 template<
size_t _Np,
typename... _Types>
593 {
using type = __type_pack_element<_Np, _Types...>; };
595 template<
size_t _Np,
typename... _Types>
599 template<
typename _Tp0,
typename... _Rest>
600 struct _Nth_type<0, _Tp0, _Rest...>
601 {
using type = _Tp0; };
603 template<
typename _Tp0,
typename _Tp1,
typename... _Rest>
604 struct _Nth_type<1, _Tp0, _Tp1, _Rest...>
605 {
using type = _Tp1; };
607 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
608 struct _Nth_type<2, _Tp0, _Tp1, _Tp2, _Rest...>
609 {
using type = _Tp2; };
611 template<
size_t _Np,
typename _Tp0,
typename _Tp1,
typename _Tp2,
616 struct _Nth_type<_Np, _Tp0, _Tp1, _Tp2, _Rest...>
617 : _Nth_type<_Np - 3, _Rest...>
621 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
622 struct _Nth_type<0, _Tp0, _Tp1, _Tp2, _Rest...>
623 {
using type = _Tp0; };
625 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
626 struct _Nth_type<1, _Tp0, _Tp1, _Tp2, _Rest...>
627 {
using type = _Tp1; };
632 namespace ranges::__detail
634 template<
typename _Range>
635 inline constexpr
bool __is_subrange =
false;
641 struct _Swallow_assign
644 constexpr
const _Swallow_assign&
645 operator=(
const _Tp&)
const noexcept
666 _GLIBCXX17_INLINE constexpr _Swallow_assign
ignore{};
668 #if __glibcxx_flat_map || __glibcxx_flat_set
669 struct sorted_unique_t {
explicit sorted_unique_t() =
default; };
670 inline constexpr sorted_unique_t sorted_unique{};
672 struct sorted_equivalent_t {
explicit sorted_equivalent_t() =
default; };
673 inline constexpr sorted_equivalent_t sorted_equivalent{};
676 _GLIBCXX_END_NAMESPACE_VERSION
constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator%(const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr _Swallow_assign ignore
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
__make_integer_seq< integer_sequence, _Tp, _Num > make_integer_sequence
Alias template make_integer_sequence.
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.