DIP66 1.2 (Multiple) alias this. Continuation of work.
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 25 16:35:59 PDT 2015
On 05/26/2015 01:17 AM, IgorStepanov wrote:
>
>
> My example:
> auto foo(T)(){ return 1; }
> auto foo(T)()if(is(T: int)){ return 2; }
>
> struct Foo
> {
> //...
> }
> struct Bar
> {
> Foo f;
> int i;
> alias i this;
> }
>
> auto ret = foo!Bar;
> assert(ret == 2); //exactly the second function
> ...
(No, this actually raises an ambiguity error, but I see the point.)
> After that, imagine, someone added alias intVal this to Foo.
> Now there are many ways to convert Bar to int. However, user
> don't know about it.
>
> And if foo!Bar will start to return 1, it is very ugly situation.
I'm not convinced the alternative is better.
One can still do e.g.:
auto foo(T)()if(!is(typeof({static assert(is(T: int));}))){ return 1; }
auto foo(T)()if(is(typeof({static assert(is(T: int));}))){ return 2; }
More information about the Digitalmars-d
mailing list