On 20/02/07, Joseph Artsimovich <joseph@stripped> wrote:
> > So what?
> > The temporary is guaranteed to exist as long as the reference is in scope.
> >
> > See 12.2 paragraph 5 in the C++ standard.
> I don't have access to C++ standard, but a simple test shows you are right.
> Then your solution is obviously better than mine.
>
it's an extremely useful feature.
4 There are two contexts in which temporaries are destroyed at a
different point than the end of the full expression. The first context
is when [...].
5 The second context is when a reference is bound to a temporary. The
temporary to which the reference is bound [...] persists for the
lifetime of the reference [...]
I use it whenever I call a function that returns a class type by value
and I only want const access to the returned value, as it avoids a
copy.
jon