On Thu, 29 Sep 2011 16:54:24 +0200, Steven Schveighoffer
<[email protected]> wrote:
I just thought of an interesting way to make a logical const object
without casts. It requires a little extra storage, but works without
changes to the current compiler (and requires no casts).
[snip]
What do people think about this?
This is what I think about it:
class A {
int n;
void delegate( ) dg;
}
pure
A createAnA( int n ) {
A result = new A;
result.n = n;
result.dg = (){ result.n++; };
return result;
}
void main( ) {
immutable A tmp = createAnA( 3 );
assert( tmp.n == 3 );
tmp.dg();
assert( tmp.n == 3 );
}
--
Simen