digitalmars.D - Ref!(T)? All we need now is opImplicitCast
- Janice Caron (15/15) Dec 09 2007 std.slist implements a singly linked list, SList(T). The function
- Bill Baxter (9/29) Dec 09 2007 But still that would only work for something like Container!(int) and
- BCS (4/38) Dec 10 2007 the Ref(T) type could wrap all the opX's in:
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.
Dec 09 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
Dec 09 2007
Bill Baxter wrote:Janice Caron wrote: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.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
Dec 10 2007