Boost logo

Boost :

From: Joel de Guzman (djowel_at_[hidden])
Date: 2002-07-03 08:09:38

David Abrahams wrote:

>From: "Daniel Frey" <d.frey_at_[hidden]>
>>See also Scott Meyers "More Efficient C++", Item 4.7. If you read the
>>book, you might get the impression I misunderstood it completely, but
>>please read Scott's errata for this item, available at:
>And there it says:
> 7/19/96 sdm 109 In July 1996, the standardization committee
> decided that named objects may be treated
> essentially the same as unnamed objects for
> purposes of performing the return value
> optimization. I added a footnote to this effect.
>Which leads me to believe that there is no "NRVO", just an "RVO".
>Furthermore, I believe that more compilers implement the RVO for unnamed
>objects than for named objects. So why aren't you using this implementation
>friend const T operator+( const T& lhs, const T& rhs )
> return T(lhs) += rhs;

It seems that reading all these, this optimization is *very* compiler
My immediate insight suggests to me that the best approach is a, ummm,
a MACRO (do I hear yuck? :-). Such a macro might be able to switch
the most efficient implementation for a particular compiler based on boost's
config switches. After all, all of us at least agree that we need to
away the return value if possible. I suggest that the OP use his
benchmark and
write such a macro with specific implementations that take into account the
quirks of known compilers.


Boost list run by bdawes at, gregod at, cpdaniel at, john at