Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-08-23 15:26:31


From: "Andrew Koenig" <ark_at_[hidden]>

> David> I don't think that's the real question at all.
>
> David> The problem is that the return type of operator[] can't be relied
on to be
> David> a reference, and in particular you can't do
>
> David> p[n] = x;
>
> David> with a generic random-access iterator.
>
> David> *(p + n) = x;
>
> David> always works (for sufficiently correct values of n and x).
>
> Interesting -- I wonder why I never noticed that?

I think you did, but forgot.

> One would think that p[n] should be equivalent to *(p+n) -- in particular
> it should be required to have the same type.

That prevents an important class of useful random-access iterators: those
which store the referent of *p inside the iterator itself. Think, e.g.,
about disk-based iterators.

I'm fairly certain that we discussed this in Copenhagen and you played a
significant role in the conversation. Beman brought up some BTree iterators
he wrote which work that way.

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk