On 08/24/2013 12:42 AM, Peter Alexander wrote:
On Friday, 23 August 2013 at 20:20:21 UTC, Timon Gehr wrote:
On 08/23/2013 10:08 PM, Peter Alexander wrote:
On Friday, 23 August 2013 at 20:04:28 UTC, H. S. Teoh wrote:
What's the problem with const again?
I'm thinking mainly of const postblit, and the ramifications of solving
that.
What problem does const postblit have that a const constructor does
not have?
Currently, const postblit completely breaks the type system.
struct Foo
{
this(this) { *p = 2; }
int* p;
}
...
That's a mutable postblit, but I see the point.
void main()
{
import std.stdio;
immutable int i = 1;
const(Foo) a = const(Foo)(&i);
const(Foo) b = a;
I think this line should fail for lack of an appropriately qualified
postblit.
writeln(a.p, " ", *a.p);
writeln(b.p, " ", *b.p);
writeln(&i, " ", i);
}
For me, this gives:
7FFF5257D418 2
7FFF5257D418 2
7FFF5257D418 1
The immutable int is changed, and apparently the same address has two
different values at the same time!
I'm not aware of any way to do this with constructors, but maybe I'm
just not aware :-)
import std.stdio;
void main(){
void check(immutable(int)* ptr){
writeln(ptr," ",*ptr);
}
struct S{
immutable(int) x;
this(int)const{
check(&x);
x=2;
check(&x);
}
}
auto s = S(0);
}
7FFFAFAA4B80 0
7FFFAFAA4B80 2