From: François Dumont Date: Tue, 3 Jul 2018 15:50:12 +0000 (+0000) Subject: stl_algobase.h (__niter_wrap): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=315aadc8642b72fc2d7172312a35e18074cca85b;p=gcc.git stl_algobase.h (__niter_wrap): New. 2018-07-03 François Dumont * include/bits/stl_algobase.h (__niter_wrap): New. (__copy_move_a2(_II, _II, _OI)): Use latter. (__copy_move_backward_a2(_BI1, _BI1, _BI2)): Likewise. (fill_n(_OI, _Size, const _Tp&)): Likewise. (equal(_II1, _II1, _II2)): Use __glibcxx_requires_can_increment. * include/debug/stl_iterator.h (std::__niter_base(const __gnu_cxx::_Safe_iterator< __gnu_cxx::__normal_iterator<>, _Sequence>&)): New declaration. * include/debug/vector (__niter_base(const __gnu_cxx::_Safe_iterator< __gnu_cxx::__normal_iterator<>, _Sequence>&)): New. From-SVN: r262349 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ae734e8487d..838887c1efd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2018-07-03 François Dumont + + * include/bits/stl_algobase.h (__niter_wrap): New. + (__copy_move_a2(_II, _II, _OI)): Use latter. + (__copy_move_backward_a2(_BI1, _BI1, _BI2)): Likewise. + (fill_n(_OI, _Size, const _Tp&)): Likewise. + (equal(_II1, _II1, _II2)): Use __glibcxx_requires_can_increment. + * include/debug/stl_iterator.h + (std::__niter_base(const __gnu_cxx::_Safe_iterator< + __gnu_cxx::__normal_iterator<>, _Sequence>&)): New declaration. + * include/debug/vector (__niter_base(const __gnu_cxx::_Safe_iterator< + __gnu_cxx::__normal_iterator<>, _Sequence>&)): New. + 2018-07-02 Jonathan Wakely P0758R1 Implicit conversion traits diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 022a3f1598b..16a3f83b610 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -277,6 +277,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __niter_base(_Iterator __it) { return __it; } + // Reverse the __niter_base transformation to get a + // __normal_iterator back again (this assumes that __normal_iterator + // is only used to wrap random access iterators, like pointers). + template + inline _From + __niter_wrap(_From __from, _To __res) + { return __from + (__res - std::__niter_base(__from)); } + + // No need to wrap, iterator already has the right type. + template + inline _Iterator + __niter_wrap(_Iterator, _Iterator __res) + { return __res; } + // All of these auxiliary structs serve two purposes. (1) Replace // calls to copy with memmove whenever possible. (Memmove, not memcpy, // because the input and output ranges are permitted to overlap.) @@ -419,9 +433,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline _OI __copy_move_a2(_II __first, _II __last, _OI __result) { - return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first), - std::__niter_base(__last), - std::__niter_base(__result))); + return std::__niter_wrap(__result, + std::__copy_move_a<_IsMove>(std::__niter_base(__first), + std::__niter_base(__last), + std::__niter_base(__result))); } /** @@ -593,7 +608,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline _BI2 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result) { - return _BI2(std::__copy_move_backward_a<_IsMove> + return std::__niter_wrap(__result, + std::__copy_move_backward_a<_IsMove> (std::__niter_base(__first), std::__niter_base(__last), std::__niter_base(__result))); } @@ -785,7 +801,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>) __glibcxx_requires_can_increment(__first, __n); - return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value)); + return std::__niter_wrap(__first, + std::__fill_n_a(std::__niter_base(__first), __n, __value)); } template @@ -1043,7 +1060,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO __glibcxx_function_requires(_EqualOpConcept< typename iterator_traits<_II1>::value_type, typename iterator_traits<_II2>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); + __glibcxx_requires_can_increment_range(__first1, __last1, __first2); return std::__equal_aux(std::__niter_base(__first1), std::__niter_base(__last1), diff --git a/libstdc++-v3/include/debug/stl_iterator.h b/libstdc++-v3/include/debug/stl_iterator.h index a6a2a762766..f20b000e0e5 100644 --- a/libstdc++-v3/include/debug/stl_iterator.h +++ b/libstdc++-v3/include/debug/stl_iterator.h @@ -120,4 +120,17 @@ namespace __gnu_debug #endif } +namespace std +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template + _Iterator + __niter_base(const __gnu_debug::_Safe_iterator< + __gnu_cxx::__normal_iterator<_Iterator, _Container>, + _Sequence>&); + +_GLIBCXX_END_NAMESPACE_VERSION +} + #endif diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 802f4fd6b78..ced5520ae7e 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -785,6 +785,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return std::hash<_GLIBCXX_STD_C::vector>()(__b); } }; + template + _Iterator + __niter_base(const __gnu_debug::_Safe_iterator< + __gnu_cxx::__normal_iterator<_Iterator, _Container>, + _Sequence>& __it) + { return std::__niter_base(__it.base()); } + _GLIBCXX_END_NAMESPACE_VERSION #endif