Reference counted containers prototype

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Dec 26 17:27:41 PST 2011


On 12/26/11 7:09 PM, 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?

Good point. A convention I used successfully in the past was that all of 
RefCounted methods should have the RefCounted_ prefix in their name. I 
seem to recall Kenji or Shoo found a wicked technique to define and use 
"super-private" methods, but I need to find it. It's used somewhere in 
Phobos. But I think the convention of putting the name of the proxy in 
the methods of the proxy is powerful enough, anyway. It's a legit 
concern, but it can be addressed effectively.

> 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.

No need to worry. The opDispatch and auto ref features have been 
_especially_ designed for allowing transparent forwarding. So they must 
work by definition - it's their primary role. They _will_ work. Think of 
it as a sort of anthropocentrism for opDispatch.

Already, I have been very surprised that opDispatch works for all cases 
it didn't work last time I tried it. The language implementation has 
improved by leaps and bounds.

=============

A question I have is container naming convention. Say we want to define 
a doubly-list structure in std.container.

1. Expose the unmanaged reference type (DListImpl in the example) and 
the managed reference as an alias. What naming convention?

2. Only expose the managed reference type (DList in the example) and 
disallow or at least discourage the use of DListImpl?

3. Only expose the unmanaged reference type (DListImpl) as e.g. DList, 
and let people who wanna reference counting use 
Refcounted!(DList!Whatevs) explicitly?

4. Something else?


Andrei


More information about the Digitalmars-d mailing list