|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-04-19 09:24:55
"Fredrik Blomqvist" <fredrik_blomqvist_at_[hidden]> writes:
> David Abrahams wrote:
>> Andrea Torsello <torsello_at_[hidden]> writes:
>>
> [snip]
>>> Yes, actually different compilers seem to act differently here.
>>> Since the compiler is free to copy const rvalues to non-const
>>> rvalues and optimize the copy away, I would consider returning a
>>> const temporary an odd thing to do. I am curious: does anyone have a
>>> use-case for it?
>>
>> I doubt it; it doesn't seem like a very important case. It could be
>> used to have some effects on overload resolution I suppose, but it's
>> hard to imagine that being useful in real code.
>>
> Just a comment on the 'const temporary return' issue.
> I'd say it's not really an issue of whether it's useful per se, but how it
> is _actually used_ in real code as a "safety" feature.
> I.e to prevent: (a*b) = c;
> Scott Meyers' Effective C++, item 21, labels this "The Right Thing To Do".
> I've seen similar recommendations in a couple of coding-guidelines and
> several times in real code, most likely inspired by EC++ or similar.
> Thus it will appear in real code if nothing else for a matter of style.
Whoops; good point!
-- Dave Abrahams Boost Consulting 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