Vision for the D language - stabilizing complexity?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 15 12:50:39 PDT 2016


On 7/15/2016 7:43 AM, Andrew Godfrey wrote:
> One example is if you make a class that has an internal cache of something.
> Updating or invalidating that cache has no logical effect on the
> externally-observable state of the class. So you should be able to modify the
> cache even on a 'const' object.

Yes, that's the "logical const" argument.

The trouble with it is there's no way for the compiler to detect that's what 
you're doing, nor can it do any checks on it. In effect, C++ const becomes 
little more than a documentation suggestion.


 > This is not a bug and I've seen it have a huge
 > effect on performance - probably a lot more than the const optimizations Walter
 > is talking about here.

You can do logical const in D just like in C++, and get those performance gains. 
You just can't call it "const". But you can call it /*logical_const*/ and get 
the same result.


More information about the Digitalmars-d mailing list