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
97namespace std _GLIBCXX_VISIBILITY(default)
99_GLIBCXX_BEGIN_NAMESPACE_VERSION
101#ifdef __cpp_lib_exchange_function
103 template <typename _Tp, typename _Up = _Tp>
106 exchange(_Tp& __obj, _Up&& __new_val)
107 noexcept(__and_<is_nothrow_move_constructible<_Tp>,
108 is_nothrow_assignable<_Tp&, _Up>>::value)
109 {
return std::__exchange(__obj, std::forward<_Up>(__new_val)); }
112#ifdef __cpp_lib_as_const
113 template<
typename _Tp>
115 constexpr add_const_t<_Tp>&
116 as_const(_Tp& __t)
noexcept
119 template<
typename _Tp>
120 void as_const(
const _Tp&&) =
delete;
123#ifdef __cpp_lib_integer_comparison_functions
124 template<
typename _Tp,
typename _Up>
126 cmp_equal(_Tp __t, _Up __u)
noexcept
128 static_assert(__is_standard_integer<_Tp>::value);
129 static_assert(__is_standard_integer<_Up>::value);
131 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
133 else if constexpr (is_signed_v<_Tp>)
134 return __t >= 0 && make_unsigned_t<_Tp>(__t) == __u;
136 return __u >= 0 && __t == make_unsigned_t<_Up>(__u);
139 template<
typename _Tp,
typename _Up>
141 cmp_not_equal(_Tp __t, _Up __u)
noexcept
142 {
return !std::cmp_equal(__t, __u); }
144 template<
typename _Tp,
typename _Up>
146 cmp_less(_Tp __t, _Up __u)
noexcept
148 static_assert(__is_standard_integer<_Tp>::value);
149 static_assert(__is_standard_integer<_Up>::value);
151 if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
153 else if constexpr (is_signed_v<_Tp>)
154 return __t < 0 || make_unsigned_t<_Tp>(__t) < __u;
156 return __u >= 0 && __t < make_unsigned_t<_Up>(__u);
159 template<
typename _Tp,
typename _Up>
161 cmp_greater(_Tp __t, _Up __u)
noexcept
162 {
return std::cmp_less(__u, __t); }
164 template<
typename _Tp,
typename _Up>
166 cmp_less_equal(_Tp __t, _Up __u)
noexcept
167 {
return !std::cmp_less(__u, __t); }
169 template<
typename _Tp,
typename _Up>
171 cmp_greater_equal(_Tp __t, _Up __u)
noexcept
172 {
return !std::cmp_less(__t, __u); }
174 template<
typename _Res,
typename _Tp>
176 in_range(_Tp __t)
noexcept
178 static_assert(__is_standard_integer<_Res>::value);
179 static_assert(__is_standard_integer<_Tp>::value);
182 if constexpr (is_signed_v<_Tp> == is_signed_v<_Res>)
183 return __int_traits<_Res>::__min <= __t
184 && __t <= __int_traits<_Res>::__max;
185 else if constexpr (is_signed_v<_Tp>)
187 && make_unsigned_t<_Tp>(__t) <= __int_traits<_Res>::__max;
189 return __t <= make_unsigned_t<_Res>(__int_traits<_Res>::__max);
193#ifdef __cpp_lib_to_underlying
195 template<typename _Tp>
197 constexpr underlying_type_t<_Tp>
198 to_underlying(_Tp __value)
noexcept
199 {
return static_cast<underlying_type_t<_Tp>
>(__value); }
202#ifdef __cpp_lib_unreachable
215 [[noreturn,__gnu__::__always_inline__]]
220 std::__glibcxx_assert_fail(
nullptr, 0,
"std::unreachable()",
nullptr);
221#elif defined _GLIBCXX_ASSERTIONS
224 __builtin_unreachable();
229_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.