Re: Why does vector.end() point beyond last element?

From: Gianni Mariani (gi2nospam_at_mariani.ws)
Date: 06/27/04


Date: 26 Jun 2004 21:36:44 EDT

as mellow as a horse wrote:
> You'll probably guess I'm only just learning this stuff so this might be a
> stupid question. Given:
>
...
> Why does b1.end() point 1 memory location past the 4th element?

Because it does !

Some may argue that it makes the applications easier to write.
i.e.

for ( i = begin(); i != end(); ++i )
{
        .. stuff with i ..
}

it also makes it easy to detect an empty list...

is_empty = begin() == end();

   I was
> getting rubbish until I had a brainwave and tried some fiddly pointer
> arithmetic. Am I missing something?

No.