33#ifndef _GLIBCXX_UTILITY_H
34#define _GLIBCXX_UTILITY_H 1
37#pragma GCC system_header
40#if __cplusplus >= 201103L
44#ifdef __glibcxx_constant_wrapper
48namespace 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>
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>
143#ifdef __glibcxx_constant_wrapper
144 template<
typename _Tp>
150 _CwFixedValue(__type __v) noexcept
156 template<
typename _Tp,
size_t _Extent>
157 struct _CwFixedValue<_Tp[_Extent]>
159 using __type = _Tp[_Extent];
162 _CwFixedValue(_Tp (&__arr)[_Extent]) noexcept
163 : _CwFixedValue(__arr,
typename _Build_index_tuple<_Extent>::__type())
166 template<
size_t... _Indices>
168 _CwFixedValue(_Tp (&__arr)[_Extent], _Index_tuple<_Indices...>) noexcept
169 : _M_data{__arr[_Indices]...}
172 _Tp _M_data[_Extent];
175 template<
typename _Tp,
size_t _Extent>
176 _CwFixedValue(_Tp (&)[_Extent]) -> _CwFixedValue<_Tp[_Extent]>;
178 template<_CwFixedValue _Xv,
179 typename =
typename decltype(_CwFixedValue(_Xv))::__type>
180 struct constant_wrapper;
182 template<
typename _Tp>
183 concept _ConstExprParam =
requires
185 typename constant_wrapper<_Tp::value>;
190 template<_ConstExprParam _Tp>
191 friend constexpr auto
192 operator+(_Tp)
noexcept -> constant_wrapper<(+_Tp::value)>
195 template<_ConstExprParam _Tp>
196 friend constexpr auto
197 operator-(_Tp)
noexcept -> constant_wrapper<(-_Tp::value)>
200 template<_ConstExprParam _Tp>
201 friend constexpr auto
202 operator~(_Tp)
noexcept -> constant_wrapper<(~_Tp::value)>
205 template<_ConstExprParam _Tp>
206 friend constexpr auto
207 operator!(_Tp)
noexcept -> constant_wrapper<(!_Tp::value)>
210 template<_ConstExprParam _Tp>
211 friend constexpr auto
212 operator&(_Tp)
noexcept -> constant_wrapper<(&_Tp::value)>
215 template<_ConstExprParam _Tp>
216 friend constexpr auto
217 operator*(_Tp)
noexcept -> constant_wrapper<(*_Tp::value)>
220 template<_ConstExprParam _Left, _ConstExprParam _Right>
221 friend constexpr auto
223 -> constant_wrapper<(_Left::value + _Right::value)>
226 template<_ConstExprParam _Left, _ConstExprParam _Right>
227 friend constexpr auto
229 -> constant_wrapper<(_Left::value - _Right::value)>
232 template<_ConstExprParam _Left, _ConstExprParam _Right>
233 friend constexpr auto
235 -> constant_wrapper<(_Left::value * _Right::value)>
238 template<_ConstExprParam _Left, _ConstExprParam _Right>
239 friend constexpr auto
241 -> constant_wrapper<(_Left::value / _Right::value)>
244 template<_ConstExprParam _Left, _ConstExprParam _Right>
245 friend constexpr auto
246 operator%(_Left, _Right)
noexcept
247 -> constant_wrapper<(_Left::value % _Right::value)>
250 template<_ConstExprParam _Left, _ConstExprParam _Right>
251 friend constexpr auto
253 -> constant_wrapper<(_Left::value << _Right::value)>
256 template<_ConstExprParam _Left, _ConstExprParam _Right>
257 friend constexpr auto
259 -> constant_wrapper<(_Left::value >> _Right::value)>
262 template<_ConstExprParam _Left, _ConstExprParam _Right>
263 friend constexpr auto
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 requires (!is_constructible_v<bool,
decltype(_Left::value)>
282 || !is_constructible_v<bool,
decltype(_Right::value)>)
283 friend constexpr auto
284 operator&&(_Left, _Right)
noexcept
285 -> constant_wrapper<(_Left::value && _Right::value)>
288 template<_ConstExprParam _Left, _ConstExprParam _Right>
289 requires (!is_constructible_v<bool,
decltype(_Left::value)>
290 || !is_constructible_v<bool,
decltype(_Right::value)>)
291 friend constexpr auto
292 operator||(_Left, _Right)
noexcept
293 -> constant_wrapper<(_Left::value || _Right::value)>
296 template<_ConstExprParam _Left, _ConstExprParam _Right>
297 friend constexpr auto
298 operator<=>(_Left, _Right)
noexcept
299 -> constant_wrapper<(_Left::value <=> _Right::value)>
302 template<_ConstExprParam _Left, _ConstExprParam _Right>
303 friend constexpr auto
304 operator<(_Left, _Right)
noexcept
305 -> constant_wrapper<(_Left::value < _Right::value)>
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 _Left, _ConstExprParam _Right>
315 friend constexpr auto
316 operator==(_Left, _Right)
noexcept
317 -> constant_wrapper<(_Left::value == _Right::value)>
320 template<_ConstExprParam _Left, _ConstExprParam _Right>
321 friend constexpr auto
322 operator!=(_Left, _Right)
noexcept
323 -> constant_wrapper<(_Left::value != _Right::value)>
326 template<_ConstExprParam _Left, _ConstExprParam _Right>
327 friend constexpr auto
328 operator>(_Left, _Right)
noexcept
329 -> constant_wrapper<(_Left::value > _Right::value)>
332 template<_ConstExprParam _Left, _ConstExprParam _Right>
333 friend constexpr auto
334 operator>=(_Left, _Right)
noexcept
335 -> constant_wrapper<(_Left::value >= _Right::value)>
338 template<_ConstExprParam _Left, _ConstExprParam _Right>
339 friend constexpr auto
340 operator,(_Left, _Right)
noexcept =
delete;
342 template<_ConstExprParam _Left, _ConstExprParam _Right>
343 friend constexpr auto
344 operator->*(_Left, _Right)
noexcept
345 -> constant_wrapper<_Left::value->*(_Right::value)>
348 template<_ConstExprParam _Tp>
350 operator++(
this _Tp)
noexcept
351 -> constant_wrapper<(++_Tp::value)>
354 template<_ConstExprParam _Tp>
356 operator++(
this _Tp,
int)
noexcept
357 -> constant_wrapper<(_Tp::value++)>
360 template<_ConstExprParam _Tp>
362 operator--(
this _Tp)
noexcept
363 -> constant_wrapper<(--_Tp::value)>
366 template<_ConstExprParam _Tp>
368 operator--(
this _Tp,
int)
noexcept
369 -> constant_wrapper<(_Tp::value--)>
372 template<_ConstExprParam _Tp, _ConstExprParam _Right>
374 operator+=(
this _Tp, _Right)
noexcept
375 -> constant_wrapper<(_Tp::value += _Right::value)>
378 template<_ConstExprParam _Tp, _ConstExprParam _Right>
380 operator-=(
this _Tp, _Right)
noexcept
381 -> constant_wrapper<(_Tp::value -= _Right::value)>
384 template<_ConstExprParam _Tp, _ConstExprParam _Right>
386 operator*=(
this _Tp, _Right)
noexcept
387 -> constant_wrapper<(_Tp::value *= _Right::value)>
390 template<_ConstExprParam _Tp, _ConstExprParam _Right>
392 operator/=(
this _Tp, _Right)
noexcept
393 -> constant_wrapper<(_Tp::value /= _Right::value)>
396 template<_ConstExprParam _Tp, _ConstExprParam _Right>
398 operator%=(
this _Tp, _Right)
noexcept
399 -> constant_wrapper<(_Tp::value %= _Right::value)>
402 template<_ConstExprParam _Tp, _ConstExprParam _Right>
404 operator&=(
this _Tp, _Right)
noexcept
405 -> constant_wrapper<(_Tp::value &= _Right::value)>
408 template<_ConstExprParam _Tp, _ConstExprParam _Right>
410 operator|=(
this _Tp, _Right)
noexcept
411 -> constant_wrapper<(_Tp::value |= _Right::value)>
414 template<_ConstExprParam _Tp, _ConstExprParam _Right>
416 operator^=(
this _Tp, _Right)
noexcept
417 -> constant_wrapper<(_Tp::value ^= _Right::value)>
420 template<_ConstExprParam _Tp, _ConstExprParam _Right>
422 operator<<=(
this _Tp, _Right)
noexcept
423 -> constant_wrapper<(_Tp::value <<= _Right::value)>
426 template<_ConstExprParam _Tp, _ConstExprParam _Right>
428 operator>>=(
this _Tp, _Right)
noexcept
429 -> constant_wrapper<(_Tp::value >>= _Right::value)>
433 template<_CwFixedValue _Xv,
typename>
434 struct constant_wrapper : _CwOperators
436 static constexpr const auto& value = _Xv._M_data;
437 using type = constant_wrapper;
438 using value_type =
typename decltype(_Xv)::__type;
440 template<_ConstExprParam _Right>
442 operator=(_Right)
const noexcept
443 -> constant_wrapper<(value = _Right::value)>
446 template<
typename... _Args,
447 bool _ConstExprInvocable =
requires {
448 requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);
449 typename constant_wrapper<
std::__invoke(value, remove_cvref_t<_Args>::value...)>;
451 requires _ConstExprInvocable || is_invocable_v<
const value_type&, _Args...>
452 static constexpr decltype(
auto)
453 operator()(_Args&&... __args)
455 requires _ConstExprInvocable || is_nothrow_invocable_v<
const value_type&, _Args...>;
458 if constexpr (_ConstExprInvocable)
459 return constant_wrapper<
std::__invoke(value, remove_cvref_t<_Args>::value...)>{};
464 template<
typename... _Args,
465 bool _ConstExprSubscriptable =
requires {
466 requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);
467 typename constant_wrapper<value[remove_cvref_t<_Args>::value...]>;
470 static constexpr decltype(
auto)
471 operator[](_Args&&... __args)
476 if constexpr (_ConstExprSubscriptable)
477 return constant_wrapper<value[remove_cvref_t<_Args>::value...]>{};
483 operator decltype(value)()
const noexcept
488 constexpr bool __is_constant_wrapper_v =
false;
490 template<auto __cw,
typename _Fn>
491 constexpr bool __is_constant_wrapper_v<constant_wrapper<__cw, _Fn>> =
true;
493 template<_CwFixedValue _Tp>
494 constexpr auto cw = constant_wrapper<_Tp>{};
497#ifdef __glibcxx_integer_sequence
500 template<
typename _Tp, _Tp... _Idx>
503#if __cplusplus >= 202002L
504 static_assert(is_integral_v<_Tp>);
506 typedef _Tp value_type;
507 static constexpr size_t size()
noexcept {
return sizeof...(_Idx); }
510#if __glibcxx_integer_sequence >= 202511L
517 template<
typename _Tp, _Tp... _Idx>
521 template<
size_t __i,
class _Tp, _Tp... _Idx>
522 struct tuple_element<__i, integer_sequence<_Tp, _Idx...>>
524 static_assert(__i <
sizeof...(_Idx));
528 template<
size_t __i,
class _Tp, _Tp... _Idx>
531 static_assert(__i <
sizeof...(_Idx));
535 template<
size_t __i,
class _Tp, _Tp... _Idx>
540 static_assert(__i <
sizeof...(_Idx));
547 template<
typename _Tp, _Tp _Num>
549#if __has_builtin(__make_integer_seq)
550 = __make_integer_seq<integer_sequence, _Tp, _Num>;
556 template<
size_t... _Idx>
560 template<
size_t _Num>
564 template<
typename... _Types>
568#if __cpp_structured_bindings >= 202411L
569#if __has_builtin(__integer_pack)
570 template <auto _Num,
typename _Tp = decltype(_Num)>
572 _IotaArray[_Num] = {__integer_pack(_Tp(_Num))...};
573#elif defined __glibcxx_integer_sequence
574 template <auto _Num,
typename _Tp = decltype(_Num),
typename = make_
integer_sequence<_Tp, _Num>>
578 template <
auto _Num,
typename _Tp, _Tp... _Is>
580 _IotaArray<_Num, _Tp, integer_sequence<_Tp, _Is...>>[_Num] = {_Is...};
584#if __cplusplus >= 201703L
587 explicit in_place_t() =
default;
590 inline constexpr in_place_t in_place{};
592 template<
typename _Tp>
struct in_place_type_t
594 explicit in_place_type_t() =
default;
597 template<
typename _Tp>
598 inline constexpr in_place_type_t<_Tp> in_place_type{};
600 template<
size_t _Idx>
struct in_place_index_t
602 explicit in_place_index_t() =
default;
605 template<
size_t _Idx>
606 inline constexpr in_place_index_t<_Idx> in_place_index{};
609 inline constexpr bool __is_in_place_type_v =
false;
611 template<
typename _Tp>
612 inline constexpr bool __is_in_place_type_v<in_place_type_t<_Tp>> =
true;
615 inline constexpr bool __is_in_place_index_v =
false;
618 inline constexpr bool __is_in_place_index_v<in_place_index_t<_Nm>> =
true;
622#if _GLIBCXX_USE_BUILTIN_TRAIT(__type_pack_element)
623 template<
size_t _Np,
typename... _Types>
625 {
using type = __type_pack_element<_Np, _Types...>; };
627 template<
size_t _Np,
typename... _Types>
631 template<
typename _Tp0,
typename... _Rest>
632 struct _Nth_type<0, _Tp0, _Rest...>
633 {
using type = _Tp0; };
635 template<
typename _Tp0,
typename _Tp1,
typename... _Rest>
636 struct _Nth_type<1, _Tp0, _Tp1, _Rest...>
637 {
using type = _Tp1; };
639 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
640 struct _Nth_type<2, _Tp0, _Tp1, _Tp2, _Rest...>
641 {
using type = _Tp2; };
643 template<
size_t _Np,
typename _Tp0,
typename _Tp1,
typename _Tp2,
648 struct _Nth_type<_Np, _Tp0, _Tp1, _Tp2, _Rest...>
649 : _Nth_type<_Np - 3, _Rest...>
653 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
654 struct _Nth_type<0, _Tp0, _Tp1, _Tp2, _Rest...>
655 {
using type = _Tp0; };
657 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
658 struct _Nth_type<1, _Tp0, _Tp1, _Tp2, _Rest...>
659 {
using type = _Tp1; };
664 namespace ranges::__detail
666 template<
typename _Range>
667 inline constexpr bool __is_subrange =
false;
673 struct _Swallow_assign
676 constexpr const _Swallow_assign&
677 operator=(
const _Tp&)
const noexcept
698 _GLIBCXX17_INLINE
constexpr _Swallow_assign
ignore{};
700#if __glibcxx_flat_map || __glibcxx_flat_set
701 struct sorted_unique_t {
explicit sorted_unique_t() =
default; };
702 inline constexpr sorted_unique_t sorted_unique{};
704 struct sorted_equivalent_t {
explicit sorted_equivalent_t() =
default; };
705 inline constexpr sorted_equivalent_t sorted_equivalent{};
708_GLIBCXX_END_NAMESPACE_VERSION
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 minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
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
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const 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.
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
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.