const member functions

Sean Kelly sean at f4.ca
Thu Sep 13 08:30:41 PDT 2007


Janice Caron wrote:
> On another thread I pondered that the D2.0 syntax for const member
> function was ambiguous. I've now come to believe it's also wrong.
> 
> What we're talking about is a function which would be declared like
> this in C++ (with const at the end)
> 
> class C
> {
>     int f() const { /* ... */ }
> }
> 
> in D2.0, apparently the syntax is:
> 
> class C
> {
>     invariant int f() { /* ... */ }
> }
> 
> Here's my problem. f isn't invariant, by D's use of the word.

Personally, I don't like the dual use of 'invariant' anyway.  That using 
it for const required that class invariant suddenly needed empty parens 
to distinguish them suggested to me that it was a poor choice--it was a 
breaking change.  I've advocated 'view' in place of 'readonly' in the 
past, but it's perhaps too common a word.


Sean



More information about the Digitalmars-d mailing list