29 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H 30 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1 35 #if __cplusplus >= 201103L 45 template<
typename _Sequence>
46 struct _Insert_range_from_self_is_safe
47 {
enum { __value = 0 }; };
49 template<
typename _Sequence>
50 struct _Is_contiguous_sequence : std::__false_type { };
54 __check_singular_aux(
const void*) {
return false; }
58 template<
typename _Iterator>
60 __check_singular(
const _Iterator& __x)
64 template<
typename _Tp>
66 __check_singular(
const _Tp* __ptr)
67 {
return __ptr == 0; }
73 template<
typename _InputIterator>
75 __check_valid_range(
const _InputIterator& __first,
76 const _InputIterator& __last,
79 const char* __function)
81 __glibcxx_check_valid_range_at(__first, __last,
82 __file, __line, __function);
87 template<
typename _Iterator,
typename _Sequence,
typename _Category>
89 __foreign_iterator_aux4(
90 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
91 const typename _Sequence::value_type* __other)
93 typedef const typename _Sequence::value_type* _PointerType;
95 #if __cplusplus >= 201103L 96 constexpr _Less __l{};
98 const _Less __l = _Less();
100 const _Sequence* __seq = __it._M_get_sequence();
105 return __l(__other, __begin) || __l(__end, __other);
109 template<
typename _Iterator,
typename _Sequence,
typename _Category>
111 __foreign_iterator_aux4(
112 const _Safe_iterator<_Iterator, _Sequence, _Category>&, ...)
116 template<
typename _Iterator,
typename _Sequence,
typename _Category,
117 typename _InputIterator>
119 __foreign_iterator_aux3(
120 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
121 const _InputIterator& __other,
const _InputIterator& __other_end,
124 if (__other == __other_end)
126 if (__it._M_get_sequence()->empty())
132 template<
typename _Iterator,
typename _Sequence,
typename _Category,
133 typename _InputIterator>
135 __foreign_iterator_aux3(
136 const _Safe_iterator<_Iterator, _Sequence, _Category>&,
137 const _InputIterator&,
const _InputIterator&,
142 template<
typename _Iterator,
typename _Sequence,
typename _Category,
143 typename _OtherIterator>
149 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
152 template<
typename _Iterator,
typename _Sequence,
typename _Category,
153 typename _OtherIterator,
typename _OtherSequence,
154 typename _OtherCategory>
165 template<
typename _Iterator,
typename _Sequence,
typename _Category,
166 typename _InputIterator>
169 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
170 const _InputIterator& __other,
171 const _InputIterator& __other_end)
173 #if __cplusplus < 201103L 174 typedef _Is_contiguous_sequence<_Sequence> __tag;
177 typename std::iterator_traits<_InputIterator>::reference>;
178 using __contiguous = _Is_contiguous_sequence<_Sequence>;
180 std::__false_type>::type;
182 return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
186 template<
typename _Iterator,
typename _Sequence,
typename _Category,
189 __foreign_iterator_aux(
190 const _Safe_iterator<_Iterator, _Sequence, _Category>&,
191 _Integral, _Integral, std::__true_type)
195 template<
typename _Iterator,
typename _Sequence,
typename _Category,
196 typename _InputIterator>
198 __foreign_iterator_aux(
199 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
200 _InputIterator __other, _InputIterator __other_end,
203 return _Insert_range_from_self_is_safe<_Sequence>::__value
205 std::__miter_base(__other_end));
208 template<
typename _Iterator,
typename _Sequence,
typename _Category,
209 typename _InputIterator>
212 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
213 _InputIterator __other, _InputIterator __other_end)
215 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
216 return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
221 template<
typename _InputIterator>
223 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
229 template<
typename _ForwardIterator>
231 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
234 if (__first == __last)
237 _ForwardIterator __next = __first;
238 for (++__next; __next != __last; __first = __next, (void)++__next)
239 if (*__next < *__first)
247 template<
typename _InputIterator,
typename _Predicate>
249 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
255 template<
typename _ForwardIterator,
typename _Predicate>
257 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
260 if (__first == __last)
263 _ForwardIterator __next = __first;
264 for (++__next; __next != __last; __first = __next, (void)++__next)
265 if (__pred(*__next, *__first))
272 template<
typename _InputIterator>
274 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
278 __glibcxx_assert(__first == __last || !(*__first < *__first));
280 return __check_sorted_aux(__first, __last,
284 template<
typename _InputIterator,
typename _Predicate>
286 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
291 __glibcxx_assert(__first == __last || !__pred(*__first, *__first));
293 return __check_sorted_aux(__first, __last, __pred,
297 template<
typename _InputIterator>
299 __check_sorted_set_aux(
const _InputIterator& __first,
300 const _InputIterator& __last,
302 {
return __check_sorted(__first, __last); }
304 template<
typename _InputIterator>
306 __check_sorted_set_aux(
const _InputIterator&,
307 const _InputIterator&,
311 template<
typename _InputIterator,
typename _Predicate>
313 __check_sorted_set_aux(
const _InputIterator& __first,
314 const _InputIterator& __last,
315 _Predicate __pred, std::__true_type)
316 {
return __check_sorted(__first, __last, __pred); }
318 template<
typename _InputIterator,
typename _Predicate>
320 __check_sorted_set_aux(
const _InputIterator&,
321 const _InputIterator&, _Predicate,
326 template<
typename _InputIterator1,
typename _InputIterator2>
328 __check_sorted_set(
const _InputIterator1& __first,
329 const _InputIterator1& __last,
330 const _InputIterator2&)
332 typedef typename std::iterator_traits<_InputIterator1>::value_type
334 typedef typename std::iterator_traits<_InputIterator2>::value_type
337 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
339 return __check_sorted_set_aux(__first, __last, _SameType());
342 template<
typename _InputIterator1,
typename _InputIterator2,
345 __check_sorted_set(
const _InputIterator1& __first,
346 const _InputIterator1& __last,
347 const _InputIterator2&, _Predicate __pred)
349 typedef typename std::iterator_traits<_InputIterator1>::value_type
351 typedef typename std::iterator_traits<_InputIterator2>::value_type
354 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
356 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
362 template<
typename _ForwardIterator,
typename _Tp>
364 __check_partitioned_lower(_ForwardIterator __first,
365 _ForwardIterator __last,
const _Tp& __value)
367 while (__first != __last && *__first < __value)
369 if (__first != __last)
372 while (__first != __last && !(*__first < __value))
375 return __first == __last;
378 template<
typename _ForwardIterator,
typename _Tp>
380 __check_partitioned_upper(_ForwardIterator __first,
381 _ForwardIterator __last,
const _Tp& __value)
383 while (__first != __last && !(__value < *__first))
385 if (__first != __last)
388 while (__first != __last && __value < *__first)
391 return __first == __last;
395 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
397 __check_partitioned_lower(_ForwardIterator __first,
398 _ForwardIterator __last,
const _Tp& __value,
401 while (__first != __last &&
bool(__pred(*__first, __value)))
403 if (__first != __last)
406 while (__first != __last && !
bool(__pred(*__first, __value)))
409 return __first == __last;
412 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
414 __check_partitioned_upper(_ForwardIterator __first,
415 _ForwardIterator __last,
const _Tp& __value,
418 while (__first != __last && !
bool(__pred(__value, *__first)))
420 if (__first != __last)
423 while (__first != __last &&
bool(__pred(__value, *__first)))
426 return __first == __last;
429 #if __cplusplus >= 201103L 430 struct _Irreflexive_checker
432 template<
typename _It>
433 static typename std::iterator_traits<_It>::reference
436 template<
typename _It,
437 typename = decltype(__deref<_It>() < __deref<_It>())>
439 _S_is_valid(_It __it)
440 {
return !(*__it < *__it); }
443 template<
typename... _Args>
445 _S_is_valid(_Args...)
448 template<
typename _It,
typename _Pred,
typename 449 = decltype(std::declval<_Pred>()(__deref<_It>(), __deref<_It>()))>
451 _S_is_valid_pred(_It __it, _Pred __pred)
452 {
return !__pred(*__it, *__it); }
455 template<
typename... _Args>
457 _S_is_valid_pred(_Args...)
461 template<
typename _Iterator>
463 __is_irreflexive(_Iterator __it)
464 {
return _Irreflexive_checker::_S_is_valid(__it); }
466 template<
typename _Iterator,
typename _Pred>
468 __is_irreflexive_pred(_Iterator __it, _Pred __pred)
469 {
return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }
Forward iterators support a superset of input iterator operations.
constexpr iterator_traits< _Iter >::iterator_category __iterator_category(const _Iter &)
Define a member typedef type to one of two argument types.
bool __foreign_iterator_aux2(const _Safe_iterator< _Iterator, _Sequence, _Category > &__it, const _Safe_iterator< _OtherIterator, _Sequence, _Category > &__other, const _Safe_iterator< _OtherIterator, _Sequence, _Category > &)
GNU debug classes for public use.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
One of the comparison functors.