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

IgorStepanov via Digitalmars-d digitalmars-d at puremagic.com
Mon May 25 16:17:46 PDT 2015


On Monday, 25 May 2015 at 22:32:55 UTC, Timon Gehr wrote:
> On 03/29/2015 07:34 PM, IgorStepanov wrote:
>>
>> 3. is(T: B) should raise an error if there are many ways to 
>> convert T to B.
>
> This is inconsistent with how 'is' works otherwise, and it 
> breaks template constraints in annoying ways. (There is no 
> SFINAE.)
>
> auto foo()()if(true){ return 1; } // this is the one you want
> auto foo()()if(a){ return 2; }    // this is the one with is(T: 
> B)
>
> void main(){
>     foo(); // error
> }
>
> Is the intention that no types with multiple alias this paths 
> to some type should be defined in the first place?

This problem was discussed early, and Andrey sad that is(D: B)
should raise a error, if D can be converted to B via multiple
ways.
I mostly agree with Andrey.
The my main argument: wrong convertion shouldn't be implicitly
hidden and I suggested return true even if there are many ways to
convertion.

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

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.


More information about the Digitalmars-d mailing list