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_singular())
98 _M_get_distance_from_begin();
99 return __dist.
second == __dp_exact
100 ? __dist.
first >= -__n
101 : !__strict && __dist.
first > 0;
106 _M_get_distance_to_end();
107 return __dist.
second == __dp_exact
108 ? __dist.
first >= __n
109 : !__strict && __dist.
first > 0;
113 template<
typename _Iterator,
typename _Sequence,
typename _Category>
114 typename _Distance_traits<_Iterator>::__type
115 _Safe_iterator<_Iterator, _Sequence, _Category>::
116 _M_get_distance_to(
const _Safe_iterator& __rhs)
const
118 typedef typename _Distance_traits<_Iterator>::__type _Dist;
119 typedef _Sequence_traits<_Sequence> _SeqTraits;
122 if (__base_dist.second == __dp_exact)
125 _Dist __seq_dist = _SeqTraits::_S_size(*this->_M_get_sequence());
126 if (this->_M_is_before_begin())
128 if (__rhs._M_is_begin())
129 return std::make_pair(1, __dp_exact);
131 return __seq_dist.second == __dp_exact
132 ? std::make_pair(__seq_dist.first + 1, __dp_exact)
136 if (this->_M_is_begin())
138 if (__rhs._M_is_before_begin())
139 return std::make_pair(-1, __dp_exact);
141 if (__rhs._M_is_end())
144 return std::make_pair(__seq_dist.first,
145 __seq_dist.second == __dp_exact
146 ? __dp_sign_max_size : __seq_dist.second);
149 if (this->_M_is_end())
151 if (__rhs._M_is_before_begin())
152 return __seq_dist.second == __dp_exact
153 ? std::make_pair(-__seq_dist.first - 1, __dp_exact)
154 :
std::make_pair(-__seq_dist.first, __dp_sign);
156 if (__rhs._M_is_begin())
157 return std::make_pair(-__seq_dist.first, __seq_dist.second);
159 return std::make_pair(-__seq_dist.first,
160 __seq_dist.second == __dp_exact
161 ? __dp_sign_max_size : __seq_dist.second);
164 if (__rhs._M_is_before_begin())
165 return __seq_dist.second == __dp_exact
166 ? std::make_pair(__seq_dist.first - 1, __dp_exact)
167 :
std::make_pair(-__seq_dist.first, __dp_sign);
169 if (__rhs._M_is_begin())
170 return std::make_pair(-__seq_dist.first,
171 __seq_dist.second == __dp_exact
172 ? __dp_sign_max_size : __seq_dist.second);
174 if (__rhs._M_is_end())
175 return std::make_pair(__seq_dist.first,
176 __seq_dist.second == __dp_exact
177 ? __dp_sign_max_size : __seq_dist.second);
179 return std::make_pair(1, __dp_equality);
182 template<
typename _Iterator,
typename _Sequence,
typename _Category>
184 _Safe_iterator<_Iterator, _Sequence, _Category>::
185 _M_valid_range(
const _Safe_iterator& __rhs,
187 bool __check_dereferenceable)
const
189 if (_M_singular() || __rhs._M_singular() || !_M_can_compare(__rhs))
193 __dist = _M_get_distance_to(__rhs);
197 if (__dist.
first == 0)
204 if (__dist.
first > 0)
205 return !__check_dereferenceable || _M_dereferenceable();
206 return __dist.
first == 0;
213 template<
typename _Iterator,
typename _Sequence>
215 _Safe_iterator<_Iterator, _Sequence, std::random_access_iterator_tag>::
216 _M_valid_range(
const _Safe_iterator& __rhs,
220 if (this->_M_singular() || __rhs._M_singular()
221 || !this->_M_can_compare(__rhs))
225 __dist = std::make_pair(__rhs.base() - this->base(), __dp_exact);
228 if (__dist.
first > 0)
229 return this->_M_dereferenceable();
230 return __dist.
first == 0;
234 namespace std _GLIBCXX_VISIBILITY(default)
236 _GLIBCXX_BEGIN_NAMESPACE_VERSION
238 template<
typename _Ite,
typename _Seq>
240 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
242 {
return __it.base(); }
244 template<
bool _IsMove,
245 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
248 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
249 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
252 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
253 __glibcxx_check_valid_range2(__first, __last, __dist);
254 __glibcxx_check_can_increment(__result, __dist.first);
256 if (__dist.second > ::__gnu_debug::__dp_equality)
257 return std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
260 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
263 template<
bool _IsMove,
264 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
266 __copy_move_a(_II __first, _II __last,
267 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
269 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
270 __glibcxx_check_valid_range2(__first, __last, __dist);
271 __glibcxx_check_can_increment(__result, __dist.first);
273 if (__dist.second > ::__gnu_debug::__dp_sign
274 && __result._M_can_advance(__dist.first,
true))
275 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
276 std::__copy_move_a<_IsMove>(__first, __last, __result.base()),
277 __result._M_sequence);
279 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
282 template<
bool _IsMove,
283 typename _IIte,
typename _ISeq,
typename _ICat,
284 typename _OIte,
typename _OSeq,
typename _OCat>
287 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
288 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
289 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
291 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
292 __glibcxx_check_valid_range2(__first, __last, __dist);
293 __glibcxx_check_can_increment(__result, __dist.first);
295 if (__dist.second > ::__gnu_debug::__dp_equality)
297 if (__dist.second > ::__gnu_debug::__dp_sign
298 && __result._M_can_advance(__dist.first,
true))
299 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
300 std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
302 __result._M_sequence);
304 return std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
308 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
311 template<
bool _IsMove,
312 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
314 __copy_move_backward_a(
315 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
316 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
319 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
320 __glibcxx_check_valid_range2(__first, __last, __dist);
321 __glibcxx_check_can_increment(__result, -__dist.first);
323 if (__dist.second > ::__gnu_debug::__dp_equality)
324 return std::__copy_move_backward_a<_IsMove>(
325 __first.base(), __last.base(), __result);
327 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
330 template<
bool _IsMove,
331 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
333 __copy_move_backward_a(_II __first, _II __last,
334 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
336 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
337 __glibcxx_check_valid_range2(__first, __last, __dist);
338 __glibcxx_check_can_increment(__result, -__dist.first);
340 if (__dist.second > ::__gnu_debug::__dp_sign
341 && __result._M_can_advance(-__dist.first,
true))
342 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
343 std::__copy_move_backward_a<_IsMove>(__first, __last,
345 __result._M_sequence);
347 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
350 template<
bool _IsMove,
351 typename _IIte,
typename _ISeq,
typename _ICat,
352 typename _OIte,
typename _OSeq,
typename _OCat>
354 __copy_move_backward_a(
355 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
356 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
357 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
359 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
360 __glibcxx_check_valid_range2(__first, __last, __dist);
361 __glibcxx_check_can_increment(__result, -__dist.first);
363 if (__dist.second > ::__gnu_debug::__dp_equality)
365 if (__dist.second > ::__gnu_debug::__dp_sign
366 && __result._M_can_advance(-__dist.first,
true))
367 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
368 std::__copy_move_backward_a<_IsMove>(__first.base(), __last.base(),
370 __result._M_sequence);
372 return std::__copy_move_backward_a<_IsMove>(
373 __first.base(), __last.base(), __result);
376 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
379 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
381 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
382 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
385 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
386 __glibcxx_check_valid_range2(__first, __last, __dist);
388 if (__dist.second > ::__gnu_debug::__dp_equality)
389 std::__fill_a(__first.base(), __last.base(), __value);
391 std::__fill_a1(__first, __last, __value);
394 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
397 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
398 _Size __n,
const _Tp& __value,
401 #if __cplusplus >= 201103L
402 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
408 __glibcxx_check_can_increment(__first, __n);
409 if (__first._M_can_advance(__n,
true))
410 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
411 std::__fill_n_a(__first.base(), __n, __value, _Cat()),
412 __first._M_sequence);
414 return std::__fill_n_a1(__first, __n, __value);
417 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
420 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
421 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
424 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
425 __glibcxx_check_valid_range2(__first1, __last1, __dist);
426 __glibcxx_check_can_increment(__first2, __dist.first);
428 if (__dist.second > ::__gnu_debug::__dp_equality)
429 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
431 return std::__equal_aux1(__first1, __last1, __first2);
434 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
436 __equal_aux(_II1 __first1, _II1 __last1,
437 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
439 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
440 __glibcxx_check_valid_range2(__first1, __last1, __dist);
441 __glibcxx_check_can_increment(__first2, __dist.first);
443 if (__dist.second > ::__gnu_debug::__dp_sign
444 && __first2._M_can_advance(__dist.first,
true))
445 return std::__equal_aux(__first1, __last1, __first2.base());
447 return std::__equal_aux1(__first1, __last1, __first2);
450 template<
typename _II1,
typename _Seq1,
typename _Cat1,
451 typename _II2,
typename _Seq2,
typename _Cat2>
454 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
455 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
456 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
458 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
459 __glibcxx_check_valid_range2(__first1, __last1, __dist);
460 __glibcxx_check_can_increment(__first2, __dist.first);
462 if (__dist.second > ::__gnu_debug::__dp_equality)
464 if (__dist.second > ::__gnu_debug::__dp_sign &&
465 __first2._M_can_advance(__dist.first,
true))
466 return std::__equal_aux(__first1.base(), __last1.base(),
468 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
471 return __equal_aux1(__first1, __last1, __first2);
474 template<
typename _Ite1,
typename _Seq1,
typename _Cat1,
477 __lexicographical_compare_aux(
478 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
479 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
480 _II2 __first2, _II2 __last2)
482 typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
483 __glibcxx_check_valid_range2(__first1, __last1, __dist1);
484 __glibcxx_check_valid_range(__first2, __last2);
486 if (__dist1.second > ::__gnu_debug::__dp_equality)
487 return std::__lexicographical_compare_aux(__first1.base(),
490 return std::__lexicographical_compare_aux1(__first1, __last1,
494 template<
typename _II1,
495 typename _Ite2,
typename _Seq2,
typename _Cat2>
497 __lexicographical_compare_aux(
498 _II1 __first1, _II1 __last1,
499 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
500 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
502 __glibcxx_check_valid_range(__first1, __last1);
503 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist2;
504 __glibcxx_check_valid_range2(__first2, __last2, __dist2);
506 if (__dist2.second > ::__gnu_debug::__dp_equality)
507 return std::__lexicographical_compare_aux(__first1, __last1,
510 return std::__lexicographical_compare_aux1(__first1, __last1,
514 template<
typename _Ite1,
typename _Seq1,
typename _Cat1,
515 typename _Ite2,
typename _Seq2,
typename _Cat2>
517 __lexicographical_compare_aux(
518 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
519 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
520 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
521 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
523 typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
524 __glibcxx_check_valid_range2(__first1, __last1, __dist1);
525 typename ::__gnu_debug::_Distance_traits<_Ite2>::__type __dist2;
526 __glibcxx_check_valid_range2(__first2, __last2, __dist2);
528 if (__dist1.second > ::__gnu_debug::__dp_equality)
530 if (__dist2.second > ::__gnu_debug::__dp_equality)
531 return std::__lexicographical_compare_aux(__first1.base(),
535 return std::__lexicographical_compare_aux(__first1.base(),
540 if (__dist2.second > ::__gnu_debug::__dp_equality)
541 return std::__lexicographical_compare_aux(__first1, __last1,
544 return std::__lexicographical_compare_aux1(__first1, __last1,
548 _GLIBCXX_END_NAMESPACE_VERSION
_T1 first
The first member.
_T2 second
The second member.
_Tp * begin(valarray< _Tp > &__va)
Return an iterator pointing to the first element of the valarray.
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
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)
Random-access iterators support a superset of bidirectional iterator operations.
Struct holding two objects of arbitrary type.