Ref!(T)? All we need now is opImplicitCast
BCS
BCS at pathlink.com
Mon Dec 10 12:01:30 PST 2007
Bill Baxter wrote:
> Janice Caron wrote:
>
>> std.slist implements a singly linked list, SList(T). The function
>> front() returns a Ref!(T).
>>
>> Naturally, I jumped up and down with glee for a few moments, thinking
>> I'd uncovered undocumented references. But alas no. Ref!(T) is simply
>> aliased to T.
>>
>> Still ... could be someone's thinking ahead?
>>
>> It occurs to me that it's almost possible to implement a reference
>> type for real. If Ref!(T) were a struct which contained a T*, and
>> which implemented opAssign, opAddAssign, and all the other op*Assigns,
>> and if the implementation of those operators assigned through the
>> pointer, then it would work as an lvalue.
>>
>> The problem is, though it wouldn't work as an rvalue ... yet. What it
>> would need for that to work is opImplicitCast, so that it could
>> auto-convert to a T by dereferencing the pointer.
>>
>> Just a thought.
>
>
> But still that would only work for something like Container!(int) and
> not Container!(MyStruct). Because you wouldn't be able to call
> MyStruct.member without creating all the necessary forwarding functions.
> Or any other op***s it has. So it's not just opAssign variants you
> need.
>
> Maybe alias this will give us what we need though, but I'm not so sure
> "alias this" on a pointer was in the original proposal.
>
> --bb
the Ref(T) type could wrap all the opX's in:
"static if(is(typeof(T.opX))"
or something like that with traits or what not.
More information about the Digitalmars-d
mailing list