Re: Why does vector.end() point beyond last element?
From: Anand Hariharan (desh_bakth_at_yahoo.com)
Date: 06/29/04
- Next message: rossum: "Re: random string"
- Previous message: Prateek R Karandikar: "Re: No use of initializer list"
- In reply to: Arthur J. O'Dwyer: "Re: Why does vector.end() point beyond last element?"
- Next in thread: David White: "Re: Why does vector.end() point beyond last element?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Jun 2004 13:28:30 -0700
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in message news:<Pine.LNX.4.58-035.0406280904410.1567@unix44.andrew.cmu.edu>...
> On Mon, 28 Jun 2004, George Huber wrote:
> >
> > >> Point 2: What would be wrong with replacing "!=" with "<=" ?
> >
> > Actually there is a big difference. With the != you are guaranteed to
> > reach the end, with <= you might not. To see this, pretend that an
> > iterator is a pointer (somewhat of a simplification). Now as items
> > are added to a vector there is no reason to believe that they will
> > be in monotonically increasing memory locations.
>
> Well, actually, for a /vector/ they /will/ be in monotonically
> increasing (in fact, linearly inreasing!) locations. This is not
> true of most (all?) other containers, though (e.g., lists, queues,
> sets).
>
This is w.r.t to the "(all?)" -> It is true for all containers that
support random access iterators. Am not sure about queue, but deque
(double ended queue) supports random access.
- Anand
- Next message: rossum: "Re: random string"
- Previous message: Prateek R Karandikar: "Re: No use of initializer list"
- In reply to: Arthur J. O'Dwyer: "Re: Why does vector.end() point beyond last element?"
- Next in thread: David White: "Re: Why does vector.end() point beyond last element?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]