Why D const is annoying

Mehrdad wfunction at hotmail.com
Wed May 2 01:12:15 PDT 2012


> > Wouldn't "physical" const-ness be an implementation detail of the 
> > object, and therefore, impossible to determine by the user of the 
> > object?
> No, it's not an implementation detail. When you mark an object as being 
> physically const, then you're guaranteeing that you will not alter it 
> through that reference or pointer.

I think you misunderstood my question.

Yes, __IF__ you mark an object as physically const, then the world is 
beautiful...

My question is, __WHEN__ can you ever do that, except in the most trivial 
situations?
As soon as you try to add an extra layer of indirection (be it a proxy, 
implementing a method in an interface, overriding a base class method, 
etc.), there is NO WAY for the caller to know what obj.foo() does on obj. 
How can it possibly know whether obj will stay physically const? 



More information about the Digitalmars-d mailing list