tail const
Dmitry Olshansky
dmitry.olsh at gmail.com
Sat Dec 4 13:39:48 PST 2010
On 05.12.2010 0:19, Michel Fortin wrote:
> On 2010-12-04 11:06:14 -0500, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> said:
>>> I'm not sure why you imply it won't work for references. That's the
>>> whole point of the proposal. It can work for references as long as the
>>> memory layout is the same and each member can also be converted as a
>>> reference.
>>
>> No. For references to work with mutable objects, you need
>> equivariance, not contravariance. It's a classic.
>
> Perhaps you should stop misinterpreting. Where did I say that
> references would have to work with *mutable* objects?
>
> struct A(T) {
> T obj;
> }
>
> Now, if you have a reference to "A!Widget", it's true that you can't
> convert it to a reference to "A!Object". What you could do however is
> convert it to a reference to "A!(const(Object))".
My thoughts exactly!
> The compiler would have to transitively check whether each member of
> the original can be converted by reference to their new type before
> allowing the conversion.
But I observe there still may be some rough edges Andrei mentioned about
this rule for a value types, so I wonder, can we make it an unsafe
library facility? Since by the end of day, all we need (better let the
compiler do it, but..) is to transitively check fields and then just
cast the damn thing.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list