55#ifndef _GLIBCXX_UTILITY
56#define _GLIBCXX_UTILITY 1
59#pragma GCC system_header
73#if __cplusplus >= 201103L
80#if __cplusplus >= 202002L
84#if __cplusplus > 202302L
88#define __glibcxx_want_addressof_constexpr
89#define __glibcxx_want_as_const
90#define __glibcxx_want_constexpr_algorithms
91#define __glibcxx_want_constexpr_utility
92#define __glibcxx_want_exchange_function
93#define __glibcxx_want_forward_like
94#define __glibcxx_want_integer_comparison_functions
95#define __glibcxx_want_integer_sequence
96#define __glibcxx_want_ranges_zip
97#define __glibcxx_want_to_underlying
98#define __glibcxx_want_tuple_element_t
99#define __glibcxx_want_tuples_by_type
100#define __glibcxx_want_unreachable
101#define __glibcxx_want_tuple_like
102#define __glibcxx_want_constrained_equality
105namespace std _GLIBCXX_VISIBILITY(default)
107_GLIBCXX_BEGIN_NAMESPACE_VERSION
109#ifdef __cpp_lib_exchange_function
111 template <typename _Tp, typename _Up = _Tp>
114 exchange(_Tp& __obj, _Up&& __new_val)
115 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
116 is_nothrow_assignable<_Tp&, _Up>>::value)
117 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
120#ifdef __cpp_lib_as_const
121 template<
typename _Tp>
123 constexpr add_const_t<_Tp>&
124 as_const(_Tp& __t)
noexcept
127 template<
typename _Tp>
128 void as_const(
const _Tp&&) =
delete;
131#ifdef __cpp_lib_integer_comparison_functions
132 template<
typename _Tp,
typename _Up>
134 cmp_equal(_Tp __t, _Up __u)
noexcept
136 static_assert(__is_standard_integer<_Tp>::value);
137 static_assert(__is_standard_integer<_Up>::value);
139 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
141 else if constexpr (is_signed_v<_Tp>)
142 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
144 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
147 template<
typename _Tp,
typename _Up>
149 cmp_not_equal(_Tp __t, _Up __u)
noexcept
150 {
return !std::cmp_equal(__t, __u); }
152 template<
typename _Tp,
typename _Up>
154 cmp_less(_Tp __t, _Up __u)
noexcept
156 static_assert(__is_standard_integer<_Tp>::value);
157 static_assert(__is_standard_integer<_Up>::value);
159 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
161 else if constexpr (is_signed_v<_Tp>)
162 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
164 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
167 template<
typename _Tp,
typename _Up>
169 cmp_greater(_Tp __t, _Up __u)
noexcept
170 {
return std::cmp_less(__u, __t); }
172 template<
typename _Tp,
typename _Up>
174 cmp_less_equal(_Tp __t, _Up __u)
noexcept
175 {
return !std::cmp_less(__u, __t); }
177 template<
typename _Tp,
typename _Up>
179 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
180 {
return !std::cmp_less(__t, __u); }
182 template<
typename _Res,
typename _Tp>
184 in_range(_Tp __t)
noexcept
186 static_assert(__is_standard_integer<_Res>::value);
187 static_assert(__is_standard_integer<_Tp>::value);
190 if constexpr (is_signed_v<_Tp> == is_signed_v<_Res>)
191 return __int_traits<_Res>::__min <= __t
192 && __t <= __int_traits<_Res>::__max;
193 else if constexpr (is_signed_v<_Tp>)
195 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Res>::__max;
197 return __t <= make_unsigned_t<_Res>(__int_traits<_Res>::__max);
201#ifdef __cpp_lib_to_underlying
203 template<typename _Tp>
205 constexpr underlying_type_t<_Tp>
206 to_underlying(_Tp __value)
noexcept
207 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
210#ifdef __cpp_lib_unreachable
223 [[noreturn,__gnu__::__always_inline__]]
228 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
229#elif defined _GLIBCXX_ASSERTIONS
232 __builtin_unreachable();
237_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.