29 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H
30 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1
38 #if __cplusplus >= 201103L
39 # include <type_traits>
45 template<
typename _Iterator,
typename _Sequence>
48 template<
typename _Iterator,
typename _Sequence>
49 class _Safe_local_iterator;
51 template<
typename _Sequence>
52 struct _Insert_range_from_self_is_safe
53 {
enum { __value = 0 }; };
55 template<
typename _Sequence>
56 struct _Is_contiguous_sequence : std::__false_type { };
60 __check_singular_aux(
const void*) {
return false; }
64 template<
typename _Iterator>
66 __check_singular(
const _Iterator& __x)
67 {
return __check_singular_aux(&__x); }
70 template<
typename _Tp>
72 __check_singular(
const _Tp* __ptr)
73 {
return __ptr == 0; }
77 template<
typename _Iterator>
83 template<
typename _Tp>
89 template<
typename _Iterator,
typename _Sequence>
95 template<
typename _Iterator,
typename _Sequence>
99 {
return __x._M_dereferenceable(); }
104 template<
typename _RandomAccessIterator>
107 const _RandomAccessIterator& __last,
109 {
return __last - __first >= 0; }
115 template<
typename _InputIterator>
125 template<
typename _Integral>
133 template<
typename _InputIterator>
136 const _InputIterator& __last, std::__false_type)
145 template<
typename _InputIterator>
149 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
154 template<
typename _Iterator,
typename _Sequence>
158 {
return __first._M_valid_range(__last); }
161 template<
typename _Iterator,
typename _Sequence>
165 {
return __first._M_valid_range(__last); }
171 template<
typename _InputIterator>
172 inline _InputIterator
173 __check_valid_range(
const _InputIterator& __first,
174 const _InputIterator& __last
175 __attribute__((__unused__)))
177 __glibcxx_check_valid_range(__first, __last);
182 template<
typename _Iterator,
typename _Sequence>
184 __foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence>& __it,
185 const typename _Sequence::value_type* __other)
187 typedef const typename _Sequence::value_type* _PointerType;
189 #if __cplusplus >= 201103L
190 constexpr _Less __l{};
192 const _Less __l = _Less();
194 const _Sequence* __seq = __it._M_get_sequence();
199 return __l(__other, __begin) || __l(__end, __other);
203 template<
typename _Iterator,
typename _Sequence>
205 __foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence>&, ...)
209 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
211 __foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence>& __it,
212 const _InputIterator& __other,
213 const _InputIterator& __other_end,
216 if (__other == __other_end)
218 if (__it._M_get_sequence()->begin() == __it._M_get_sequence()->end())
224 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
226 __foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence>&,
227 const _InputIterator&,
const _InputIterator&,
232 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator>
237 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
240 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator,
241 typename _OtherSequence>
249 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
252 const _InputIterator& __other,
253 const _InputIterator& __other_end)
255 return __foreign_iterator_aux3(__it, __other, __other_end,
256 _Is_contiguous_sequence<_Sequence>());
260 template<
typename _Iterator,
typename _Sequence,
typename _Integral>
262 __foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence>&,
263 _Integral, _Integral,
268 template<
typename _Iterator,
typename _Sequence,
269 typename _InputIterator>
271 __foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence>& __it,
272 _InputIterator __other, _InputIterator __other_end,
275 return _Insert_range_from_self_is_safe<_Sequence>::__value
279 template<
typename _Iterator,
typename _Sequence,
280 typename _InputIterator>
282 __foreign_iterator(
const _Safe_iterator<_Iterator, _Sequence>& __it,
283 _InputIterator __other, _InputIterator __other_end)
285 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
286 return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
290 template<
typename _CharT,
typename _Integer>
293 const _Integer& __n __attribute__((__unused__)))
295 #ifdef _GLIBCXX_DEBUG_PEDANTIC
296 __glibcxx_assert(__s != 0 || __n == 0);
302 template<
typename _CharT>
306 #ifdef _GLIBCXX_DEBUG_PEDANTIC
307 __glibcxx_assert(__s != 0);
314 template<
typename _InputIterator>
316 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
322 template<
typename _ForwardIterator>
324 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
327 if (__first == __last)
330 _ForwardIterator __next = __first;
331 for (++__next; __next != __last; __first = __next, ++__next)
332 if (*__next < *__first)
340 template<
typename _InputIterator,
typename _Predicate>
342 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
348 template<
typename _ForwardIterator,
typename _Predicate>
350 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
353 if (__first == __last)
356 _ForwardIterator __next = __first;
357 for (++__next; __next != __last; __first = __next, ++__next)
358 if (__pred(*__next, *__first))
365 template<
typename _InputIterator>
367 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
371 __glibcxx_assert(__first == __last || !(*__first < *__first));
373 return __check_sorted_aux(__first, __last,
377 template<
typename _InputIterator,
typename _Predicate>
379 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
384 __glibcxx_assert(__first == __last || !__pred(*__first, *__first));
386 return __check_sorted_aux(__first, __last, __pred,
390 template<
typename _InputIterator>
392 __check_sorted_set_aux(
const _InputIterator& __first,
393 const _InputIterator& __last,
395 {
return __check_sorted(__first, __last); }
397 template<
typename _InputIterator>
399 __check_sorted_set_aux(
const _InputIterator&,
400 const _InputIterator&,
404 template<
typename _InputIterator,
typename _Predicate>
406 __check_sorted_set_aux(
const _InputIterator& __first,
407 const _InputIterator& __last,
408 _Predicate __pred, std::__true_type)
409 {
return __check_sorted(__first, __last, __pred); }
411 template<
typename _InputIterator,
typename _Predicate>
413 __check_sorted_set_aux(
const _InputIterator&,
414 const _InputIterator&, _Predicate,
419 template<
typename _InputIterator1,
typename _InputIterator2>
421 __check_sorted_set(
const _InputIterator1& __first,
422 const _InputIterator1& __last,
423 const _InputIterator2&)
425 typedef typename std::iterator_traits<_InputIterator1>::value_type
427 typedef typename std::iterator_traits<_InputIterator2>::value_type
430 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
432 return __check_sorted_set_aux(__first, __last, _SameType());
435 template<
typename _InputIterator1,
typename _InputIterator2,
438 __check_sorted_set(
const _InputIterator1& __first,
439 const _InputIterator1& __last,
440 const _InputIterator2&, _Predicate __pred)
442 typedef typename std::iterator_traits<_InputIterator1>::value_type
444 typedef typename std::iterator_traits<_InputIterator2>::value_type
447 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
449 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
455 template<
typename _ForwardIterator,
typename _Tp>
457 __check_partitioned_lower(_ForwardIterator __first,
458 _ForwardIterator __last,
const _Tp& __value)
460 while (__first != __last && *__first < __value)
462 if (__first != __last)
465 while (__first != __last && !(*__first < __value))
468 return __first == __last;
471 template<
typename _ForwardIterator,
typename _Tp>
473 __check_partitioned_upper(_ForwardIterator __first,
474 _ForwardIterator __last,
const _Tp& __value)
476 while (__first != __last && !(__value < *__first))
478 if (__first != __last)
481 while (__first != __last && __value < *__first)
484 return __first == __last;
488 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
490 __check_partitioned_lower(_ForwardIterator __first,
491 _ForwardIterator __last,
const _Tp& __value,
494 while (__first != __last &&
bool(__pred(*__first, __value)))
496 if (__first != __last)
499 while (__first != __last && !
bool(__pred(*__first, __value)))
502 return __first == __last;
505 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
507 __check_partitioned_upper(_ForwardIterator __first,
508 _ForwardIterator __last,
const _Tp& __value,
511 while (__first != __last && !
bool(__pred(__value, *__first)))
513 if (__first != __last)
516 while (__first != __last &&
bool(__pred(__value, *__first)))
519 return __first == __last;
523 template<
typename _Iterator>
524 struct __is_safe_random_iterator
526 enum { __value = 0 };
527 typedef std::__false_type __type;
530 template<
typename _Iterator,
typename _Sequence>
531 struct __is_safe_random_iterator<_Safe_iterator<_Iterator, _Sequence> >
532 : std::__are_same<std::random_access_iterator_tag,
533 typename std::iterator_traits<_Iterator>::
537 template<
typename _Iterator>
539 : std::_Iter_base<_Iterator, __is_safe_random_iterator<_Iterator>::__value>
548 template<
typename _Iterator>
549 inline typename _Siter_base<_Iterator>::iterator_type
551 {
return _Siter_base<_Iterator>::_S_base(__it); }
bool __valid_range_aux(const _Integral &, const _Integral &, std::__true_type)
bool __check_dereferenceable(const _Iterator &)
Forward iterators support a superset of input iterator operations.
bool __foreign_iterator_aux2(const _Safe_iterator< _Iterator, _Sequence > &__it, const _Safe_iterator< _OtherIterator, _Sequence > &__other, const _Safe_iterator< _OtherIterator, _Sequence > &)
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
GNU debug classes for public use.
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
bool __valid_range(const _InputIterator &__first, const _InputIterator &__last)
Random-access iterators support a superset of bidirectional iterator operations.
bool _M_dereferenceable() const
Is the iterator dereferenceable?
One of the comparison functors.
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
bool __valid_range_aux2(const _RandomAccessIterator &__first, const _RandomAccessIterator &__last, std::random_access_iterator_tag)