Allocators

Peter Alexander peter.alexander.au at gmail.com
Fri Aug 23 15:42:17 PDT 2013


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;
}

void main()
{
     import std.stdio;
     immutable int i = 1;
     const(Foo) a = const(Foo)(&i);
     const(Foo) b = a;
     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 :-)


More information about the Digitalmars-d mailing list