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())
96 ? _M_get_distance_from_begin()
97 : _M_get_distance_to_end();
102 return __dist.
second > __dp_sign
103 ? __dist.
first >= __n
104 : !__strict && __dist.
first > 0;
107 template<
typename _Iterator,
typename _Sequence,
typename _Category>
108 template<
typename _Diff>
110 _Safe_iterator<_Iterator, _Sequence, _Category>::
114 return __dist.
second == __dp_exact
115 ? _M_can_advance(__way * __dist.
first)
116 : _M_can_advance(__way * (__dist.first == 0
118 : __dist.first < 0 ? -1 : 1));
121 template<
typename _Iterator,
typename _Sequence,
typename _Category>
122 typename _Distance_traits<_Iterator>::__type
123 _Safe_iterator<_Iterator, _Sequence, _Category>::
124 _M_get_distance_to(
const _Safe_iterator& __rhs)
const
126 typedef typename _Distance_traits<_Iterator>::__type _Dist;
127 typedef _Sequence_traits<_Sequence> _SeqTraits;
130 if (__base_dist.second == __dp_exact)
133 _Dist __seq_dist = _SeqTraits::_S_size(*this->_M_get_sequence());
134 if (this->_M_is_before_begin())
136 if (__rhs._M_is_begin())
137 return std::make_pair(1, __dp_exact);
139 return __seq_dist.second == __dp_exact
140 ? std::make_pair(__seq_dist.first + 1, __dp_exact)
144 if (this->_M_is_begin())
146 if (__rhs._M_is_before_begin())
147 return std::make_pair(-1, __dp_exact);
149 if (__rhs._M_is_end())
152 return std::make_pair(__seq_dist.first,
153 __seq_dist.second == __dp_exact
154 ? __dp_sign_max_size : __seq_dist.second);
157 if (this->_M_is_end())
159 if (__rhs._M_is_before_begin())
160 return __seq_dist.second == __dp_exact
161 ? std::make_pair(-__seq_dist.first - 1, __dp_exact)
162 :
std::make_pair(-__seq_dist.first, __dp_sign);
164 if (__rhs._M_is_begin())
165 return std::make_pair(-__seq_dist.first, __seq_dist.second);
167 return std::make_pair(-__seq_dist.first,
168 __seq_dist.second == __dp_exact
169 ? __dp_sign_max_size : __seq_dist.second);
172 if (__rhs._M_is_before_begin())
173 return __seq_dist.second == __dp_exact
174 ? std::make_pair(__seq_dist.first - 1, __dp_exact)
175 :
std::make_pair(-__seq_dist.first, __dp_sign);
177 if (__rhs._M_is_begin())
178 return std::make_pair(-__seq_dist.first,
179 __seq_dist.second == __dp_exact
180 ? __dp_sign_max_size : __seq_dist.second);
182 if (__rhs._M_is_end())
183 return std::make_pair(__seq_dist.first,
184 __seq_dist.second == __dp_exact
185 ? __dp_sign_max_size : __seq_dist.second);
187 return std::make_pair(1, __dp_equality);
190 template<
typename _Iterator,
typename _Sequence,
typename _Category>
192 _Safe_iterator<_Iterator, _Sequence, _Category>::
193 _M_valid_range(
const _Safe_iterator& __rhs,
195 bool __check_dereferenceable)
const
197 if (_M_singular() || __rhs._M_singular() || !_M_can_compare(__rhs))
201 __dist = _M_get_distance_to(__rhs);
202 if (__dist.
second != __dp_equality)
205 return __dist.
first == 0
207 && (!__check_dereferenceable || _M_dereferenceable()));
214 template<
typename _Iterator,
typename _Sequence>
216 _Safe_iterator<_Iterator, _Sequence, std::random_access_iterator_tag>::
217 _M_valid_range(
const _Safe_iterator& __rhs,
221 if (this->_M_singular() || __rhs._M_singular()
222 || !this->_M_can_compare(__rhs))
226 __dist = std::make_pair(__rhs.base() - this->base(), __dp_exact);
229 return __dist.
first == 0
230 || (__dist.
first > 0 && this->_M_dereferenceable());
234namespace std _GLIBCXX_VISIBILITY(default)
236_GLIBCXX_BEGIN_NAMESPACE_VERSION
238 template<
typename _Ite,
typename _Seq>
241 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
243 {
return __it.base(); }
245 template<
bool _IsMove,
246 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
250 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
251 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
254 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
255 __glibcxx_check_valid_range2(__first, __last, __dist);
256 __glibcxx_check_can_increment_dist(__result, __dist, 1);
258 if (__dist.second > ::__gnu_debug::__dp_equality)
259 return std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
262 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
265 template<
bool _IsMove,
266 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
269 __copy_move_a(_II __first, _II __last,
270 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
272 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
273 __glibcxx_check_valid_range2(__first, __last, __dist);
274 __glibcxx_check_can_increment_dist(__result, __dist, 1);
276 if (__dist.second > ::__gnu_debug::__dp_sign
277 && __result._M_can_advance(__dist.first,
true))
278 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
279 std::__copy_move_a<_IsMove>(__first, __last, __result.base()),
280 __result._M_sequence);
282 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
285 template<
bool _IsMove,
286 typename _IIte,
typename _ISeq,
typename _ICat,
287 typename _OIte,
typename _OSeq,
typename _OCat>
289 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
291 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
292 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
293 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
295 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
296 __glibcxx_check_valid_range2(__first, __last, __dist);
297 __glibcxx_check_can_increment_dist(__result, __dist, 1);
299 if (__dist.second > ::__gnu_debug::__dp_equality)
301 if (__dist.second > ::__gnu_debug::__dp_sign
302 && __result._M_can_advance(__dist.first,
true))
303 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
304 std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
306 __result._M_sequence);
308 return std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
312 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
315 template<
bool _IsMove,
316 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
319 __copy_move_backward_a(
320 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
321 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
324 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
325 __glibcxx_check_valid_range2(__first, __last, __dist);
326 __glibcxx_check_can_increment_dist(__result, __dist, -1);
328 if (__dist.second > ::__gnu_debug::__dp_equality)
329 return std::__copy_move_backward_a<_IsMove>(
330 __first.base(), __last.base(), __result);
332 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
335 template<
bool _IsMove,
336 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
339 __copy_move_backward_a(_II __first, _II __last,
340 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
342 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
343 __glibcxx_check_valid_range2(__first, __last, __dist);
344 __glibcxx_check_can_increment_dist(__result, __dist, -1);
346 if (__dist.second > ::__gnu_debug::__dp_sign
347 && __result._M_can_advance(-__dist.first,
true))
348 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
349 std::__copy_move_backward_a<_IsMove>(__first, __last,
351 __result._M_sequence);
353 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
356 template<
bool _IsMove,
357 typename _IIte,
typename _ISeq,
typename _ICat,
358 typename _OIte,
typename _OSeq,
typename _OCat>
360 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
361 __copy_move_backward_a(
362 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
363 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
364 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
366 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
367 __glibcxx_check_valid_range2(__first, __last, __dist);
368 __glibcxx_check_can_increment_dist(__result, __dist, -1);
370 if (__dist.second > ::__gnu_debug::__dp_equality)
372 if (__dist.second > ::__gnu_debug::__dp_sign
373 && __result._M_can_advance(-__dist.first,
true))
374 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
375 std::__copy_move_backward_a<_IsMove>(__first.base(), __last.base(),
377 __result._M_sequence);
379 return std::__copy_move_backward_a<_IsMove>(
380 __first.base(), __last.base(), __result);
383 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
386 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
389 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
390 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
393 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
394 __glibcxx_check_valid_range2(__first, __last, __dist);
396 if (__dist.second > ::__gnu_debug::__dp_equality)
397 std::__fill_a(__first.base(), __last.base(), __value);
399 std::__fill_a1(__first, __last, __value);
402 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
405 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
406 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
407 _Size __n,
const _Tp& __value,
410#if __cplusplus >= 201103L
411 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
417 __glibcxx_check_can_increment(__first, __n);
418 if (__first._M_can_advance(__n,
true))
419 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
420 std::__fill_n_a(__first.base(), __n, __value, _Cat()),
421 __first._M_sequence);
423 return std::__fill_n_a1(__first, __n, __value);
426 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
430 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
431 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
434 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
435 __glibcxx_check_valid_range2(__first1, __last1, __dist);
436 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
438 if (__dist.second > ::__gnu_debug::__dp_equality)
439 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
441 return std::__equal_aux1(__first1, __last1, __first2);
444 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
447 __equal_aux(_II1 __first1, _II1 __last1,
448 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
450 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
451 __glibcxx_check_valid_range2(__first1, __last1, __dist);
452 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
454 if (__dist.second > ::__gnu_debug::__dp_sign
455 && __first2._M_can_advance(__dist.first,
true))
456 return std::__equal_aux(__first1, __last1, __first2.base());
458 return std::__equal_aux1(__first1, __last1, __first2);
461 template<
typename _II1,
typename _Seq1,
typename _Cat1,
462 typename _II2,
typename _Seq2,
typename _Cat2>
466 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
467 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
468 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
470 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
471 __glibcxx_check_valid_range2(__first1, __last1, __dist);
472 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
474 if (__dist.second > ::__gnu_debug::__dp_equality)
476 if (__dist.second > ::__gnu_debug::__dp_sign &&
477 __first2._M_can_advance(__dist.first,
true))
478 return std::__equal_aux(__first1.base(), __last1.base(),
480 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
483 return __equal_aux1(__first1, __last1, __first2);
486 template<
typename _Ite1,
typename _Seq1,
typename _Cat1,
490 __lexicographical_compare_aux(
491 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
492 const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
493 _II2 __first2, _II2 __last2)
495 typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
496 __glibcxx_check_valid_range2(__first1, __last1, __dist1);
497 __glibcxx_check_valid_range(__first2, __last2);
499 if (__dist1.second > ::__gnu_debug::__dp_equality)
500 return std::__lexicographical_compare_aux(__first1.base(),
503 return std::__lexicographical_compare_aux1(__first1, __last1,
507 template<
typename _II1,
508 typename _Ite2,
typename _Seq2,
typename _Cat2>
511 __lexicographical_compare_aux(
512 _II1 __first1, _II1 __last1,
513 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
514 const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
516 __glibcxx_check_valid_range(__first1, __last1);
517 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist2;
518 __glibcxx_check_valid_range2(__first2, __last2, __dist2);
520 if (__dist2.second > ::__gnu_debug::__dp_equality)
521 return std::__lexicographical_compare_aux(__first1, __last1,
524 return std::__lexicographical_compare_aux1(__first1, __last1,
528 template<
typename _Ite1,
typename _Seq1,
typename _Cat1,
529 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
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first 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)
Struct holding two objects of arbitrary type.
_T1 first
The first member.
_T2 second
The second member.
Random-access iterators support a superset of bidirectional iterator operations.