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

Janice Caron caron800 at googlemail.com
Sun Dec 9 12:17:30 PST 2007


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.



More information about the Digitalmars-d mailing list