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
89#if __cplusplus > 201703L
90# define __cpp_lib_constexpr_algorithms 201806L
94 template <
typename _Tp,
typename _Up = _Tp>
98 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
100 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
102#if __cplusplus >= 201703L
104#define __cpp_lib_as_const 201510L
105 template<
typename _Tp>
107 constexpr add_const_t<_Tp>&
108 as_const(_Tp& __t)
noexcept
111 template<
typename _Tp>
112 void as_const(
const _Tp&&) =
delete;
114#if __cplusplus > 201703L
115#define __cpp_lib_integer_comparison_functions 202002L
117 template<
typename _Tp,
typename _Up>
119 cmp_equal(_Tp __t, _Up __u)
noexcept
121 static_assert(__is_standard_integer<_Tp>::value);
122 static_assert(__is_standard_integer<_Up>::value);
124 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
126 else if constexpr (is_signed_v<_Tp>)
127 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
129 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
132 template<
typename _Tp,
typename _Up>
134 cmp_not_equal(_Tp __t, _Up __u)
noexcept
135 {
return !std::cmp_equal(__t, __u); }
137 template<
typename _Tp,
typename _Up>
139 cmp_less(_Tp __t, _Up __u)
noexcept
141 static_assert(__is_standard_integer<_Tp>::value);
142 static_assert(__is_standard_integer<_Up>::value);
144 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
146 else if constexpr (is_signed_v<_Tp>)
147 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
149 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
152 template<
typename _Tp,
typename _Up>
154 cmp_greater(_Tp __t, _Up __u)
noexcept
155 {
return std::cmp_less(__u, __t); }
157 template<
typename _Tp,
typename _Up>
159 cmp_less_equal(_Tp __t, _Up __u)
noexcept
160 {
return !std::cmp_less(__u, __t); }
162 template<
typename _Tp,
typename _Up>
164 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
165 {
return !std::cmp_less(__t, __u); }
167 template<
typename _Up,
typename _Tp>
169 in_range(_Tp __t)
noexcept
171 static_assert(__is_standard_integer<_Up>::value);
172 static_assert(__is_standard_integer<_Tp>::value);
175 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
176 return __int_traits<_Up>::__min <= __t
177 && __t <= __int_traits<_Up>::__max;
178 else if constexpr (is_signed_v<_Tp>)
180 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Up>::__max;
182 return __t <= make_unsigned_t<_Up>(__int_traits<_Up>::__max);
185#if __cplusplus > 202002L
186#define __cpp_lib_to_underlying 202102L
188 template<
typename _Tp>
190 constexpr underlying_type_t<_Tp>
191 to_underlying(_Tp __value)
noexcept
192 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
194#define __cpp_lib_unreachable 202202L
207 [[noreturn,__gnu__::__always_inline__]]
212 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
213#elif defined _GLIBCXX_ASSERTIONS
216 __builtin_unreachable();
224_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>.