const(X) member of Y
Maxim Fomin
maxim at maxim-fomin.ru
Wed Feb 6 14:14:16 PST 2013
On Wednesday, 6 February 2013 at 21:47:35 UTC, Dan wrote:
> On Wednesday, 6 February 2013 at 20:30:40 UTC, Maxim Fomin
> wrote:
>> The fact that bar() does not work and (&bar)() works is
>> terrific.
>
> Sorry - but I don't understand what is terrific? Is this
> sarcasm?
This means it is a huge hole in a type system. Calling
non-immutable method from immutable one is not supported, yet is
possible not through explicit delegate and even not through
casting, but through implicit method call which on low level
happens even without delegate creation. Or, in another way, why
block bar() if (&bar)() works?
> struct X {
> this(this) { c = c.dup; }
> char c[];
> }
>
> (1) What is special about 'struct Y { const(X) x; }' versus
> 'void goo(const(X) x) {}'?
> Both require a copy of X, but for some reason the 'struct Y
> { const(X) x; }' requires the postblit to have signature
> 'this(this) const {...}'.
> Why is this?
Current implementation generates __fieldPostBlit method for Y
struct which calls X postblit. Since Y struct has a const X and
X.__postblit is not marked as const method, there is conflict
between constness and postblits.
goo function does no have such problem
> (2) Do structs have, or is it planned that structs will have,
> true copy constructors (as opposed to postblits)?
Who knows, but current implementation has implicit copy
constructor __cpctor. It is supposed to be hidden from users but
is actually accessible. I don't know why Walter has chosen such
way of copy construction.
More information about the Digitalmars-d
mailing list