Reference counted containers prototype

Robert Jacques sandford at jhu.edu
Mon Dec 26 17:14:40 PST 2011


On Mon, 26 Dec 2011 17:09:02 -0800, Peter Alexander <peter.alexander.au at gmail.com> 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?

You, can't. Looking at the source code asConst is a private member function and therefore, given we are using opDispatch for forwarding, these methods should have _ or __ prepended onto them.

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

There are several uses for opDispatch. For example, vector swizzling is an example of using opDispatch to replace a finite set of related functions. General forwarding, like alias this, requires a minimalistic design: the public interface should be as small as reasonable and the private functions should never use a 'good' function name.


More information about the Digitalmars-d mailing list