Do we really need const?

Bill Baxter dnewsgroup at billbaxter.com
Mon Sep 17 23:32:04 PDT 2007


Walter Bright wrote:
> Christopher Wright wrote:
>> Most of the time, you shouldn't need to write those overloads. Either 
>> the function can be const, in which case you can use it with mutable 
>> data anyway, or it can't, in which case you can't write a const 
>> overload for it. At least in an ideal system.
> 
> The reason that C++ member functions are written twice, const and 
> non-const, are to transmit the const to the return type:
> 
> const T foo(const S);
> T foo(S);
> 
> Nothing more.

There's also the practice of writing all iterators twice.  One tail 
const, one tail mutable.

--bb



More information about the Digitalmars-d mailing list