55#ifndef _GLIBCXX_UTILITY
56#define _GLIBCXX_UTILITY 1
58#pragma GCC system_header
71#if __cplusplus >= 201103L
78#if __cplusplus >= 202002L
82#define __glibcxx_want_addressof_constexpr
83#define __glibcxx_want_as_const
84#define __glibcxx_want_constexpr_algorithms
85#define __glibcxx_want_constexpr_utility
86#define __glibcxx_want_exchange_function
87#define __glibcxx_want_forward_like
88#define __glibcxx_want_integer_comparison_functions
89#define __glibcxx_want_integer_sequence
90#define __glibcxx_want_ranges_zip
91#define __glibcxx_want_to_underlying
92#define __glibcxx_want_tuple_element_t
93#define __glibcxx_want_tuples_by_type
94#define __glibcxx_want_unreachable
95#define __glibcxx_want_tuple_like
96#define __glibcxx_want_constrained_equality
99namespace std _GLIBCXX_VISIBILITY(default)
101_GLIBCXX_BEGIN_NAMESPACE_VERSION
103#ifdef __cpp_lib_exchange_function
105 template <typename _Tp, typename _Up = _Tp>
108 exchange(_Tp& __obj, _Up&& __new_val)
109 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
110 is_nothrow_assignable<_Tp&, _Up>>::value)
111 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
114#ifdef __cpp_lib_as_const
115 template<
typename _Tp>
117 constexpr add_const_t<_Tp>&
118 as_const(_Tp& __t)
noexcept
121 template<
typename _Tp>
122 void as_const(
const _Tp&&) =
delete;
125#ifdef __cpp_lib_integer_comparison_functions
126 template<
typename _Tp,
typename _Up>
128 cmp_equal(_Tp __t, _Up __u)
noexcept
130 static_assert(__is_standard_integer<_Tp>::value);
131 static_assert(__is_standard_integer<_Up>::value);
133 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
135 else if constexpr (is_signed_v<_Tp>)
136 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
138 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
141 template<
typename _Tp,
typename _Up>
143 cmp_not_equal(_Tp __t, _Up __u)
noexcept
144 {
return !std::cmp_equal(__t, __u); }
146 template<
typename _Tp,
typename _Up>
148 cmp_less(_Tp __t, _Up __u)
noexcept
150 static_assert(__is_standard_integer<_Tp>::value);
151 static_assert(__is_standard_integer<_Up>::value);
153 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
155 else if constexpr (is_signed_v<_Tp>)
156 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
158 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
161 template<
typename _Tp,
typename _Up>
163 cmp_greater(_Tp __t, _Up __u)
noexcept
164 {
return std::cmp_less(__u, __t); }
166 template<
typename _Tp,
typename _Up>
168 cmp_less_equal(_Tp __t, _Up __u)
noexcept
169 {
return !std::cmp_less(__u, __t); }
171 template<
typename _Tp,
typename _Up>
173 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
174 {
return !std::cmp_less(__t, __u); }
176 template<
typename _Res,
typename _Tp>
178 in_range(_Tp __t)
noexcept
180 static_assert(__is_standard_integer<_Res>::value);
181 static_assert(__is_standard_integer<_Tp>::value);
184 if constexpr (is_signed_v<_Tp> == is_signed_v<_Res>)
185 return __int_traits<_Res>::__min <= __t
186 && __t <= __int_traits<_Res>::__max;
187 else if constexpr (is_signed_v<_Tp>)
189 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Res>::__max;
191 return __t <= make_unsigned_t<_Res>(__int_traits<_Res>::__max);
195#ifdef __cpp_lib_to_underlying
197 template<typename _Tp>
199 constexpr underlying_type_t<_Tp>
200 to_underlying(_Tp __value)
noexcept
201 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
204#ifdef __cpp_lib_unreachable
217 [[noreturn,__gnu__::__always_inline__]]
222 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
223#elif defined _GLIBCXX_ASSERTIONS
226 __builtin_unreachable();
231_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.