Logical const

Simen kjaeraas simen.kjaras at gmail.com
Mon Nov 29 18:26:04 PST 2010


Walter Bright <newshound2 at digitalmars.com> wrote:

> Logical const means the same value is returned every time, not a  
> different one.

So you would have only pure functions work with logical const?


The new keyword 'newlevel' defined earlier could certainly include pure.
Also, the compiler could have the automatically generated opEquals
ignore fields marked 'newlevel'. This way, logical constness is
preserved, no?

Going further, one could define mutable state only in (pure) member
functions. This state would actually be stored in the object, but would
be inaccessible to other member functions, and would not be considered
by opEquals. I believe this is the closest we could come to enforcing
logical constness.

-- 
Simen


More information about the Digitalmars-d mailing list