55#ifndef _GLIBCXX_UTILITY
56#define _GLIBCXX_UTILITY 1
59#pragma GCC system_header
73#if __cplusplus >= 201103L
80#if __cplusplus >= 202002L
84#define __glibcxx_want_addressof_constexpr
85#define __glibcxx_want_as_const
86#define __glibcxx_want_constexpr_algorithms
87#define __glibcxx_want_constexpr_utility
88#define __glibcxx_want_exchange_function
89#define __glibcxx_want_forward_like
90#define __glibcxx_want_integer_comparison_functions
91#define __glibcxx_want_integer_sequence
92#define __glibcxx_want_ranges_zip
93#define __glibcxx_want_to_underlying
94#define __glibcxx_want_tuple_element_t
95#define __glibcxx_want_tuples_by_type
96#define __glibcxx_want_unreachable
97#define __glibcxx_want_tuple_like
98#define __glibcxx_want_constrained_equality
101namespace std _GLIBCXX_VISIBILITY(default)
103_GLIBCXX_BEGIN_NAMESPACE_VERSION
105#ifdef __cpp_lib_exchange_function
107 template <typename _Tp, typename _Up = _Tp>
110 exchange(_Tp& __obj, _Up&& __new_val)
111 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
112 is_nothrow_assignable<_Tp&, _Up>>::value)
113 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
116#ifdef __cpp_lib_as_const
117 template<
typename _Tp>
119 constexpr add_const_t<_Tp>&
120 as_const(_Tp& __t)
noexcept
123 template<
typename _Tp>
124 void as_const(
const _Tp&&) =
delete;
127#ifdef __cpp_lib_integer_comparison_functions
128 template<
typename _Tp,
typename _Up>
130 cmp_equal(_Tp __t, _Up __u)
noexcept
132 static_assert(__is_standard_integer<_Tp>::value);
133 static_assert(__is_standard_integer<_Up>::value);
135 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
137 else if constexpr (is_signed_v<_Tp>)
138 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
140 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
143 template<
typename _Tp,
typename _Up>
145 cmp_not_equal(_Tp __t, _Up __u)
noexcept
146 {
return !std::cmp_equal(__t, __u); }
148 template<
typename _Tp,
typename _Up>
150 cmp_less(_Tp __t, _Up __u)
noexcept
152 static_assert(__is_standard_integer<_Tp>::value);
153 static_assert(__is_standard_integer<_Up>::value);
155 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
157 else if constexpr (is_signed_v<_Tp>)
158 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
160 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
163 template<
typename _Tp,
typename _Up>
165 cmp_greater(_Tp __t, _Up __u)
noexcept
166 {
return std::cmp_less(__u, __t); }
168 template<
typename _Tp,
typename _Up>
170 cmp_less_equal(_Tp __t, _Up __u)
noexcept
171 {
return !std::cmp_less(__u, __t); }
173 template<
typename _Tp,
typename _Up>
175 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
176 {
return !std::cmp_less(__t, __u); }
178 template<
typename _Res,
typename _Tp>
180 in_range(_Tp __t)
noexcept
182 static_assert(__is_standard_integer<_Res>::value);
183 static_assert(__is_standard_integer<_Tp>::value);
186 if constexpr (is_signed_v<_Tp> == is_signed_v<_Res>)
187 return __int_traits<_Res>::__min <= __t
188 && __t <= __int_traits<_Res>::__max;
189 else if constexpr (is_signed_v<_Tp>)
191 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Res>::__max;
193 return __t <= make_unsigned_t<_Res>(__int_traits<_Res>::__max);
197#ifdef __cpp_lib_to_underlying
199 template<typename _Tp>
201 constexpr underlying_type_t<_Tp>
202 to_underlying(_Tp __value)
noexcept
203 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
206#ifdef __cpp_lib_unreachable
219 [[noreturn,__gnu__::__always_inline__]]
224 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
225#elif defined _GLIBCXX_ASSERTIONS
228 __builtin_unreachable();
233_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.