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>
57 __check_valid_range(
const _InputIterator& __first,
58 const _InputIterator& __last,
61 const char* __function)
63 __glibcxx_check_valid_range_at(__first, __last,
64 __file, __line, __function);
69 template<
typename _Iterator,
typename _Sequence,
typename _Category>
71 __foreign_iterator_aux4(
72 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
73 const typename _Sequence::value_type* __other)
75 typedef const typename _Sequence::value_type* _PointerType;
77#if __cplusplus >= 201103L
78 constexpr _Less __l{};
80 const _Less __l = _Less();
82 const _Sequence* __seq = __it._M_get_sequence();
87 return __l(__other, __begin) || __l(__end, __other);
91 template<
typename _Iterator,
typename _Sequence,
typename _Category>
93 __foreign_iterator_aux4(
94 const _Safe_iterator<_Iterator, _Sequence, _Category>&, ...)
98 template<
typename _Iterator,
typename _Sequence,
typename _Category,
99 typename _InputIterator>
101 __foreign_iterator_aux3(
102 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
103 const _InputIterator& __other,
const _InputIterator& __other_end,
106 if (__other == __other_end)
108 if (__it._M_get_sequence()->empty())
114 template<
typename _Iterator,
typename _Sequence,
typename _Category,
115 typename _InputIterator>
117 __foreign_iterator_aux3(
118 const _Safe_iterator<_Iterator, _Sequence, _Category>&,
119 const _InputIterator&,
const _InputIterator&,
124 template<
typename _Iterator,
typename _Sequence,
typename _Category,
125 typename _OtherIterator>
131 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
134 template<
typename _Iterator,
typename _Sequence,
typename _Category,
135 typename _OtherIterator,
typename _OtherSequence,
136 typename _OtherCategory>
147 template<
typename _Iterator,
typename _Sequence,
typename _Category,
148 typename _InputIterator>
151 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
152 const _InputIterator& __other,
153 const _InputIterator& __other_end)
155#if __cplusplus < 201103L
156 typedef _Is_contiguous_sequence<_Sequence> __tag;
160 using __contiguous = _Is_contiguous_sequence<_Sequence>;
162 std::__false_type>::type;
164 return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
168 template<
typename _Iterator,
typename _Sequence,
typename _Category,
171 __foreign_iterator_aux(
172 const _Safe_iterator<_Iterator, _Sequence, _Category>&,
173 _Integral, _Integral, std::__true_type)
177 template<
typename _Iterator,
typename _Sequence,
typename _Category,
178 typename _InputIterator>
180 __foreign_iterator_aux(
181 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
182 _InputIterator __other, _InputIterator __other_end,
185 return _Insert_range_from_self_is_safe<_Sequence>::__value
187 std::__miter_base(__other_end));
190 template<
typename _Iterator,
typename _Sequence,
typename _Category,
191 typename _InputIterator>
194 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
195 _InputIterator __other, _InputIterator __other_end)
197 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
198 return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
203 template<
typename _InputIterator>
206 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
212 template<
typename _ForwardIterator>
215 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
218 if (__first == __last)
221 _ForwardIterator __next = __first;
222 for (++__next; __next != __last; __first = __next, (void)++__next)
223 if (*__next < *__first)
231 template<
typename _InputIterator,
typename _Predicate>
234 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
240 template<
typename _ForwardIterator,
typename _Predicate>
243 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
246 if (__first == __last)
249 _ForwardIterator __next = __first;
250 for (++__next; __next != __last; __first = __next, (void)++__next)
251 if (__pred(*__next, *__first))
258 template<
typename _InputIterator>
261 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
263 return __check_sorted_aux(__first, __last,
267 template<
typename _InputIterator,
typename _Predicate>
270 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
273 return __check_sorted_aux(__first, __last, __pred,
277 template<
typename _InputIterator>
280 __check_sorted_set_aux(
const _InputIterator& __first,
281 const _InputIterator& __last,
283 {
return __check_sorted(__first, __last); }
285 template<
typename _InputIterator>
288 __check_sorted_set_aux(
const _InputIterator&,
289 const _InputIterator&,
293 template<
typename _InputIterator,
typename _Predicate>
296 __check_sorted_set_aux(
const _InputIterator& __first,
297 const _InputIterator& __last,
298 _Predicate __pred, std::__true_type)
299 {
return __check_sorted(__first, __last, __pred); }
301 template<
typename _InputIterator,
typename _Predicate>
304 __check_sorted_set_aux(
const _InputIterator&,
305 const _InputIterator&, _Predicate,
310 template<
typename _InputIterator1,
typename _InputIterator2>
313 __check_sorted_set(
const _InputIterator1& __first,
314 const _InputIterator1& __last,
315 const _InputIterator2&)
322 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
324 return __check_sorted_set_aux(__first, __last, _SameType());
327 template<
typename _InputIterator1,
typename _InputIterator2,
331 __check_sorted_set(
const _InputIterator1& __first,
332 const _InputIterator1& __last,
333 const _InputIterator2&, _Predicate __pred)
340 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
342 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
348 template<
typename _ForwardIterator,
typename _Tp>
351 __check_partitioned_lower(_ForwardIterator __first,
352 _ForwardIterator __last,
const _Tp& __value)
354 while (__first != __last && *__first < __value)
356 if (__first != __last)
359 while (__first != __last && !(*__first < __value))
362 return __first == __last;
365 template<
typename _ForwardIterator,
typename _Tp>
368 __check_partitioned_upper(_ForwardIterator __first,
369 _ForwardIterator __last,
const _Tp& __value)
371 while (__first != __last && !(__value < *__first))
373 if (__first != __last)
376 while (__first != __last && __value < *__first)
379 return __first == __last;
383 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
386 __check_partitioned_lower(_ForwardIterator __first,
387 _ForwardIterator __last,
const _Tp& __value,
390 while (__first != __last &&
bool(__pred(*__first, __value)))
392 if (__first != __last)
395 while (__first != __last && !
bool(__pred(*__first, __value)))
398 return __first == __last;
401 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
404 __check_partitioned_upper(_ForwardIterator __first,
405 _ForwardIterator __last,
const _Tp& __value,
408 while (__first != __last && !
bool(__pred(__value, *__first)))
410 if (__first != __last)
413 while (__first != __last &&
bool(__pred(__value, *__first)))
416 return __first == __last;
419#if __cplusplus >= 201103L
420 struct _Irreflexive_checker
422 template<
typename _It>
426 template<
typename _It,
427 typename =
decltype(__ref<_It>() < __ref<_It>())>
430 _S_is_valid(_It __it)
431 {
return !(*__it < *__it); }
434 template<
typename... _Args>
437 _S_is_valid(_Args...)
440 template<
typename _It,
typename _Pred,
typename
441 =
decltype(std::declval<_Pred>()(__ref<_It>(), __ref<_It>()))>
444 _S_is_valid_pred(_It __it, _Pred __pred)
445 {
return !__pred(*__it, *__it); }
448 template<
typename... _Args>
451 _S_is_valid_pred(_Args...)
455 template<
typename _Iterator>
458 __is_irreflexive(_Iterator __it)
459 {
return _Irreflexive_checker::_S_is_valid(__it); }
461 template<
typename _Iterator,
typename _Pred>
464 __is_irreflexive_pred(_Iterator __it, _Pred __pred)
465 {
return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
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 > &)
Define a member typedef type to one of two argument types.
Traits class for iterators.
One of the comparison functors.
Forward iterators support a superset of input iterator operations.