Reference counted containers prototype

Peter Alexander peter.alexander.au at gmail.com
Mon Dec 26 17:25:09 PST 2011


On 27/12/11 1:09 AM, Peter Alexander wrote:
> On 26/12/11 5:25 PM, Andrei Alexandrescu wrote:
>> (a) All interaction with the held object is done via opDispatch. In fact
>> opDispatch can be engineered to statically enforce no reference to the
>> held object escapes.
>
> I have a separate, but very much related concern:
>
> If the held object has a method with the same name as RefCounted (e.g.
> asConst) then how do you call the held object's method instead of
> RefCounted's method?
>
> I've always felt very suspicious of opDispatch. It seems like exactly
> the kind of thing that seems good when you look at simple cases, but
> would cause subtle problems when used in conjunction with other D
> features (e.g. UFCS).
>
> I'm not yet convinced that opDispatch has been thoroughly explored
> enough to be used in such a fundamental part of the standard library.

Following up to this, how do I access non-function members of the held 
object? e.g.

struct Foo
{
     int x = 1;
}

void main()
{
     RefCounted!Foo f;
     writeln(f.x); // Doesn't work
}


Also, what about template member functions of the held object?

struct Foo
{
     int get(int X)() { return X; }
}

void main()
{
     RefCounted!Foo f;
     writeln(f.get!123()); // Doesn't work either
}


I must admit that I haven't played around much with opDispatch, but 
neither of these appear to work with the current implementation, and 
that's a complete deal-breaker for me. Hopefully I'm just missing 
something though.


More information about the Digitalmars-d mailing list