How to break const
Mehrdad
wfunction at hotmail.com
Mon Jun 18 07:58:02 PDT 2012
On Monday, 18 June 2012 at 14:55:42 UTC, Mehrdad wrote:
> Identical calls giving identical results? What?
>
>
> import std.stdio;
> struct S
> {
> this(int a)
> {
> this.a = a;
> this.increment = { return this.a++; };
> }
> int a;
> int delegate() pure increment;
> auto oops() const { return this.increment(); }
> }
> void main()
> {
> auto c = immutable(S)(0);
> writeln(c.oops()); // 0
> writeln(c.oops()); // 1
> writeln(c.oops()); // 2
> writeln(c.oops()); // 3
> writeln(c.oops()); // 4
> writeln(c.oops()); // 5
> }
Heck, make that all @safe pure nothrow:
int delegate() pure @safe nothrow increment;
auto oops() pure const @safe nothrow { return
this.increment(); }
More information about the Digitalmars-d
mailing list