Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-10-12 10:05:25


Daniel Frey <d.frey_at_[hidden]> writes:

> > - "More Effective C++", Item 20, "Facilitate the return value
> > optimization" argues for using the constructor in the return statement,
> > rather than creating a named temp. The argument is that although NRVO is
> > also now possible, RVO (unnamed temporary) has been around longer, and
> > may therefore be more widely implemented. Thus, compilers implementing
> > NRVO almost certainly implements RVO, but not necessarily the other way
> > around. Given this, why isn't the following used in operators.hpp:
> >
> > friend T operator+( const T& lhs, const T& rhs ) {
> > return T(lhs)+=rhs;
> > }
>
> Please read Scott's errata. You actually return a T& that was supplied by
> operator+= and therefore, the compiler is not allowed to apply the
> RVO.

OK, good, I understood that! Thanks Daniel.

-- 
           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