This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: safe iterator consistency patch


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]