29 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H 30 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1 34 #if __cplusplus >= 201103L 44 template<
typename _Iterator,
typename _Sequence>
47 template<
typename _Sequence>
48 struct _Insert_range_from_self_is_safe
49 {
enum { __value = 0 }; };
51 template<
typename _Sequence>
52 struct _Is_contiguous_sequence : std::__false_type { };
56 __check_singular_aux(
const void*) {
return false; }
60 template<
typename _Iterator>
62 __check_singular(
const _Iterator& __x)
66 template<
typename _Tp>
68 __check_singular(
const _Tp* __ptr)
69 {
return __ptr == 0; }
73 template<
typename _Iterator>
79 template<
typename _Tp>
88 template<
typename _InputIterator>
90 __check_valid_range(
const _InputIterator& __first,
91 const _InputIterator& __last
92 __attribute__((__unused__)))
94 __glibcxx_check_valid_range(__first, __last);
99 template<
typename _Iterator,
typename _Sequence>
102 const typename _Sequence::value_type* __other)
104 typedef const typename _Sequence::value_type* _PointerType;
106 #if __cplusplus >= 201103L 107 constexpr _Less __l{};
109 const _Less __l = _Less();
111 const _Sequence* __seq = __it._M_get_sequence();
116 return __l(__other, __begin) || __l(__end, __other);
120 template<
typename _Iterator,
typename _Sequence>
126 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
129 const _InputIterator& __other,
130 const _InputIterator& __other_end,
133 if (__other == __other_end)
135 if (__it._M_get_sequence()->begin() == __it._M_get_sequence()->end())
141 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
144 const _InputIterator&,
const _InputIterator&,
149 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator>
154 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
157 template<
typename _Iterator,
typename _Sequence,
typename _OtherIterator,
158 typename _OtherSequence>
166 template<
typename _Iterator,
typename _Sequence,
typename _InputIterator>
169 const _InputIterator& __other,
170 const _InputIterator& __other_end)
172 #if __cplusplus < 201103L 173 typedef _Is_contiguous_sequence<_Sequence> __tag;
176 typename std::iterator_traits<_InputIterator>::reference>;
177 using __contiguous = _Is_contiguous_sequence<_Sequence>;
178 using __tag =
typename std::conditional<__lvalref::value, __contiguous,
179 std::__false_type>::type;
181 return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
185 template<
typename _Iterator,
typename _Sequence,
typename _Integral>
188 _Integral, _Integral,
193 template<
typename _Iterator,
typename _Sequence,
194 typename _InputIterator>
197 _InputIterator __other, _InputIterator __other_end,
200 return _Insert_range_from_self_is_safe<_Sequence>::__value
202 std::__miter_base(__other_end));
205 template<
typename _Iterator,
typename _Sequence,
206 typename _InputIterator>
209 _InputIterator __other, _InputIterator __other_end)
211 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
212 return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
216 template<
typename _CharT,
typename _Integer>
219 const _Integer& __n __attribute__((__unused__)))
221 #ifdef _GLIBCXX_DEBUG_PEDANTIC 222 __glibcxx_assert(__s != 0 || __n == 0);
228 template<
typename _CharT>
232 #ifdef _GLIBCXX_DEBUG_PEDANTIC 233 __glibcxx_assert(__s != 0);
240 template<
typename _InputIterator>
242 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
248 template<
typename _ForwardIterator>
250 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
253 if (__first == __last)
256 _ForwardIterator __next = __first;
257 for (++__next; __next != __last; __first = __next, (void)++__next)
258 if (*__next < *__first)
266 template<
typename _InputIterator,
typename _Predicate>
268 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
274 template<
typename _ForwardIterator,
typename _Predicate>
276 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
279 if (__first == __last)
282 _ForwardIterator __next = __first;
283 for (++__next; __next != __last; __first = __next, (void)++__next)
284 if (__pred(*__next, *__first))
291 template<
typename _InputIterator>
293 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
297 __glibcxx_assert(__first == __last || !(*__first < *__first));
299 return __check_sorted_aux(__first, __last,
303 template<
typename _InputIterator,
typename _Predicate>
305 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
310 __glibcxx_assert(__first == __last || !__pred(*__first, *__first));
312 return __check_sorted_aux(__first, __last, __pred,
316 template<
typename _InputIterator>
318 __check_sorted_set_aux(
const _InputIterator& __first,
319 const _InputIterator& __last,
321 {
return __check_sorted(__first, __last); }
323 template<
typename _InputIterator>
325 __check_sorted_set_aux(
const _InputIterator&,
326 const _InputIterator&,
330 template<
typename _InputIterator,
typename _Predicate>
332 __check_sorted_set_aux(
const _InputIterator& __first,
333 const _InputIterator& __last,
334 _Predicate __pred, std::__true_type)
335 {
return __check_sorted(__first, __last, __pred); }
337 template<
typename _InputIterator,
typename _Predicate>
339 __check_sorted_set_aux(
const _InputIterator&,
340 const _InputIterator&, _Predicate,
345 template<
typename _InputIterator1,
typename _InputIterator2>
347 __check_sorted_set(
const _InputIterator1& __first,
348 const _InputIterator1& __last,
349 const _InputIterator2&)
351 typedef typename std::iterator_traits<_InputIterator1>::value_type
353 typedef typename std::iterator_traits<_InputIterator2>::value_type
356 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
358 return __check_sorted_set_aux(__first, __last, _SameType());
361 template<
typename _InputIterator1,
typename _InputIterator2,
364 __check_sorted_set(
const _InputIterator1& __first,
365 const _InputIterator1& __last,
366 const _InputIterator2&, _Predicate __pred)
368 typedef typename std::iterator_traits<_InputIterator1>::value_type
370 typedef typename std::iterator_traits<_InputIterator2>::value_type
373 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
375 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
381 template<
typename _ForwardIterator,
typename _Tp>
383 __check_partitioned_lower(_ForwardIterator __first,
384 _ForwardIterator __last,
const _Tp& __value)
386 while (__first != __last && *__first < __value)
388 if (__first != __last)
391 while (__first != __last && !(*__first < __value))
394 return __first == __last;
397 template<
typename _ForwardIterator,
typename _Tp>
399 __check_partitioned_upper(_ForwardIterator __first,
400 _ForwardIterator __last,
const _Tp& __value)
402 while (__first != __last && !(__value < *__first))
404 if (__first != __last)
407 while (__first != __last && __value < *__first)
410 return __first == __last;
414 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
416 __check_partitioned_lower(_ForwardIterator __first,
417 _ForwardIterator __last,
const _Tp& __value,
420 while (__first != __last &&
bool(__pred(*__first, __value)))
422 if (__first != __last)
425 while (__first != __last && !
bool(__pred(*__first, __value)))
428 return __first == __last;
431 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
433 __check_partitioned_upper(_ForwardIterator __first,
434 _ForwardIterator __last,
const _Tp& __value,
437 while (__first != __last && !
bool(__pred(__value, *__first)))
439 if (__first != __last)
442 while (__first != __last &&
bool(__pred(__value, *__first)))
445 return __first == __last;
448 #if __cplusplus >= 201103L 449 struct _Irreflexive_checker
451 template<
typename _It>
452 static typename std::iterator_traits<_It>::reference
455 template<
typename _It,
456 typename = decltype(__deref<_It>() < __deref<_It>())>
458 _S_is_valid(_It __it)
459 {
return !(*__it < *__it); }
462 template<
typename... _Args>
464 _S_is_valid(_Args...)
467 template<
typename _It,
typename _Pred,
typename 468 = decltype(std::declval<_Pred>()(__deref<_It>(), __deref<_It>()))>
470 _S_is_valid_pred(_It __it, _Pred __pred)
471 {
return !__pred(*__it, *__it); }
474 template<
typename... _Args>
476 _S_is_valid_pred(_Args...)
480 template<
typename _Iterator>
482 __is_irreflexive(_Iterator __it)
483 {
return _Irreflexive_checker::_S_is_valid(__it); }
485 template<
typename _Iterator,
typename _Pred>
487 __is_irreflexive_pred(_Iterator __it, _Pred __pred)
488 {
return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
GNU debug classes for public use.
const _CharT * __check_string(const _CharT *__s, const _Integer &__n __attribute__((__unused__)))
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
One of the comparison functors.
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 > &)
iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)