33#ifndef _GLIBCXX_UTILITY_H
34#define _GLIBCXX_UTILITY_H 1
37#pragma GCC system_header
40#if __cplusplus >= 201103L
45namespace std _GLIBCXX_VISIBILITY(default)
47_GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _Tp>
57 template<
typename _Tp,
58 typename _Up =
typename remove_cv<_Tp>::type,
61 using __enable_if_has_tuple_size = _Tp;
63 template<
typename _Tp>
64 struct tuple_size<const __enable_if_has_tuple_size<_Tp>>
67 template<
typename _Tp>
68 struct tuple_size<volatile __enable_if_has_tuple_size<_Tp>>
71 template<
typename _Tp>
72 struct tuple_size<const volatile __enable_if_has_tuple_size<_Tp>>
73 :
public tuple_size<_Tp> { };
75#if __cplusplus >= 201703L
76 template<
typename _Tp>
81 template<
size_t __i,
typename _Tp>
85 template<
size_t __i,
typename _Tp>
88 template<
size_t __i,
typename _Tp>
91 using type =
const __tuple_element_t<__i, _Tp>;
94 template<
size_t __i,
typename _Tp>
97 using type =
volatile __tuple_element_t<__i, _Tp>;
100 template<
size_t __i,
typename _Tp>
101 struct tuple_element<__i, const volatile _Tp>
103 using type =
const volatile __tuple_element_t<__i, _Tp>;
106#if __cplusplus >= 201402L
110 template<
typename _Tp,
typename... _Types>
112 __find_uniq_type_in_pack()
114 constexpr size_t __sz =
sizeof...(_Types);
115 constexpr bool __found[__sz] = { __is_same(_Tp, _Types) ... };
117 for (
size_t __i = 0; __i < __sz; ++__i)
135#ifdef __glibcxx_tuple_element_t
136 template<
size_t __i,
typename _Tp>
140#ifdef __glibcxx_constant_wrapper
141 template<
typename _Tp>
147 _CwFixedValue(__type __v) noexcept
153 template<
typename _Tp,
size_t _Extent>
154 struct _CwFixedValue<_Tp[_Extent]>
156 using __type = _Tp[_Extent];
159 _CwFixedValue(_Tp (&__arr)[_Extent]) noexcept
160 : _CwFixedValue(__arr,
typename _Build_index_tuple<_Extent>::__type())
163 template<
size_t... _Indices>
165 _CwFixedValue(_Tp (&__arr)[_Extent], _Index_tuple<_Indices...>) noexcept
166 : _M_data{__arr[_Indices]...}
169 _Tp _M_data[_Extent];
172 template<
typename _Tp,
size_t _Extent>
173 _CwFixedValue(_Tp (&)[_Extent]) -> _CwFixedValue<_Tp[_Extent]>;
175 template<_CwFixedValue _Xv,
176 typename =
typename decltype(_CwFixedValue(_Xv))::__type>
177 struct constant_wrapper;
179 template<
typename _Tp>
180 concept _ConstExprParam =
requires
182 typename constant_wrapper<_Tp::value>;
187 template<_ConstExprParam _Tp>
188 friend constexpr auto
189 operator+(_Tp)
noexcept -> constant_wrapper<(+_Tp::value)>
192 template<_ConstExprParam _Tp>
193 friend constexpr auto
194 operator-(_Tp)
noexcept -> constant_wrapper<(-_Tp::value)>
197 template<_ConstExprParam _Tp>
198 friend constexpr auto
199 operator~(_Tp)
noexcept -> constant_wrapper<(~_Tp::value)>
202 template<_ConstExprParam _Tp>
203 friend constexpr auto
204 operator!(_Tp)
noexcept -> constant_wrapper<(!_Tp::value)>
207 template<_ConstExprParam _Tp>
208 friend constexpr auto
209 operator&(_Tp)
noexcept -> constant_wrapper<(&_Tp::value)>
212 template<_ConstExprParam _Tp>
213 friend constexpr auto
214 operator*(_Tp)
noexcept -> constant_wrapper<(*_Tp::value)>
217 template<_ConstExprParam _Left, _ConstExprParam _Right>
218 friend constexpr auto
220 -> constant_wrapper<(_Left::value + _Right::value)>
223 template<_ConstExprParam _Left, _ConstExprParam _Right>
224 friend constexpr auto
226 -> constant_wrapper<(_Left::value - _Right::value)>
229 template<_ConstExprParam _Left, _ConstExprParam _Right>
230 friend constexpr auto
232 -> constant_wrapper<(_Left::value * _Right::value)>
235 template<_ConstExprParam _Left, _ConstExprParam _Right>
236 friend constexpr auto
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 friend constexpr auto
250 -> constant_wrapper<(_Left::value << _Right::value)>
253 template<_ConstExprParam _Left, _ConstExprParam _Right>
254 friend constexpr auto
256 -> constant_wrapper<(_Left::value >> _Right::value)>
259 template<_ConstExprParam _Left, _ConstExprParam _Right>
260 friend constexpr auto
262 -> constant_wrapper<(_Left::value & _Right::value)>
265 template<_ConstExprParam _Left, _ConstExprParam _Right>
266 friend constexpr auto
268 -> constant_wrapper<(_Left::value | _Right::value)>
271 template<_ConstExprParam _Left, _ConstExprParam _Right>
272 friend constexpr auto
274 -> constant_wrapper<(_Left::value ^ _Right::value)>
277 template<_ConstExprParam _Left, _ConstExprParam _Right>
278 requires (!is_constructible_v<bool,
decltype(_Left::value)>
279 || !is_constructible_v<bool,
decltype(_Right::value)>)
280 friend constexpr auto
281 operator&&(_Left, _Right)
noexcept
282 -> constant_wrapper<(_Left::value && _Right::value)>
285 template<_ConstExprParam _Left, _ConstExprParam _Right>
286 requires (!is_constructible_v<bool,
decltype(_Left::value)>
287 || !is_constructible_v<bool,
decltype(_Right::value)>)
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
308 -> constant_wrapper<(_Left::value <= _Right::value)>
311 template<_ConstExprParam _Left, _ConstExprParam _Right>
312 friend constexpr auto
313 operator==(_Left, _Right)
noexcept
314 -> constant_wrapper<(_Left::value == _Right::value)>
317 template<_ConstExprParam _Left, _ConstExprParam _Right>
318 friend constexpr auto
319 operator!=(_Left, _Right)
noexcept
320 -> constant_wrapper<(_Left::value != _Right::value)>
323 template<_ConstExprParam _Left, _ConstExprParam _Right>
324 friend constexpr auto
325 operator>(_Left, _Right)
noexcept
326 -> constant_wrapper<(_Left::value > _Right::value)>
329 template<_ConstExprParam _Left, _ConstExprParam _Right>
330 friend constexpr auto
331 operator>=(_Left, _Right)
noexcept
332 -> constant_wrapper<(_Left::value >= _Right::value)>
335 template<_ConstExprParam _Left, _ConstExprParam _Right>
336 friend constexpr auto
337 operator,(_Left, _Right)
noexcept =
delete;
339 template<_ConstExprParam _Left, _ConstExprParam _Right>
340 friend constexpr auto
341 operator->*(_Left, _Right)
noexcept
342 -> constant_wrapper<_Left::value->*(_Right::value)>
345 template<_ConstExprParam _Tp, _ConstExprParam... _Args>
347 operator()(
this _Tp, _Args...) noexcept
349 requires(_Args...) { constant_wrapper<_Tp::value(_Args::value...)>(); }
350 {
return constant_wrapper<_Tp::value(_Args::value...)>{}; }
352 template<_ConstExprParam _Tp, _ConstExprParam... _Args>
354 operator[](
this _Tp, _Args...) noexcept
355 -> constant_wrapper<(_Tp::value[_Args::value...])>
358 template<_ConstExprParam _Tp>
360 operator++(
this _Tp)
noexcept
361 -> constant_wrapper<(++_Tp::value)>
364 template<_ConstExprParam _Tp>
366 operator++(
this _Tp,
int)
noexcept
367 -> constant_wrapper<(_Tp::value++)>
370 template<_ConstExprParam _Tp>
372 operator--(
this _Tp)
noexcept
373 -> constant_wrapper<(--_Tp::value)>
376 template<_ConstExprParam _Tp>
378 operator--(
this _Tp,
int)
noexcept
379 -> constant_wrapper<(_Tp::value--)>
382 template<_ConstExprParam _Tp, _ConstExprParam _Right>
384 operator+=(
this _Tp, _Right)
noexcept
385 -> constant_wrapper<(_Tp::value += _Right::value)>
388 template<_ConstExprParam _Tp, _ConstExprParam _Right>
390 operator-=(
this _Tp, _Right)
noexcept
391 -> constant_wrapper<(_Tp::value -= _Right::value)>
394 template<_ConstExprParam _Tp, _ConstExprParam _Right>
396 operator*=(
this _Tp, _Right)
noexcept
397 -> constant_wrapper<(_Tp::value *= _Right::value)>
400 template<_ConstExprParam _Tp, _ConstExprParam _Right>
402 operator/=(
this _Tp, _Right)
noexcept
403 -> constant_wrapper<(_Tp::value /= _Right::value)>
406 template<_ConstExprParam _Tp, _ConstExprParam _Right>
408 operator%=(
this _Tp, _Right)
noexcept
409 -> constant_wrapper<(_Tp::value %= _Right::value)>
412 template<_ConstExprParam _Tp, _ConstExprParam _Right>
414 operator&=(
this _Tp, _Right)
noexcept
415 -> constant_wrapper<(_Tp::value &= _Right::value)>
418 template<_ConstExprParam _Tp, _ConstExprParam _Right>
420 operator|=(
this _Tp, _Right)
noexcept
421 -> constant_wrapper<(_Tp::value |= _Right::value)>
424 template<_ConstExprParam _Tp, _ConstExprParam _Right>
426 operator^=(
this _Tp, _Right)
noexcept
427 -> constant_wrapper<(_Tp::value ^= _Right::value)>
430 template<_ConstExprParam _Tp, _ConstExprParam _Right>
432 operator<<=(
this _Tp, _Right)
noexcept
433 -> constant_wrapper<(_Tp::value <<= _Right::value)>
436 template<_ConstExprParam _Tp, _ConstExprParam _Right>
438 operator>>=(
this _Tp, _Right)
noexcept
439 -> constant_wrapper<(_Tp::value >>= _Right::value)>
443 template<_CwFixedValue _Xv,
typename>
444 struct constant_wrapper : _CwOperators
446 static constexpr const auto& value = _Xv._M_data;
447 using type = constant_wrapper;
448 using value_type =
typename decltype(_Xv)::__type;
450 template<_ConstExprParam _Right>
452 operator=(_Right)
const noexcept
453 -> constant_wrapper<(value = _Right::value)>
457 operator decltype(value)()
const noexcept
462 constexpr bool __is_constant_wrapper_v =
false;
464 template<auto __cw,
typename _Fn>
465 constexpr bool __is_constant_wrapper_v<constant_wrapper<__cw, _Fn>> =
true;
467 template<_CwFixedValue _Tp>
468 constexpr auto cw = constant_wrapper<_Tp>{};
471#ifdef __glibcxx_integer_sequence
474 template<
typename _Tp, _Tp... _Idx>
477#if __cplusplus >= 202002L
478 static_assert(is_integral_v<_Tp>);
480 typedef _Tp value_type;
481 static constexpr size_t size()
noexcept {
return sizeof...(_Idx); }
485 template<
typename _Tp, _Tp _Num>
487#if __has_builtin(__make_integer_seq)
488 = __make_integer_seq<integer_sequence, _Tp, _Num>;
494 template<
size_t... _Idx>
498 template<
size_t _Num>
502 template<
typename... _Types>
506#if __cpp_structured_bindings >= 202411L
507#if __has_builtin(__integer_pack)
508 template <auto _Num,
typename _Tp = decltype(_Num)>
510 _IotaArray[_Num] = {__integer_pack(_Tp(_Num))...};
511#elif defined __glibcxx_integer_sequence
512 template <auto _Num,
typename _Tp = decltype(_Num),
typename = make_
integer_sequence<_Tp, _Num>>
516 template <
auto _Num,
typename _Tp, _Tp... _Is>
518 _IotaArray<_Num, _Tp, integer_sequence<_Tp, _Is...>>[_Num] = {_Is...};
522#if __cplusplus >= 201703L
525 explicit in_place_t() =
default;
528 inline constexpr in_place_t in_place{};
530 template<
typename _Tp>
struct in_place_type_t
532 explicit in_place_type_t() =
default;
535 template<
typename _Tp>
536 inline constexpr in_place_type_t<_Tp> in_place_type{};
538 template<
size_t _Idx>
struct in_place_index_t
540 explicit in_place_index_t() =
default;
543 template<
size_t _Idx>
544 inline constexpr in_place_index_t<_Idx> in_place_index{};
547 inline constexpr bool __is_in_place_type_v =
false;
549 template<
typename _Tp>
550 inline constexpr bool __is_in_place_type_v<in_place_type_t<_Tp>> =
true;
553 inline constexpr bool __is_in_place_index_v =
false;
556 inline constexpr bool __is_in_place_index_v<in_place_index_t<_Nm>> =
true;
560#if _GLIBCXX_USE_BUILTIN_TRAIT(__type_pack_element)
561 template<
size_t _Np,
typename... _Types>
563 {
using type = __type_pack_element<_Np, _Types...>; };
565 template<
size_t _Np,
typename... _Types>
569 template<
typename _Tp0,
typename... _Rest>
570 struct _Nth_type<0, _Tp0, _Rest...>
571 {
using type = _Tp0; };
573 template<
typename _Tp0,
typename _Tp1,
typename... _Rest>
574 struct _Nth_type<1, _Tp0, _Tp1, _Rest...>
575 {
using type = _Tp1; };
577 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
578 struct _Nth_type<2, _Tp0, _Tp1, _Tp2, _Rest...>
579 {
using type = _Tp2; };
581 template<
size_t _Np,
typename _Tp0,
typename _Tp1,
typename _Tp2,
586 struct _Nth_type<_Np, _Tp0, _Tp1, _Tp2, _Rest...>
587 : _Nth_type<_Np - 3, _Rest...>
591 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
592 struct _Nth_type<0, _Tp0, _Tp1, _Tp2, _Rest...>
593 {
using type = _Tp0; };
595 template<
typename _Tp0,
typename _Tp1,
typename _Tp2,
typename... _Rest>
596 struct _Nth_type<1, _Tp0, _Tp1, _Tp2, _Rest...>
597 {
using type = _Tp1; };
602 namespace ranges::__detail
604 template<
typename _Range>
605 inline constexpr bool __is_subrange =
false;
611 struct _Swallow_assign
614 constexpr const _Swallow_assign&
615 operator=(
const _Tp&)
const noexcept
636 _GLIBCXX17_INLINE
constexpr _Swallow_assign
ignore{};
638#if __glibcxx_flat_map || __glibcxx_flat_set
639 struct sorted_unique_t {
explicit sorted_unique_t() =
default; };
640 inline constexpr sorted_unique_t sorted_unique{};
642 struct sorted_equivalent_t {
explicit sorted_equivalent_t() =
default; };
643 inline constexpr sorted_equivalent_t sorted_equivalent{};
646_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.
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.