29 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H
30 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1
37 #if __cplusplus >= 201103L
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 }; };
57 __check_singular_aux(
const void*) {
return false; }
61 template<
typename _Iterator>
63 __check_singular(
const _Iterator& __x)
64 {
return __check_singular_aux(&__x); }
67 template<
typename _Tp>
69 __check_singular(
const _Tp* __ptr)
70 {
return __ptr == 0; }
74 template<
typename _Iterator>
80 template<
typename _Tp>
86 template<
typename _Iterator,
typename _Sequence>
92 template<
typename _Iterator,
typename _Sequence>
96 {
return __x._M_dereferenceable(); }
101 template<
typename _RandomAccessIterator>
104 const _RandomAccessIterator& __last,
106 {
return __last - __first >= 0; }
112 template<
typename _InputIterator>
122 template<
typename _Integral>
130 template<
typename _InputIterator>
133 const _InputIterator& __last, std::__false_type)
142 template<
typename _InputIterator>
146 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
151 template<
typename _Iterator,
typename _Sequence>
155 {
return __first._M_valid_range(__last); }
158 template<
typename _Iterator,
typename _Sequence>
162 {
return __first._M_valid_range(__last); }
168 template<
typename _InputIterator>
169 inline _InputIterator
170 __check_valid_range(
const _InputIterator& __first,
171 const _InputIterator& __last
172 __attribute__((__unused__)))
174 __glibcxx_check_valid_range(__first, __last);
178 #if __cplusplus >= 201103L
180 template<
typename _Iterator,
typename _Sequence>
182 __foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence>& __it,
183 typename _Sequence::const_pointer __begin,
184 typename _Sequence::const_pointer __other)
186 typedef typename _Sequence::const_pointer _PointerType;
189 return (__l(__other, __begin)
196 template<
typename _Iterator,
typename _Sequence,
197 typename _InputIterator>
199 __foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence>&,
203 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
205 __foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence>& __it,
206 _InputIterator __other,
213 if (__it._M_get_sequence()->_M_base().begin()
214 != __it._M_get_sequence()->_M_base().end())
215 if (
std::addressof(*(__it._M_get_sequence()->_M_base().end() - 1))
217 == __it._M_get_sequence()->size() - 1)
218 return (__foreign_iterator_aux4
226 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
228 __foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence>& __it,
229 _InputIterator __other,
235 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator>
240 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
242 #if __cplusplus >= 201103L
246 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
249 _InputIterator __other,
252 typedef typename _Sequence::const_iterator _ItType;
253 typedef typename std::iterator_traits<_ItType>::reference _Ref;
254 return __foreign_iterator_aux3(__it, __other,
260 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
267 template<
typename _Iterator,
typename _Sequence,
270 __foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence>& __it,
275 template<
typename _Iterator,
typename _Sequence,
276 typename _InputIterator>
278 __foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence>& __it,
279 _InputIterator __other,
282 return (_Insert_range_from_self_is_safe<_Sequence>::__value
287 template<
typename _Iterator,
typename _Sequence,
288 typename _InputIterator>
290 __foreign_iterator(
const _Safe_iterator<_Iterator, _Sequence>& __it,
291 _InputIterator __other)
293 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
294 return __foreign_iterator_aux(__it, __other, _Integral());
298 template<
typename _CharT,
typename _Integer>
301 const _Integer& __n __attribute__((__unused__)))
303 #ifdef _GLIBCXX_DEBUG_PEDANTIC
304 __glibcxx_assert(__s != 0 || __n == 0);
310 template<
typename _CharT>
314 #ifdef _GLIBCXX_DEBUG_PEDANTIC
315 __glibcxx_assert(__s != 0);
322 template<
typename _InputIterator>
324 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
330 template<
typename _ForwardIterator>
332 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
335 if (__first == __last)
338 _ForwardIterator __next = __first;
339 for (++__next; __next != __last; __first = __next, ++__next)
340 if (*__next < *__first)
348 template<
typename _InputIterator,
typename _Predicate>
350 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
356 template<
typename _ForwardIterator,
typename _Predicate>
358 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
361 if (__first == __last)
364 _ForwardIterator __next = __first;
365 for (++__next; __next != __last; __first = __next, ++__next)
366 if (__pred(*__next, *__first))
373 template<
typename _InputIterator>
375 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
379 __glibcxx_assert(__first == __last || !(*__first < *__first));
381 return __check_sorted_aux(__first, __last,
385 template<
typename _InputIterator,
typename _Predicate>
387 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
392 __glibcxx_assert(__first == __last || !__pred(*__first, *__first));
394 return __check_sorted_aux(__first, __last, __pred,
398 template<
typename _InputIterator>
400 __check_sorted_set_aux(
const _InputIterator& __first,
401 const _InputIterator& __last,
403 {
return __check_sorted(__first, __last); }
405 template<
typename _InputIterator>
407 __check_sorted_set_aux(
const _InputIterator&,
408 const _InputIterator&,
412 template<
typename _InputIterator,
typename _Predicate>
414 __check_sorted_set_aux(
const _InputIterator& __first,
415 const _InputIterator& __last,
416 _Predicate __pred, std::__true_type)
417 {
return __check_sorted(__first, __last, __pred); }
419 template<
typename _InputIterator,
typename _Predicate>
421 __check_sorted_set_aux(
const _InputIterator&,
422 const _InputIterator&, _Predicate,
427 template<
typename _InputIterator1,
typename _InputIterator2>
429 __check_sorted_set(
const _InputIterator1& __first,
430 const _InputIterator1& __last,
431 const _InputIterator2&)
433 typedef typename std::iterator_traits<_InputIterator1>::value_type
435 typedef typename std::iterator_traits<_InputIterator2>::value_type
438 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
440 return __check_sorted_set_aux(__first, __last, _SameType());
443 template<
typename _InputIterator1,
typename _InputIterator2,
446 __check_sorted_set(
const _InputIterator1& __first,
447 const _InputIterator1& __last,
448 const _InputIterator2&, _Predicate __pred)
450 typedef typename std::iterator_traits<_InputIterator1>::value_type
452 typedef typename std::iterator_traits<_InputIterator2>::value_type
455 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
457 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
463 template<
typename _ForwardIterator,
typename _Tp>
465 __check_partitioned_lower(_ForwardIterator __first,
466 _ForwardIterator __last,
const _Tp& __value)
468 while (__first != __last && *__first < __value)
470 if (__first != __last)
473 while (__first != __last && !(*__first < __value))
476 return __first == __last;
479 template<
typename _ForwardIterator,
typename _Tp>
481 __check_partitioned_upper(_ForwardIterator __first,
482 _ForwardIterator __last,
const _Tp& __value)
484 while (__first != __last && !(__value < *__first))
486 if (__first != __last)
489 while (__first != __last && __value < *__first)
492 return __first == __last;
496 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
498 __check_partitioned_lower(_ForwardIterator __first,
499 _ForwardIterator __last,
const _Tp& __value,
502 while (__first != __last &&
bool(__pred(*__first, __value)))
504 if (__first != __last)
507 while (__first != __last && !
bool(__pred(*__first, __value)))
510 return __first == __last;
513 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
515 __check_partitioned_upper(_ForwardIterator __first,
516 _ForwardIterator __last,
const _Tp& __value,
519 while (__first != __last && !
bool(__pred(__value, *__first)))
521 if (__first != __last)
524 while (__first != __last &&
bool(__pred(__value, *__first)))
527 return __first == __last;
531 template<
typename _Iterator>
532 struct __is_safe_random_iterator
534 enum { __value = 0 };
535 typedef std::__false_type __type;
538 template<
typename _Iterator,
typename _Sequence>
539 struct __is_safe_random_iterator<_Safe_iterator<_Iterator, _Sequence> >
540 : std::__are_same<std::random_access_iterator_tag,
541 typename std::iterator_traits<_Iterator>::
545 template<
typename _Iterator>
547 : std::_Iter_base<_Iterator, __is_safe_random_iterator<_Iterator>::__value>
556 template<
typename _Iterator>
557 inline typename _Siter_base<_Iterator>::iterator_type
559 {
return _Siter_base<_Iterator>::_S_base(__it); }
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
Forward iterators support a superset of input iterator operations.
_Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
Random-access iterators support a superset of bidirectional iterator operations.
One of the comparison functors.
bool __valid_range_aux(const _Integral &, const _Integral &, std::__true_type)
bool __check_dereferenceable(const _Iterator &)
bool __valid_range(const _InputIterator &__first, const _InputIterator &__last)
bool _M_dereferenceable() const
Is the iterator dereferenceable?
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
bool __foreign_iterator_aux2(const _Safe_iterator< _Iterator, _Sequence > &__it, const _Safe_iterator< _OtherIterator, _Sequence > &__other, std::input_iterator_tag)
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
bool __valid_range_aux2(const _RandomAccessIterator &__first, const _RandomAccessIterator &__last, std::random_access_iterator_tag)