Boost logo

Boost :

From: Mattias Flodin (flodin_at_[hidden])
Date: 2002-10-12 16:37:14


On Sat, Oct 12, 2002 at 09:56:32AM -0700, Andrei Alexandrescu wrote:
> I recently reached the conclusion that taking a parameter by const reference
> just to make a copy of it inside the function is a "lie". The signature
> says: "I don't need a value! A reference to a const is all I need!" and the
> code says: "The first line of this function makes a copy!" There will be a
> section in my upcoming article entitled "The Lying const". Taking const& T
> as arguments in /any/ function when you actually *do* need a copy chokes the
> compiler (and Zuto) and practically forbids them to make important
> optimizations.

Why would I want to communicate information about what my implementation
does in the function interface? I don't see why putting const there
would be a lie; more like information hiding, which is usually
considered a good thing.

But, certainly, from an optimization point of view, it has problems.
Abstraction and optimization were never good friends.

-- 
Mattias Flodin <flodin_at_[hidden]>  -  http://www.cs.umu.se/~flodin/
Room NADV 102
Department of Computing Science
Umeå University
S-901 87 Umeå, Sweden
--
"One morning I shot an elephant in my pyjamas. How he got into my pyjamas
I'll never know." -- Groucho Marx

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