Const Ideas

Janice Caron caron800 at googlemail.com
Fri Nov 30 10:10:24 PST 2007


On 11/30/07, Craig Black <cblack at ara.com> wrote:
> Janice proposed an idea
> for constifying instance member functions using const(this).

That actually wasn't me. I like the idea (a lot), but I can't claim
credit for inventing it.

I did come up with the idea of extending it to const(identifier) though.


> If we did this, I would suggest getting rid of the postfix syntax.

I would certainly agree with that!


> const X x;  // The data is const, the reference is mutable

The problem I have with this is that I believe X should mean the same
as (X). So if you accept that, const X x; must mean the same thing as
const(X) x; And if you believe that const(...) has to mean "everything
inside the brackets is const" (which is what I believe) then you have
to conclude that const X x must mean "x is completely and absolutely
const, and nothing about it is mutable". That's actually what it means
right now (so long as you omit the brackets). That's why I argue that
you need something else - something /outside the brackets/ - to mean
"let the reference be mutable". (And obviously, that mechanism should
only be available for reference types).



More information about the Digitalmars-d mailing list