Ref!(T)? All we need now is opImplicitCast

Bill Baxter dnewsgroup at billbaxter.com
Sun Dec 9 16:05:40 PST 2007


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



More information about the Digitalmars-d mailing list