How to break const
deadalnix
deadalnix at gmail.com
Mon Jun 18 05:43:03 PDT 2012
Le 18/06/2012 07:36, Mehrdad a écrit :
> Is it just me, or did I subvert the type system here?
>
delegate fail to ensure transitivity of type qualifier. This is no news.
This is however a big error.
I proposed a fix to that by changing the semantic of the type qualifier
depending on its position in the declaration, but didn't received much
feedback at the time.
>
> 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);
> }
More information about the Digitalmars-d
mailing list