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
98namespace std _GLIBCXX_VISIBILITY(default)
100_GLIBCXX_BEGIN_NAMESPACE_VERSION
102#ifdef __cpp_lib_exchange_function
104 template <typename _Tp, typename _Up = _Tp>
107 exchange(_Tp& __obj, _Up&& __new_val)
108 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
109 is_nothrow_assignable<_Tp&, _Up>>::value)
110 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
113#ifdef __cpp_lib_as_const
114 template<
typename _Tp>
116 constexpr add_const_t<_Tp>&
117 as_const(_Tp& __t)
noexcept
120 template<
typename _Tp>
121 void as_const(
const _Tp&&) =
delete;
124#ifdef __cpp_lib_integer_comparison_functions
125 template<
typename _Tp,
typename _Up>
127 cmp_equal(_Tp __t, _Up __u)
noexcept
129 static_assert(__is_standard_integer<_Tp>::value);
130 static_assert(__is_standard_integer<_Up>::value);
132 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
134 else if constexpr (is_signed_v<_Tp>)
135 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
137 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
140 template<
typename _Tp,
typename _Up>
142 cmp_not_equal(_Tp __t, _Up __u)
noexcept
143 {
return !std::cmp_equal(__t, __u); }
145 template<
typename _Tp,
typename _Up>
147 cmp_less(_Tp __t, _Up __u)
noexcept
149 static_assert(__is_standard_integer<_Tp>::value);
150 static_assert(__is_standard_integer<_Up>::value);
152 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
154 else if constexpr (is_signed_v<_Tp>)
155 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
157 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
160 template<
typename _Tp,
typename _Up>
162 cmp_greater(_Tp __t, _Up __u)
noexcept
163 {
return std::cmp_less(__u, __t); }
165 template<
typename _Tp,
typename _Up>
167 cmp_less_equal(_Tp __t, _Up __u)
noexcept
168 {
return !std::cmp_less(__u, __t); }
170 template<
typename _Tp,
typename _Up>
172 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
173 {
return !std::cmp_less(__t, __u); }
175 template<
typename _Res,
typename _Tp>
177 in_range(_Tp __t)
noexcept
179 static_assert(__is_standard_integer<_Res>::value);
180 static_assert(__is_standard_integer<_Tp>::value);
183 if constexpr (is_signed_v<_Tp> == is_signed_v<_Res>)
184 return __int_traits<_Res>::__min <= __t
185 && __t <= __int_traits<_Res>::__max;
186 else if constexpr (is_signed_v<_Tp>)
188 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Res>::__max;
190 return __t <= make_unsigned_t<_Res>(__int_traits<_Res>::__max);
194#ifdef __cpp_lib_to_underlying
196 template<typename _Tp>
198 constexpr underlying_type_t<_Tp>
199 to_underlying(_Tp __value)
noexcept
200 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
203#ifdef __cpp_lib_unreachable
216 [[noreturn,__gnu__::__always_inline__]]
221 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
222#elif defined _GLIBCXX_ASSERTIONS
225 __builtin_unreachable();
230_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.