mutable constant?

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 26 08:48:24 PDT 2013


On Wednesday, June 26, 2013 13:16:16 monarch_dodra wrote:
> It seems safe, however, your example seems to show how to indeed
> break the type system... without a cast (!):
> 
>      @property
>      Point* ptr() inout {
>          points[this.id].x = cast(int) this.x;
>          points[this.id].y = cast(int) this.y;
> 
>          return points[this.id];
>      }
> 
> 
> void main() {
>      immutable TplPoint!float my = TplPoint!float(42, 23);
>      Point* p = my.ptr; //Oops! mutable point!
> }
> 
> Disturbing...

It doesn't break anything. It just shows the need for pure.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list