55#ifndef _GLIBCXX_UTILITY
56#define _GLIBCXX_UTILITY 1
58#pragma GCC system_header
71#if __cplusplus >= 201103L
78#if __cplusplus >= 202002L
82namespace std _GLIBCXX_VISIBILITY(default)
84_GLIBCXX_BEGIN_NAMESPACE_VERSION
86#if __cplusplus >= 201402L
87#define __cpp_lib_exchange_function 201304L
90 template <
typename _Tp,
typename _Up = _Tp>
94 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
96 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
98#if __cplusplus >= 201703L
100#define __cpp_lib_as_const 201510L
101 template<
typename _Tp>
103 constexpr add_const_t<_Tp>&
104 as_const(_Tp& __t)
noexcept
107 template<
typename _Tp>
108 void as_const(
const _Tp&&) =
delete;
110#if __cplusplus > 201703L
111#define __cpp_lib_integer_comparison_functions 202002L
113 template<
typename _Tp,
typename _Up>
115 cmp_equal(_Tp __t, _Up __u)
noexcept
117 static_assert(__is_standard_integer<_Tp>::value);
118 static_assert(__is_standard_integer<_Up>::value);
120 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
122 else if constexpr (is_signed_v<_Tp>)
123 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
125 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
128 template<
typename _Tp,
typename _Up>
130 cmp_not_equal(_Tp __t, _Up __u)
noexcept
131 {
return !std::cmp_equal(__t, __u); }
133 template<
typename _Tp,
typename _Up>
135 cmp_less(_Tp __t, _Up __u)
noexcept
137 static_assert(__is_standard_integer<_Tp>::value);
138 static_assert(__is_standard_integer<_Up>::value);
140 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
142 else if constexpr (is_signed_v<_Tp>)
143 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
145 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
148 template<
typename _Tp,
typename _Up>
150 cmp_greater(_Tp __t, _Up __u)
noexcept
151 {
return std::cmp_less(__u, __t); }
153 template<
typename _Tp,
typename _Up>
155 cmp_less_equal(_Tp __t, _Up __u)
noexcept
156 {
return !std::cmp_less(__u, __t); }
158 template<
typename _Tp,
typename _Up>
160 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
161 {
return !std::cmp_less(__t, __u); }
163 template<
typename _Up,
typename _Tp>
165 in_range(_Tp __t)
noexcept
167 static_assert(__is_standard_integer<_Up>::value);
168 static_assert(__is_standard_integer<_Tp>::value);
171 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
172 return __int_traits<_Up>::__min <= __t
173 && __t <= __int_traits<_Up>::__max;
174 else if constexpr (is_signed_v<_Tp>)
176 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Up>::__max;
178 return __t <= make_unsigned_t<_Up>(__int_traits<_Up>::__max);
181#if __cplusplus > 202002L
182#define __cpp_lib_to_underlying 202102L
184 template<
typename _Tp>
186 constexpr underlying_type_t<_Tp>
187 to_underlying(_Tp __value)
noexcept
188 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
190#define __cpp_lib_unreachable 202202L
203 [[noreturn,__gnu__::__always_inline__]]
208 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
209#elif defined _GLIBCXX_ASSERTIONS
212 __builtin_unreachable();
220_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
constexpr _Tp exchange(_Tp &__obj, _Up &&__new_val) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_assignable< _Tp &, _Up > >::value)
Assign __new_val to __obj and return its previous value.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.