On Wednesday, November 14, 2012 20:48:57 Dan wrote:
> This fails to compile when accessing as m.pgoo() complaining
> about postblit.
> What is wrong with this?
> 
> Note: If I alias as array instead of map: alias const(X)[] Map;
> it compiles fine.
> 
> Thanks
> Dan
> -----------------------------
> struct X { this(this) {} }
> alias const(X)[string] Map;
> @property int pgoo(ref Map x) { return 3; }
> 
> void main() {
> Map m;
> pgoo(m);
> m.pgoo();
> }

Postblit doesn't work with const objects and there's not currently any way to 
make it work with const objects. So, any attempt to copy any element in your 
AA won't work. So, if the AA implementation has any code in it which requires 
copying an element (and it probably does), then a type with a postblit in it 
won't work if it's const.

At present const and postblit don't get allow at all, and it sounds like the 
solution that Andrei and Walter have been cooking up will probably involve 
adding copy constructors, but nothing has actually happened yet. postblit 
fundamentally doesn't work with const or immutable though and can't, because 
you can't modify const or immutable objects, and postblit requires you to 
alter the object. So, as far as const and immutable go, postblit is 
fundamentally flawed.

- Jonathan M Davis

Reply via email to