Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-10-12 13:31:12


>From: "Daniel Frey" <d.frey_at_[hidden]>

>On Sat, 12 Oct 2002 14:26:04 +0200, Terje Slettebø wrote:

>> - The posting with the patch
>> (http://lists.boost.org/MailArchives/boost/msg31458.php) says "See also
>> Scott Meyers "More Efficient C++", Item 4.7.". There's no Item 4.7, and
>> Item 4 doesn't seem to apply, so I wonder what is referred to, here?

>Maybe it's another item number in the english book, I only had the german
>translation at hand.

I still don't know which Item you referred to. What's its name?

>I think it's in the patch in the files-section, isn't it? 'const T' is
>IMHO the type that should be returned. If the patch returns 'T', it's an
>error. Please note that the only current version is the patch, not any
>code I attached to a posting.

It seems there may be valid reasons for operating on non-const temps,
though, as Howard and Andrei mentioned.

>> 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.
>It would be different, if you have a function like this:

>friend T operator+( const T& lhs, const T& rhs ) {
> return T(lhs);
>}

I understand this now.

Regards,

Terje


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