29 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H 30 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1 34 #if __cplusplus >= 201103L 43 template<
typename _Iterator,
typename _Sequence>
46 template<
typename _Sequence>
47 struct _Insert_range_from_self_is_safe
48 {
enum { __value = 0 }; };
50 template<
typename _Sequence>
51 struct _Is_contiguous_sequence : std::__false_type { };
55 __check_singular_aux(
const void*) {
return false; }
59 template<
typename _Iterator>
61 __check_singular(
const _Iterator& __x)
65 template<
typename _Tp>
67 __check_singular(
const _Tp* __ptr)
68 {
return __ptr == 0; }
72 template<
typename _Iterator>
78 template<
typename _Tp>
87 template<
typename _InputIterator>
89 __check_valid_range(
const _InputIterator& __first,
90 const _InputIterator& __last
91 __attribute__((__unused__)))
93 __glibcxx_check_valid_range(__first, __last);
98 template<
typename _Iterator,
typename _Sequence>
100 __foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence>& __it,
101 const typename _Sequence::value_type* __other)
103 typedef const typename _Sequence::value_type* _PointerType;
105 #if __cplusplus >= 201103L 106 constexpr _Less __l{};
108 const _Less __l = _Less();
110 const _Sequence* __seq = __it._M_get_sequence();
115 return __l(__other, __begin) || __l(__end, __other);
119 template<
typename _Iterator,
typename _Sequence>
121 __foreign_iterator_aux4(
const _Safe_iterator<_Iterator, _Sequence>&, ...)
125 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
127 __foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence>& __it,
128 const _InputIterator& __other,
129 const _InputIterator& __other_end,
132 if (__other == __other_end)
134 if (__it._M_get_sequence()->begin() == __it._M_get_sequence()->end())
140 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
142 __foreign_iterator_aux3(
const _Safe_iterator<_Iterator, _Sequence>&,
143 const _InputIterator&,
const _InputIterator&,
148 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator>
153 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
156 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator,
157 typename _OtherSequence>
165 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
168 const _InputIterator& __other,
169 const _InputIterator& __other_end)
171 #if __cplusplus < 201103L 172 typedef _Is_contiguous_sequence<_Sequence> __tag;
175 typename std::iterator_traits<_InputIterator>::reference>;
176 using __contiguous = _Is_contiguous_sequence<_Sequence>;
178 std::__false_type>::type;
180 return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
184 template<
typename _Iterator,
typename _Sequence,
typename _Integral>
186 __foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence>&,
187 _Integral, _Integral,
192 template<
typename _Iterator,
typename _Sequence,
193 typename _InputIterator>
195 __foreign_iterator_aux(
const _Safe_iterator<_Iterator, _Sequence>& __it,
196 _InputIterator __other, _InputIterator __other_end,
199 return _Insert_range_from_self_is_safe<_Sequence>::__value
201 std::__miter_base(__other_end));
204 template<
typename _Iterator,
typename _Sequence,
205 typename _InputIterator>
207 __foreign_iterator(
const _Safe_iterator<_Iterator, _Sequence>& __it,
208 _InputIterator __other, _InputIterator __other_end)
210 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
211 return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
215 template<
typename _CharT,
typename _Integer>
218 const _Integer& __n __attribute__((__unused__)))
220 #ifdef _GLIBCXX_DEBUG_PEDANTIC 221 __glibcxx_assert(__s != 0 || __n == 0);
227 template<
typename _CharT>
231 #ifdef _GLIBCXX_DEBUG_PEDANTIC 232 __glibcxx_assert(__s != 0);
239 template<
typename _InputIterator>
241 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
247 template<
typename _ForwardIterator>
249 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
252 if (__first == __last)
255 _ForwardIterator __next = __first;
256 for (++__next; __next != __last; __first = __next, (void)++__next)
257 if (*__next < *__first)
265 template<
typename _InputIterator,
typename _Predicate>
267 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
273 template<
typename _ForwardIterator,
typename _Predicate>
275 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
278 if (__first == __last)
281 _ForwardIterator __next = __first;
282 for (++__next; __next != __last; __first = __next, (void)++__next)
283 if (__pred(*__next, *__first))
290 template<
typename _InputIterator>
292 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
296 __glibcxx_assert(__first == __last || !(*__first < *__first));
298 return __check_sorted_aux(__first, __last,
302 template<
typename _InputIterator,
typename _Predicate>
304 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
309 __glibcxx_assert(__first == __last || !__pred(*__first, *__first));
311 return __check_sorted_aux(__first, __last, __pred,
315 template<
typename _InputIterator>
317 __check_sorted_set_aux(
const _InputIterator& __first,
318 const _InputIterator& __last,
320 {
return __check_sorted(__first, __last); }
322 template<
typename _InputIterator>
324 __check_sorted_set_aux(
const _InputIterator&,
325 const _InputIterator&,
329 template<
typename _InputIterator,
typename _Predicate>
331 __check_sorted_set_aux(
const _InputIterator& __first,
332 const _InputIterator& __last,
333 _Predicate __pred, std::__true_type)
334 {
return __check_sorted(__first, __last, __pred); }
336 template<
typename _InputIterator,
typename _Predicate>
338 __check_sorted_set_aux(
const _InputIterator&,
339 const _InputIterator&, _Predicate,
344 template<
typename _InputIterator1,
typename _InputIterator2>
346 __check_sorted_set(
const _InputIterator1& __first,
347 const _InputIterator1& __last,
348 const _InputIterator2&)
350 typedef typename std::iterator_traits<_InputIterator1>::value_type
352 typedef typename std::iterator_traits<_InputIterator2>::value_type
355 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
357 return __check_sorted_set_aux(__first, __last, _SameType());
360 template<
typename _InputIterator1,
typename _InputIterator2,
363 __check_sorted_set(
const _InputIterator1& __first,
364 const _InputIterator1& __last,
365 const _InputIterator2&, _Predicate __pred)
367 typedef typename std::iterator_traits<_InputIterator1>::value_type
369 typedef typename std::iterator_traits<_InputIterator2>::value_type
372 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
374 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
380 template<
typename _ForwardIterator,
typename _Tp>
382 __check_partitioned_lower(_ForwardIterator __first,
383 _ForwardIterator __last,
const _Tp& __value)
385 while (__first != __last && *__first < __value)
387 if (__first != __last)
390 while (__first != __last && !(*__first < __value))
393 return __first == __last;
396 template<
typename _ForwardIterator,
typename _Tp>
398 __check_partitioned_upper(_ForwardIterator __first,
399 _ForwardIterator __last,
const _Tp& __value)
401 while (__first != __last && !(__value < *__first))
403 if (__first != __last)
406 while (__first != __last && __value < *__first)
409 return __first == __last;
413 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
415 __check_partitioned_lower(_ForwardIterator __first,
416 _ForwardIterator __last,
const _Tp& __value,
419 while (__first != __last &&
bool(__pred(*__first, __value)))
421 if (__first != __last)
424 while (__first != __last && !
bool(__pred(*__first, __value)))
427 return __first == __last;
430 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
432 __check_partitioned_upper(_ForwardIterator __first,
433 _ForwardIterator __last,
const _Tp& __value,
436 while (__first != __last && !
bool(__pred(__value, *__first)))
438 if (__first != __last)
441 while (__first != __last &&
bool(__pred(__value, *__first)))
444 return __first == __last;
447 #if __cplusplus >= 201103L 448 struct _Irreflexive_checker
450 template<
typename _It>
451 static typename std::iterator_traits<_It>::reference
454 template<
typename _It,
455 typename = decltype(__deref<_It>() < __deref<_It>())>
457 _S_is_valid(_It __it)
458 {
return !(*__it < *__it); }
461 template<
typename... _Args>
463 _S_is_valid(_Args...)
466 template<
typename _It,
typename _Pred,
typename 467 = decltype(std::declval<_Pred>()(__deref<_It>(), __deref<_It>()))>
469 _S_is_valid_pred(_It __it, _Pred __pred)
470 {
return !__pred(*__it, *__it); }
473 template<
typename... _Args>
475 _S_is_valid_pred(_Args...)
479 template<
typename _Iterator>
481 __is_irreflexive(_Iterator __it)
482 {
return _Irreflexive_checker::_S_is_valid(__it); }
484 template<
typename _Iterator,
typename _Pred>
486 __is_irreflexive_pred(_Iterator __it, _Pred __pred)
487 {
return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
One of the comparison functors.
GNU debug classes for public use.
Forward iterators support a superset of input iterator operations.
Define a member typedef type to one of two argument types.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
bool __check_dereferenceable(const _Iterator &)
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
bool __foreign_iterator_aux2(const _Safe_iterator< _Iterator, _Sequence > &__it, const _Safe_iterator< _OtherIterator, _Sequence > &__other, const _Safe_iterator< _OtherIterator, _Sequence > &)