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

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 30 08:04:27 PDT 2015

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?


More information about the Digitalmars-d mailing list