29#ifndef _GLIBCXX_DEBUG_FUNCTIONS_H
30#define _GLIBCXX_DEBUG_FUNCTIONS_H 1
34#if __cplusplus >= 201103L
44 template<
typename _Sequence>
45 struct _Insert_range_from_self_is_safe
46 {
enum { __value = 0 }; };
48 template<
typename _Sequence>
49 struct _Is_contiguous_sequence : std::__false_type { };
55 template<
typename _InputIterator>
56 _GLIBCXX20_CONSTEXPR
inline _InputIterator
57 __check_valid_range(
const _InputIterator& __first,
58 const _InputIterator& __last,
61 const char* __function)
63 if (!std::__is_constant_evaluated())
65 __glibcxx_check_valid_range_at(__first, __last,
66 __file, __line, __function);
73 template<
typename _Iterator,
typename _Sequence,
typename _Category>
75 __foreign_iterator_aux4(
77 const typename _Sequence::value_type* __other)
79 typedef const typename _Sequence::value_type* _PointerType;
80 typedef std::less<_PointerType> _Less;
81#if __cplusplus >= 201103L
82 constexpr _Less __l{};
84 const _Less __l = _Less();
86 const _Sequence* __seq = __it._M_get_sequence();
91 return __l(__other, __begin) || __l(__end, __other);
95 template<
typename _Iterator,
typename _Sequence,
typename _Category>
97 __foreign_iterator_aux4(
102 template<
typename _Iterator,
typename _Sequence,
typename _Category,
103 typename _InputIterator>
105 __foreign_iterator_aux3(
107 const _InputIterator& __other,
const _InputIterator& __other_end,
110 if (__other == __other_end)
112 if (__it._M_get_sequence()->empty())
118 template<
typename _Iterator,
typename _Sequence,
typename _Category,
119 typename _InputIterator>
121 __foreign_iterator_aux3(
123 const _InputIterator&,
const _InputIterator&,
128 template<
typename _Iterator,
typename _Sequence,
typename _Category,
129 typename _OtherIterator>
135 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
138 template<
typename _Iterator,
typename _Sequence,
typename _Category,
139 typename _OtherIterator,
typename _OtherSequence,
140 typename _OtherCategory>
151 template<
typename _Iterator,
typename _Sequence,
typename _Category,
152 typename _InputIterator>
155 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
156 const _InputIterator& __other,
157 const _InputIterator& __other_end)
159#if __cplusplus < 201103L
160 typedef _Is_contiguous_sequence<_Sequence> __tag;
164 using __contiguous = _Is_contiguous_sequence<_Sequence>;
165 using __tag = std::__conditional_t<__lvalref::value, __contiguous,
168 return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
172 template<
typename _Iterator,
typename _Sequence,
typename _Category,
175 __foreign_iterator_aux(
177 _Integral, _Integral, std::__true_type)
181 template<
typename _Iterator,
typename _Sequence,
typename _Category,
182 typename _InputIterator>
184 __foreign_iterator_aux(
186 _InputIterator __other, _InputIterator __other_end,
189 return _Insert_range_from_self_is_safe<_Sequence>::__value
191 std::__miter_base(__other_end));
194 template<
typename _Iterator,
typename _Sequence,
typename _Category,
195 typename _InputIterator>
199 _InputIterator __other, _InputIterator __other_end)
201 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
202 return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
207 template<
typename _InputIterator>
210 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
211 std::input_iterator_tag)
216 template<
typename _ForwardIterator>
219 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
220 std::forward_iterator_tag)
222 if (__first == __last)
225 _ForwardIterator __next = __first;
226 for (++__next; __next != __last; __first = __next, (void)++__next)
227 if (*__next < *__first)
235 template<
typename _InputIterator,
typename _Predicate>
238 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
239 _Predicate, std::input_iterator_tag)
244 template<
typename _ForwardIterator,
typename _Predicate>
247 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
248 _Predicate __pred, std::forward_iterator_tag)
250 if (__first == __last)
253 _ForwardIterator __next = __first;
254 for (++__next; __next != __last; __first = __next, (void)++__next)
255 if (__pred(*__next, *__first))
262 template<
typename _InputIterator>
265 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
267 return __check_sorted_aux(__first, __last,
271 template<
typename _InputIterator,
typename _Predicate>
274 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
277 return __check_sorted_aux(__first, __last, __pred,
281 template<
typename _InputIterator>
284 __check_sorted_set_aux(
const _InputIterator& __first,
285 const _InputIterator& __last,
287 {
return __check_sorted(__first, __last); }
289 template<
typename _InputIterator>
292 __check_sorted_set_aux(
const _InputIterator&,
293 const _InputIterator&,
297 template<
typename _InputIterator,
typename _Predicate>
300 __check_sorted_set_aux(
const _InputIterator& __first,
301 const _InputIterator& __last,
302 _Predicate __pred, std::__true_type)
303 {
return __check_sorted(__first, __last, __pred); }
305 template<
typename _InputIterator,
typename _Predicate>
308 __check_sorted_set_aux(
const _InputIterator&,
309 const _InputIterator&, _Predicate,
314 template<
typename _InputIterator1,
typename _InputIterator2>
317 __check_sorted_set(
const _InputIterator1& __first,
318 const _InputIterator1& __last,
319 const _InputIterator2&)
321 typedef typename std::iterator_traits<_InputIterator1>::value_type
323 typedef typename std::iterator_traits<_InputIterator2>::value_type
326 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
328 return __check_sorted_set_aux(__first, __last, _SameType());
331 template<
typename _InputIterator1,
typename _InputIterator2,
335 __check_sorted_set(
const _InputIterator1& __first,
336 const _InputIterator1& __last,
337 const _InputIterator2&, _Predicate __pred)
339 typedef typename std::iterator_traits<_InputIterator1>::value_type
341 typedef typename std::iterator_traits<_InputIterator2>::value_type
344 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
346 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
352 template<
typename _ForwardIterator,
typename _Tp>
355 __check_partitioned_lower(_ForwardIterator __first,
356 _ForwardIterator __last,
const _Tp& __value)
358 while (__first != __last && *__first < __value)
360 if (__first != __last)
363 while (__first != __last && !(*__first < __value))
366 return __first == __last;
369 template<
typename _ForwardIterator,
typename _Tp>
372 __check_partitioned_upper(_ForwardIterator __first,
373 _ForwardIterator __last,
const _Tp& __value)
375 while (__first != __last && !(__value < *__first))
377 if (__first != __last)
380 while (__first != __last && __value < *__first)
383 return __first == __last;
387 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
390 __check_partitioned_lower(_ForwardIterator __first,
391 _ForwardIterator __last,
const _Tp& __value,
394 while (__first != __last &&
bool(__pred(*__first, __value)))
396 if (__first != __last)
399 while (__first != __last && !
bool(__pred(*__first, __value)))
402 return __first == __last;
405 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
408 __check_partitioned_upper(_ForwardIterator __first,
409 _ForwardIterator __last,
const _Tp& __value,
412 while (__first != __last && !
bool(__pred(__value, *__first)))
414 if (__first != __last)
417 while (__first != __last &&
bool(__pred(__value, *__first)))
420 return __first == __last;
423#if __cplusplus >= 201103L
424 struct _Irreflexive_checker
426 template<
typename _It>
427 static typename std::iterator_traits<_It>::reference
430 template<
typename _It,
431 typename =
decltype(__ref<_It>() < __ref<_It>())>
434 _S_is_valid(_It __it)
435 {
return !(*__it < *__it); }
438 template<
typename... _Args>
441 _S_is_valid(_Args...)
444 template<
typename _It,
typename _Pred,
typename
448 _S_is_valid_pred(_It __it, _Pred __pred)
449 {
return !__pred(*__it, *__it); }
452 template<
typename... _Args>
455 _S_is_valid_pred(_Args...)
459 template<
typename _Iterator>
462 __is_irreflexive(_Iterator __it)
463 {
return _Irreflexive_checker::_S_is_valid(__it); }
465 template<
typename _Iterator,
typename _Pred>
468 __is_irreflexive_pred(_Iterator __it, _Pred __pred)
469 {
return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
GNU debug classes for public use.
bool __foreign_iterator_aux2(const _Safe_iterator< _Iterator, _Sequence, _Category > &__it, const _Safe_iterator< _OtherIterator, _Sequence, _Category > &__other, const _Safe_iterator< _OtherIterator, _Sequence, _Category > &)
Traits class for iterators.