29 #ifndef _GLIBCXX_DEBUG_FUNCTIONS_H
30 #define _GLIBCXX_DEBUG_FUNCTIONS_H 1
34 #if __cplusplus >= 201103L
44 template<
typename _Sequence>
45 struct _Insert_range_from_self_is_safe
46 {
enum { __value = 0 }; };
48 template<
typename _Sequence>
49 struct _Is_contiguous_sequence : std::__false_type { };
55 template<
typename _InputIterator>
56 _GLIBCXX20_CONSTEXPR
inline _InputIterator
57 __check_valid_range(
const _InputIterator& __first,
58 const _InputIterator& __last,
61 const char* __function)
63 if (!std::__is_constant_evaluated())
65 __glibcxx_check_valid_range_at(__first, __last,
66 __file, __line, __function);
73 template<
typename _Iterator,
typename _Sequence,
typename _Category>
75 __foreign_iterator_aux4(
76 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
77 const typename _Sequence::value_type* __other)
79 typedef const typename _Sequence::value_type* _PointerType;
81 #if __cplusplus >= 201103L
82 constexpr _Less __l{};
84 const _Less __l = _Less();
86 const _Sequence* __seq = __it._M_get_sequence();
91 return __l(__other, __begin) || __l(__end, __other);
95 template<
typename _Iterator,
typename _Sequence,
typename _Category>
97 __foreign_iterator_aux4(
98 const _Safe_iterator<_Iterator, _Sequence, _Category>&, ...)
102 template<
typename _Iterator,
typename _Sequence,
typename _Category,
103 typename _InputIterator>
105 __foreign_iterator_aux3(
106 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
107 const _InputIterator& __other,
const _InputIterator& __other_end,
110 if (__other == __other_end)
112 if (__it._M_get_sequence()->empty())
118 template<
typename _Iterator,
typename _Sequence,
typename _Category,
119 typename _InputIterator>
121 __foreign_iterator_aux3(
122 const _Safe_iterator<_Iterator, _Sequence, _Category>&,
123 const _InputIterator&,
const _InputIterator&,
128 template<
typename _Iterator,
typename _Sequence,
typename _Category,
129 typename _OtherIterator>
135 {
return __it._M_get_sequence() != __other._M_get_sequence(); }
138 template<
typename _Iterator,
typename _Sequence,
typename _Category,
139 typename _OtherIterator,
typename _OtherSequence,
140 typename _OtherCategory>
151 template<
typename _Iterator,
typename _Sequence,
typename _Category,
152 typename _InputIterator>
155 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
156 const _InputIterator& __other,
157 const _InputIterator& __other_end)
159 #if __cplusplus < 201103L
160 typedef _Is_contiguous_sequence<_Sequence> __tag;
164 using __contiguous = _Is_contiguous_sequence<_Sequence>;
165 using __tag = std::__conditional_t<__lvalref::value, __contiguous,
168 return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
171 #if __cplusplus < 201103L
173 template<
typename _Iterator,
typename _Sequence,
typename _Category,
176 __foreign_iterator_aux(
177 const _Safe_iterator<_Iterator, _Sequence, _Category>&,
178 _Integral, _Integral, std::__true_type)
182 template<
typename _Iterator,
typename _Sequence,
typename _Category,
183 typename _InputIterator>
185 __foreign_iterator_aux(
186 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
187 _InputIterator __other, _InputIterator __other_end,
190 template<
typename _Iterator,
typename _Sequence,
typename _Category,
191 typename _InputIterator>
194 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
195 _InputIterator __other, _InputIterator __other_end)
198 return _Insert_range_from_self_is_safe<_Sequence>::__value
200 std::__miter_base(__other_end));
203 #if __cplusplus < 201103L
204 template<
typename _Iterator,
typename _Sequence,
typename _Category,
205 typename _InputIterator>
208 const _Safe_iterator<_Iterator, _Sequence, _Category>& __it,
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());
218 template<
typename _InputIterator>
221 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
227 template<
typename _ForwardIterator>
230 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
233 if (__first == __last)
236 _ForwardIterator __next = __first;
237 for (++__next; __next != __last; __first = __next, (void)++__next)
238 if (*__next < *__first)
246 template<
typename _InputIterator,
typename _Predicate>
249 __check_sorted_aux(
const _InputIterator&,
const _InputIterator&,
255 template<
typename _ForwardIterator,
typename _Predicate>
258 __check_sorted_aux(_ForwardIterator __first, _ForwardIterator __last,
261 if (__first == __last)
264 _ForwardIterator __next = __first;
265 for (++__next; __next != __last; __first = __next, (void)++__next)
266 if (__pred(*__next, *__first))
273 template<
typename _InputIterator>
276 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last)
278 return __check_sorted_aux(__first, __last,
282 template<
typename _InputIterator,
typename _Predicate>
285 __check_sorted(
const _InputIterator& __first,
const _InputIterator& __last,
288 return __check_sorted_aux(__first, __last, __pred,
292 template<
typename _InputIterator>
295 __check_sorted_set_aux(
const _InputIterator& __first,
296 const _InputIterator& __last,
298 {
return __check_sorted(__first, __last); }
300 template<
typename _InputIterator>
303 __check_sorted_set_aux(
const _InputIterator&,
304 const _InputIterator&,
308 template<
typename _InputIterator,
typename _Predicate>
311 __check_sorted_set_aux(
const _InputIterator& __first,
312 const _InputIterator& __last,
313 _Predicate __pred, std::__true_type)
314 {
return __check_sorted(__first, __last, __pred); }
316 template<
typename _InputIterator,
typename _Predicate>
319 __check_sorted_set_aux(
const _InputIterator&,
320 const _InputIterator&, _Predicate,
325 template<
typename _InputIterator1,
typename _InputIterator2>
328 __check_sorted_set(
const _InputIterator1& __first,
329 const _InputIterator1& __last,
330 const _InputIterator2&)
337 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
339 return __check_sorted_set_aux(__first, __last, _SameType());
342 template<
typename _InputIterator1,
typename _InputIterator2,
346 __check_sorted_set(
const _InputIterator1& __first,
347 const _InputIterator1& __last,
348 const _InputIterator2&, _Predicate __pred)
355 typedef typename std::__are_same<_ValueType1, _ValueType2>::__type
357 return __check_sorted_set_aux(__first, __last, __pred, _SameType());
363 template<
typename _ForwardIterator,
typename _Tp>
366 __check_partitioned_lower(_ForwardIterator __first,
367 _ForwardIterator __last,
const _Tp& __value)
369 while (__first != __last && *__first < __value)
371 if (__first != __last)
374 while (__first != __last && !(*__first < __value))
377 return __first == __last;
380 template<
typename _ForwardIterator,
typename _Tp>
383 __check_partitioned_upper(_ForwardIterator __first,
384 _ForwardIterator __last,
const _Tp& __value)
386 while (__first != __last && !(__value < *__first))
388 if (__first != __last)
391 while (__first != __last && __value < *__first)
394 return __first == __last;
398 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
401 __check_partitioned_lower(_ForwardIterator __first,
402 _ForwardIterator __last,
const _Tp& __value,
405 while (__first != __last &&
bool(__pred(*__first, __value)))
407 if (__first != __last)
410 while (__first != __last && !
bool(__pred(*__first, __value)))
413 return __first == __last;
416 template<
typename _ForwardIterator,
typename _Tp,
typename _Pred>
419 __check_partitioned_upper(_ForwardIterator __first,
420 _ForwardIterator __last,
const _Tp& __value,
423 while (__first != __last && !
bool(__pred(__value, *__first)))
425 if (__first != __last)
428 while (__first != __last &&
bool(__pred(__value, *__first)))
431 return __first == __last;
434 #if __cplusplus >= 201103L
435 struct _Irreflexive_checker
437 template<
typename _It>
441 template<
typename _It,
442 typename = decltype(__ref<_It>() < __ref<_It>())>
445 _S_is_valid(_It __it)
446 {
return !(*__it < *__it); }
449 template<
typename... _Args>
452 _S_is_valid(_Args...)
455 template<
typename _It,
typename _Pred,
typename
456 = decltype(std::declval<_Pred>()(__ref<_It>(), __ref<_It>()))>
459 _S_is_valid_pred(_It __it, _Pred __pred)
460 {
return !__pred(*__it, *__it); }
463 template<
typename... _Args>
466 _S_is_valid_pred(_Args...)
470 template<
typename _Iterator>
473 __is_irreflexive(_Iterator __it)
474 {
return _Irreflexive_checker::_S_is_valid(__it); }
476 template<
typename _Iterator,
typename _Pred>
479 __is_irreflexive_pred(_Iterator __it, _Pred __pred)
480 {
return _Irreflexive_checker::_S_is_valid_pred(__it, __pred); }