From: Andrew Koenig (ark_at_[hidden])
Date: 2002-08-25 10:33:09
Peter> The reason for this is that in
Peter> void f(value_type &);
Peter> f(*(p + n));
Peter> the temporary "p + n" is guaranteed to live until the end of
Peter> the full expression, and *(p + n) may return a reference to
Peter> something inside that temporary.
Ah yes, now I remember that discussion from the standards committee
(about a year and a half ago).
And thinking about it some more, I see that the root of the problem
is one very simple fact: If you have an iterator that refers to
a container element, iter[n] is a way of referring to any other
element of that container without ever having an iterator refer
directly to that element. Moreover, it is the only way of doing so,
which makes it a particularly knotty implementation problem
for certain kinds of containers.
-- Andrew Koenig, ark_at_[hidden], http://www.research.att.com/info/ark
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk