Why D const is annoying

Timon Gehr timon.gehr at gmx.ch
Wed May 2 01:15:35 PDT 2012


On 05/02/2012 08:48 AM, Mehrdad wrote:
> In the world of OOP,

interface Readonly{
     auto read(){ ... }
}

class Mutable{
     auto read(){ ... }
     void write(int x){ ... }

     Readonly getReadonly(){ ... }
}

private class Adapter: Readonly{
     Mutable field;
     auto read(){ return field.read(); }
}


> when would "guarantee"ing (so to speak) 'physical'
> const-ness ever be handy?
>

Concurrency?

> Wouldn't "physical" const-ness be an implementation detail of the
> object, and therefore,

If it is, don't use the const qualifier.

> impossible to determine by the user of the object?

It is possible because 'const' is part of the method interface.


More information about the Digitalmars-d mailing list