DIP66 1.2 (Multiple) alias this. Continuation of work.

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 31 08:05:32 PDT 2015


On 3/31/15 7:28 AM, IgorStepanov wrote:
> On Monday, 30 March 2015 at 18:33:17 UTC, Andrei Alexandrescu wrote:
>> On 3/30/15 8:04 AM, Steven Schveighoffer wrote:
>>> On 3/29/15 1:34 PM, IgorStepanov wrote:
>>>
>>>> 1. We should reject types which use opDispatch and alias this at the
>>>> same time.
>>>
>>> Why? Alias this has no filter. opDispatch can use template constraints.
>>> It makes perfect sense to prefer opDispatch, unless it doesn't have a
>>> valid match, and then use alias this instead.
>>>
>>> For example, if I wanted to wrap a type so I can instrument calls to
>>> 'foo', I could do something like this:
>>>
>>> struct FooWrapper(T)
>>> {
>>>    T t;
>>>    alias t this;
>>>    auto opDispatch(string s, A...)(A args) if(s == "foo") {
>>> writeln("calling foo"); return t.foo(args); }
>>> }
>>>
>>> Why is this a bad use case?
>>
>> The idea is to start restrictive and define interaction meaningfully
>> later based on compelling use cases. -- Andrei
>
> Andrei, do you approve those changes? Can we move to work on my github PR?

Gotta run for a couple hours, will review this shortly after. -- Andrei


More information about the Digitalmars-d mailing list