29#ifndef _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC
30#define _GLIBCXX_DEBUG_SAFE_ITERATOR_TCC 1
36 template<
typename _Iterator,
typename _Sequence,
typename _Category>
37 typename _Distance_traits<_Iterator>::__type
38 _Safe_iterator<_Iterator, _Sequence, _Category>::
39 _M_get_distance_from_begin()
const
41 typedef _Sequence_traits<_Sequence> _SeqTraits;
46 return std::make_pair(0, __dp_exact);
49 return _SeqTraits::_S_size(*_M_get_sequence());
51 typename _Distance_traits<_Iterator>::__type __res
54 if (__res.second == __dp_equality)
55 return std::make_pair(1, __dp_sign);
60 template<
typename _Iterator,
typename _Sequence,
typename _Category>
61 typename _Distance_traits<_Iterator>::__type
62 _Safe_iterator<_Iterator, _Sequence, _Category>::
63 _M_get_distance_to_end()
const
65 typedef _Sequence_traits<_Sequence> _SeqTraits;
70 return _SeqTraits::_S_size(*_M_get_sequence());
73 return std::make_pair(0, __dp_exact);
75 typename _Distance_traits<_Iterator>::__type __res
78 if (__res.second == __dp_equality)
79 return std::make_pair(1, __dp_sign);
84 template<
typename _Iterator,
typename _Sequence,
typename _Category>
86 _Safe_iterator<_Iterator, _Sequence, _Category>::
87 _M_can_advance(difference_type __n,
bool __strict)
const
89 if (this->_M_value_initialized() && __n == 0)
92 if (this->_M_singular())
99 ? _M_get_distance_from_begin()
100 : _M_get_distance_to_end();
105 return __dist.second > __dp_sign
106 ? __dist.first >= __n
107 : !__strict && __dist.first > 0;
110 template<
typename _Iterator,
typename _Sequence,
typename _Category>
111 template<
typename _Diff>
113 _Safe_iterator<_Iterator, _Sequence, _Category>::
117 return __dist.second == __dp_exact
118 ? _M_can_advance(__way * __dist.first)
119 : _M_can_advance(__way * (__dist.first == 0
121 : __dist.first < 0 ? -1 : 1));
124 template<
typename _Iterator,
typename _Sequence,
typename _Category>
125 typename _Distance_traits<_Iterator>::__type
126 _Safe_iterator<_Iterator, _Sequence, _Category>::
127 _M_get_distance_to(
const _Safe_iterator& __rhs)
const
129 typedef typename _Distance_traits<_Iterator>::__type _Dist;
130 typedef _Sequence_traits<_Sequence> _SeqTraits;
133 if (__base_dist.second == __dp_exact)
136 _Dist __seq_dist = _SeqTraits::_S_size(*this->_M_get_sequence());
137 if (this->_M_is_before_begin())
139 if (__rhs._M_is_begin())
140 return std::make_pair(1, __dp_exact);
142 return __seq_dist.second == __dp_exact
143 ? std::make_pair(__seq_dist.first + 1, __dp_exact)
147 if (this->_M_is_begin())
149 if (__rhs._M_is_before_begin())
150 return std::make_pair(-1, __dp_exact);
152 if (__rhs._M_is_end())
155 return std::make_pair(__seq_dist.first,
156 __seq_dist.second == __dp_exact
157 ? __dp_sign_max_size : __seq_dist.second);
160 if (this->_M_is_end())
162 if (__rhs._M_is_before_begin())
163 return __seq_dist.second == __dp_exact
164 ? std::make_pair(-__seq_dist.first - 1, __dp_exact)
165 :
std::make_pair(-__seq_dist.first, __dp_sign);
167 if (__rhs._M_is_begin())
168 return std::make_pair(-__seq_dist.first, __seq_dist.second);
170 return std::make_pair(-__seq_dist.first,
171 __seq_dist.second == __dp_exact
172 ? __dp_sign_max_size : __seq_dist.second);
175 if (__rhs._M_is_before_begin())
176 return __seq_dist.second == __dp_exact
177 ? std::make_pair(__seq_dist.first - 1, __dp_exact)
178 :
std::make_pair(-__seq_dist.first, __dp_sign);
180 if (__rhs._M_is_begin())
181 return std::make_pair(-__seq_dist.first,
182 __seq_dist.second == __dp_exact
183 ? __dp_sign_max_size : __seq_dist.second);
185 if (__rhs._M_is_end())
186 return std::make_pair(__seq_dist.first,
187 __seq_dist.second == __dp_exact
188 ? __dp_sign_max_size : __seq_dist.second);
190 return std::make_pair(1, __dp_equality);
193 template<
typename _Iterator,
typename _Sequence,
typename _Category>
195 _Safe_iterator<_Iterator, _Sequence, _Category>::
196 _M_valid_range(
const _Safe_iterator& __rhs,
198 bool __check_dereferenceable)
const
200 if (_M_value_initialized() && __rhs._M_value_initialized())
202 __dist = std::make_pair(0, __dp_exact);
206 if (_M_singular() || __rhs._M_singular() || !_M_can_compare(__rhs))
210 __dist = _M_get_distance_to(__rhs);
211 if (__dist.second != __dp_equality)
214 return __dist.first == 0
216 && (!__check_dereferenceable || _M_dereferenceable()));
223 template<
typename _Iterator,
typename _Sequence>
225 _Safe_iterator<_Iterator, _Sequence, std::random_access_iterator_tag>::
226 _M_valid_range(
const _Safe_iterator& __rhs,
230 if (this->_M_value_initialized() && __rhs._M_value_initialized())
232 __dist = std::make_pair(0, __dp_exact);
236 if (this->_M_singular() || __rhs._M_singular()
237 || !this->_M_can_compare(__rhs))
241 __dist = std::make_pair(__rhs.base() - this->base(), __dp_exact);
244 return __dist.first == 0
245 || (__dist.first > 0 && this->_M_dereferenceable());
249namespace std _GLIBCXX_VISIBILITY(default)
251_GLIBCXX_BEGIN_NAMESPACE_VERSION
253 template<
typename _Ite,
typename _Seq>
255 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
257 {
return __it.base(); }
259 template<
bool _IsMove,
260 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
263 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
264 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
267 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
268 __glibcxx_check_valid_range2(__first, __last, __dist);
269 __glibcxx_check_can_increment_dist(__result, __dist, 1);
271 if (__dist.second > ::__gnu_debug::__dp_equality)
278 template<
bool _IsMove,
279 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
281 __copy_move_a(_II __first, _II __last,
282 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
284 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
285 __glibcxx_check_valid_range2(__first, __last, __dist);
286 __glibcxx_check_can_increment_dist(__result, __dist, 1);
288 if (__dist.second > ::__gnu_debug::__dp_sign
289 && __result._M_can_advance(__dist.first,
true))
290 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
292 __result._M_sequence);
297 template<
bool _IsMove,
298 typename _IIte,
typename _ISeq,
typename _ICat,
299 typename _OIte,
typename _OSeq,
typename _OCat>
302 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
303 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
304 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
306 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
307 __glibcxx_check_valid_range2(__first, __last, __dist);
308 __glibcxx_check_can_increment_dist(__result, __dist, 1);
310 if (__dist.second > ::__gnu_debug::__dp_equality)
312 if (__dist.second > ::__gnu_debug::__dp_sign
313 && __result._M_can_advance(__dist.first,
true))
314 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
317 __result._M_sequence);
326 template<
bool _IsMove,
327 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
329 __copy_move_backward_a(
330 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
331 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
334 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
335 __glibcxx_check_valid_range2(__first, __last, __dist);
336 __glibcxx_check_can_increment_dist(__result, __dist, -1);
338 if (__dist.second > ::__gnu_debug::__dp_equality)
340 __first.base(), __last.base(), __result);
345 template<
bool _IsMove,
346 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
348 __copy_move_backward_a(_II __first, _II __last,
349 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
351 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
352 __glibcxx_check_valid_range2(__first, __last, __dist);
353 __glibcxx_check_can_increment_dist(__result, __dist, -1);
355 if (__dist.second > ::__gnu_debug::__dp_sign
356 && __result._M_can_advance(-__dist.first,
true))
357 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
360 __result._M_sequence);
365 template<
bool _IsMove,
366 typename _IIte,
typename _ISeq,
typename _ICat,
367 typename _OIte,
typename _OSeq,
typename _OCat>
369 __copy_move_backward_a(
370 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
371 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
372 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
374 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
375 __glibcxx_check_valid_range2(__first, __last, __dist);
376 __glibcxx_check_can_increment_dist(__result, __dist, -1);
378 if (__dist.second > ::__gnu_debug::__dp_equality)
380 if (__dist.second > ::__gnu_debug::__dp_sign
381 && __result._M_can_advance(-__dist.first,
true))
382 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
385 __result._M_sequence);
388 __first.base(), __last.base(), __result);
394 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
396 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
397 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
400 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
401 __glibcxx_check_valid_range2(__first, __last, __dist);
403 if (__dist.second > ::__gnu_debug::__dp_equality)
404 std::__fill_a(__first.base(), __last.base(), __value);
406 std::__fill_a1(__first, __last, __value);
409 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
412 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
413 _Size __n,
const _Tp& __value,
416#if __cplusplus >= 201103L
417 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
423 __glibcxx_check_can_increment(__first, __n);
424 if (__first._M_can_advance(__n,
true))
425 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
426 std::__fill_n_a(__first.base(), __n, __value, _Cat()),
427 __first._M_sequence);
429 return std::__fill_n_a1(__first, __n, __value);
432 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
435 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
436 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
439 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
440 __glibcxx_check_valid_range2(__first1, __last1, __dist);
441 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
443 if (__dist.second > ::__gnu_debug::__dp_equality)
444 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
446 return std::__equal_aux1(__first1, __last1, __first2);
449 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
451 __equal_aux(_II1 __first1, _II1 __last1,
452 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
454 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
455 __glibcxx_check_valid_range2(__first1, __last1, __dist);
456 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
458 if (__dist.second > ::__gnu_debug::__dp_sign
459 && __first2._M_can_advance(__dist.first,
true))
460 return std::__equal_aux(__first1, __last1, __first2.base());
462 return std::__equal_aux1(__first1, __last1, __first2);
465 template<
typename _II1,
typename _Seq1,
typename _Cat1,
466 typename _II2,
typename _Seq2,
typename _Cat2>
469 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
470 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
471 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
473 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
474 __glibcxx_check_valid_range2(__first1, __last1, __dist);
475 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
477 if (__dist.second > ::__gnu_debug::__dp_equality)
479 if (__dist.second > ::__gnu_debug::__dp_sign &&
480 __first2._M_can_advance(__dist.first,
true))
481 return std::__equal_aux(__first1.base(), __last1.base(),
483 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
486 return __equal_aux1(__first1, __last1, __first2);
489 template<
typename _Ite1,
typename _Seq1,
typename _Cat1,
492 __lexicographical_compare_aux(
493 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
494 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
495 _II2 __first2, _II2 __last2)
497 typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
498 __glibcxx_check_valid_range2(__first1, __last1, __dist1);
499 __glibcxx_check_valid_range(__first2, __last2);
501 if (__dist1.second > ::__gnu_debug::__dp_equality)
502 return std::__lexicographical_compare_aux(__first1.base(),
505 return std::__lexicographical_compare_aux1(__first1, __last1,
509 template<
typename _II1,
510 typename _Ite2,
typename _Seq2,
typename _Cat2>
512 __lexicographical_compare_aux(
513 _II1 __first1, _II1 __last1,
514 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
515 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
517 __glibcxx_check_valid_range(__first1, __last1);
518 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist2;
519 __glibcxx_check_valid_range2(__first2, __last2, __dist2);
521 if (__dist2.second > ::__gnu_debug::__dp_equality)
522 return std::__lexicographical_compare_aux(__first1, __last1,
525 return std::__lexicographical_compare_aux1(__first1, __last1,
529 template<
typename _Ite1,
typename _Seq1,
typename _Cat1,
530 typename _Ite2,
typename _Seq2,
typename _Cat2>
532 __lexicographical_compare_aux(
533 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
534 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
535 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
536 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
538 typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
539 __glibcxx_check_valid_range2(__first1, __last1, __dist1);
540 typename ::__gnu_debug::_Distance_traits<_Ite2>::__type __dist2;
541 __glibcxx_check_valid_range2(__first2, __last2, __dist2);
543 if (__dist1.second > ::__gnu_debug::__dp_equality)
545 if (__dist2.second > ::__gnu_debug::__dp_equality)
546 return std::__lexicographical_compare_aux(__first1.base(),
550 return std::__lexicographical_compare_aux(__first1.base(),
555 if (__dist2.second > ::__gnu_debug::__dp_equality)
556 return std::__lexicographical_compare_aux(__first1, __last1,
559 return std::__lexicographical_compare_aux1(__first1, __last1,
563_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
GNU debug classes for public use.
constexpr _Distance_traits< _Iterator >::__type __get_distance(_Iterator __lhs, _Iterator __rhs, std::random_access_iterator_tag)
Struct holding two objects of arbitrary type.
Random-access iterators support a superset of bidirectional iterator operations.