[Libreoffice] [PUSHED] Re: [PATCH] DECLARE_LIST(TOXControlList, Control*) to std::vector<Control*> in sw.
Kohei Yoshida
kyoshida at novell.com
Fri Feb 18 06:51:12 PST 2011
On Fri, 2011-02-18 at 09:11 +0100, David Tardon wrote:
> On Thu, Feb 17, 2011 at 11:36:27PM +0100, Jan Holesovsky wrote:
> > The main thing that I changed was that in some cases you used
> > vector<...>::iterator it = another_iterator + 1; This is not correct,
> > operator+() is not defined on std::vector, so the result might be not
> > what you'd expect; similarly with -1. I have changed those to ++it, or
> > --it (on a temporary copy, or so).
>
> Hi, Kendy,
>
> sure it is defined, see ISO C++, 24.1.5, table 76: Random access
> iterator requirements. ISO C++, 23.1.1, table 68 even describes
> operational semantics of operator[] for vector and deque by
> *(a.begin() + n) :)
It works as long as the iterator is random access iterator. As soon as
you change the container to, say, list, whose iterator is bi-directional
but not random access that above statement is not guaranteed to work.
(It may work, but not guaranteed.)
It's better (and safer) to use std::advance to advance the iterator
position, or ++ or -- if it's only a change of one position.
Kohei
--
Kohei Yoshida, LibreOffice hacker, Calc
<kyoshida at novell.com>
More information about the LibreOffice
mailing list