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

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 30 11:33:19 PDT 2015


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



More information about the Digitalmars-d mailing list