On Monday, June 18, 2012 07:36:26 Mehrdad wrote:
> Is it just me, or did I subvert the type system here?
> 
> 
> import std.stdio;
> 
> struct Const
> {
>       this(void delegate() increment)
>       { this.increment = increment; }
>       int a;
>       void delegate() increment;
>       void oops() const { this.increment(); }
> }
> 
> void main()
> {
>       Const c;
>       c = Const({ c.a++; });
>       writeln(c.a);
>       c.oops();
>       writeln(c.a);
> }

No, actually I don't think that you did. The delegate isn't accessing the this 
pointer - which is where const would kick in. It's accessing c through a non-
const reference to the data that was put in its body inside of main.

- Jonathan M Davis

Reply via email to