Is This a Solution For the Const/Rebindable Issue?

Steven Schveighoffer schveiguy at yahoo.com
Sun Jun 12 21:31:38 PDT 2011


On Sun, 12 Jun 2011 23:58:01 -0400, Mehrdad <wfunction at hotmail.com> wrote:

> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> On Sun, 12 Jun 2011 23:36:21 -0400, Mehrdad <wfunction at hotmail.com>  
>> wrote:
>> > An idea came to my mind for fixing the const/rebindable issue, and I'm
>> > not sure if it's a good idea or not but I thought I'd mention it. I'm
>> > not sure if it's been mentioned before, but a quick search didn't make
>> > it seem like it has been.
>> It has been brought up, a long time ago, by me on the phobos mailing  
>> list
>> (the idea to just assume const(Object) is rebindable, not the final
>> thing).  I think it was on the ML that Andrei maintained, so it's  
>> archive
>> is gone.
>> I had the exact same thoughts as you, and Walter found a perfectly
>> iron-clad reason why it doesn't work.  I can't say I remember the exact
>> reason (maybe he does off the top of his head), but it definitely killed
>> the idea quite well.  So it doesn't work unfortunately :(  I know the  
>> lack
>> of reference/reason is unsatisfying, but I hope you can trust me that to
>> pursue this is not going to go anywhere, and I don't want to re-argue it
>> again...
>> -Steve
>
> No problem, I won't. :) But if you remember the reason, please post it  
> since I'm curious!

I'll see if it's in my sent mail...

OK, I found it, it was actually the same logic but applied to shared  
objects.  But Walter convinced me that the issues are the same (at least  
for this problem).

Consider this type:

struct S
{
    Object o;
}

now, we have these two variables:

const(S) s;
const(Object) o;

finally, the issue:

void kryptonite(ref const(Object) o)
{
    o = new Object();
}

kryptonite(o); // fine
kryptonite(s.o);// oops!

The problem is, there isn't a way to distinguish a tail-const object  
reference from a fully const object reference, yet both types can exist.   
If you want to pass a reference to such a reference, then you run into  
sticky issues like this one.

I understand that you want final to mean "head const", but final is a  
storage class, not a type modifier -- it cannot be used as part of the  
type info.

-Steve


More information about the Digitalmars-d mailing list