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_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_can_compare(__rhs))
225 __dist = std::make_pair(__rhs.base() - this->base(), __dp_exact);
228 return __dist.
first == 0
229 || (__dist.
first > 0 && this->_M_dereferenceable());
233 namespace std _GLIBCXX_VISIBILITY(default)
235 _GLIBCXX_BEGIN_NAMESPACE_VERSION
237 template<
bool _IsMove,
238 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
241 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
242 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
245 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
246 __glibcxx_check_valid_range2(__first, __last, __dist);
247 __glibcxx_check_can_increment_dist(__result, __dist, 1);
249 if (__dist.second > ::__gnu_debug::__dp_equality)
250 return std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
253 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
256 template<
bool _IsMove,
257 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
259 __copy_move_a(_II __first, _II __last,
260 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
262 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
263 __glibcxx_check_valid_range2(__first, __last, __dist);
264 __glibcxx_check_can_increment_dist(__result, __dist, 1);
266 if (__dist.second > ::__gnu_debug::__dp_sign
267 && __result._M_can_advance(__dist.first,
true))
268 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
269 std::__copy_move_a<_IsMove>(__first, __last, __result.base()),
270 __result._M_sequence);
272 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
275 template<
bool _IsMove,
276 typename _IIte,
typename _ISeq,
typename _ICat,
277 typename _OIte,
typename _OSeq,
typename _OCat>
280 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
281 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
282 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
284 typename ::__gnu_debug::_Distance_traits<_IIte>::__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_equality)
290 if (__dist.second > ::__gnu_debug::__dp_sign
291 && __result._M_can_advance(__dist.first,
true))
292 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
293 std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
295 __result._M_sequence);
297 return std::__copy_move_a<_IsMove>(__first.base(), __last.base(),
301 return std::__copy_move_a1<_IsMove>(__first, __last, __result);
304 template<
bool _IsMove,
305 typename _Ite,
typename _Seq,
typename _Cat,
typename _OI>
307 __copy_move_backward_a(
308 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
309 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
312 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
313 __glibcxx_check_valid_range2(__first, __last, __dist);
314 __glibcxx_check_can_increment_dist(__result, __dist, -1);
316 if (__dist.second > ::__gnu_debug::__dp_equality)
317 return std::__copy_move_backward_a<_IsMove>(
318 __first.base(), __last.base(), __result);
320 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
323 template<
bool _IsMove,
324 typename _II,
typename _Ite,
typename _Seq,
typename _Cat>
326 __copy_move_backward_a(_II __first, _II __last,
327 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __result)
329 typename ::__gnu_debug::_Distance_traits<_II>::__type __dist;
330 __glibcxx_check_valid_range2(__first, __last, __dist);
331 __glibcxx_check_can_increment_dist(__result, __dist, -1);
333 if (__dist.second > ::__gnu_debug::__dp_sign
334 && __result._M_can_advance(-__dist.first,
true))
335 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
336 std::__copy_move_backward_a<_IsMove>(__first, __last,
338 __result._M_sequence);
340 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
343 template<
bool _IsMove,
344 typename _IIte,
typename _ISeq,
typename _ICat,
345 typename _OIte,
typename _OSeq,
typename _OCat>
347 __copy_move_backward_a(
348 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __first,
349 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>& __last,
350 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>& __result)
352 typename ::__gnu_debug::_Distance_traits<_IIte>::__type __dist;
353 __glibcxx_check_valid_range2(__first, __last, __dist);
354 __glibcxx_check_can_increment_dist(__result, __dist, -1);
356 if (__dist.second > ::__gnu_debug::__dp_equality)
358 if (__dist.second > ::__gnu_debug::__dp_sign
359 && __result._M_can_advance(-__dist.first,
true))
360 return ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>(
361 std::__copy_move_backward_a<_IsMove>(__first.base(), __last.base(),
363 __result._M_sequence);
365 return std::__copy_move_backward_a<_IsMove>(
366 __first.base(), __last.base(), __result);
369 return std::__copy_move_backward_a1<_IsMove>(__first, __last, __result);
372 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Tp>
374 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
375 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __last,
378 typename ::__gnu_debug::_Distance_traits<_Ite>::__type __dist;
379 __glibcxx_check_valid_range2(__first, __last, __dist);
381 if (__dist.second > ::__gnu_debug::__dp_equality)
382 std::__fill_a(__first.base(), __last.base(), __value);
384 std::__fill_a1(__first, __last, __value);
387 template<
typename _Ite,
typename _Seq,
typename _Cat,
typename _Size,
390 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
391 _Size __n,
const _Tp& __value,
394 #if __cplusplus >= 201103L
395 static_assert(is_integral<_Size>{},
"fill_n must pass integral size");
401 __glibcxx_check_can_increment(__first, __n);
402 if (__first._M_can_advance(__n,
true))
403 return ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>(
404 std::__fill_n_a(__first.base(), __n, __value, _Cat()),
405 __first._M_sequence);
407 return std::__fill_n_a1(__first, __n, __value);
410 template<
typename _II1,
typename _Seq1,
typename _Cat1,
typename _II2>
413 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
414 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
417 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
418 __glibcxx_check_valid_range2(__first1, __last1, __dist);
419 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
421 if (__dist.second > ::__gnu_debug::__dp_equality)
422 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
424 return std::__equal_aux1(__first1, __last1, __first2);
427 template<
typename _II1,
typename _II2,
typename _Seq2,
typename _Cat2>
429 __equal_aux(_II1 __first1, _II1 __last1,
430 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
432 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
433 __glibcxx_check_valid_range2(__first1, __last1, __dist);
434 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
436 if (__dist.second > ::__gnu_debug::__dp_sign
437 && __first2._M_can_advance(__dist.first,
true))
438 return std::__equal_aux(__first1, __last1, __first2.base());
440 return std::__equal_aux1(__first1, __last1, __first2);
443 template<
typename _II1,
typename _Seq1,
typename _Cat1,
444 typename _II2,
typename _Seq2,
typename _Cat2>
447 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __first1,
448 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>& __last1,
449 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>& __first2)
451 typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist;
452 __glibcxx_check_valid_range2(__first1, __last1, __dist);
453 __glibcxx_check_can_increment_dist(__first2, __dist, 1);
455 if (__dist.second > ::__gnu_debug::__dp_equality)
457 if (__dist.second > ::__gnu_debug::__dp_sign &&
458 __first2._M_can_advance(__dist.first,
true))
459 return std::__equal_aux(__first1.base(), __last1.base(),
461 return std::__equal_aux(__first1.base(), __last1.base(), __first2);
464 return __equal_aux1(__first1, __last1, __first2);
467 _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.