This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: safe iterator consistency patch
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: François Dumont <francois dot cppdevs at free dot fr>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sat, 11 Dec 2010 12:56:34 +0000
- Subject: Re: safe iterator consistency patch
- References: <4D033F7E.8090504@free.fr>
On 11 December 2010 09:08, François Dumont wrote:
>
> ? ?Here is a patch proposition to make implementation of safe iterator more
> consistent with the underlying iterator one. It do not fix any bug, I just
> consider the implementation more natural if all the safe iterator operators
> are using the same underlying iterator operator.
Hi François,
@@ -294,9 +290,10 @@
_Safe_iterator
operator+(const difference_type& __n) const
{
- _Safe_iterator __tmp(*this);
- __tmp += __n;
- return __tmp;
+ _GLIBCXX_DEBUG_VERIFY(this->_M_can_advance(__n),
+ _M_message(__msg_advance_oob)
+ ._M_iterator(*this)._M_integer(__n));
+ return _Safe_iterator(_M_current + __n, _M_get_sequence());
}
I think this change and the similar one in operator- make the code
more complicated for no benefit. If the check can be done by reusing
the check that occurs in _Safe_iterator's operator+= and operator-=
then we should reuse it and not repeat the code (unless this variant
gives a better diagnostic when the check fails?)
Portable code cannot rely on a particular sequence of iterator
operations anyway (i.e. adding a negative value versus subtracting a
positive one, or operator+= versus operator+ and operator=) so I don't
think this consistency is very important.