Toughts on alias this. (implict converstion in general)

Simen Kjærås simen.kjaras at gmail.com
Thu May 14 07:02:51 UTC 2020


On Wednesday, 13 May 2020 at 22:53:47 UTC, 12345swordy wrote:
> Let type a, b, x, y exist
>
> x contains alias this of a
> y contains alias this of b
>
> function f() exist with two overloads.
>
> f((a, y)) takes the tuple of a and y
> f((x, b)) takes the tuple of x and b
>
> you pass tuple (x, y) to function f.
>
> What exact function does it call in this case?
> To be frank: I have no idea in this case.

It should match the behavior of classes:

class A {}
class B {}
class X : A {}
class Y : B {}

void fun(A a, Y y) {}
void fun(X x, B b) {}

unittest {
     // `fun` called with argument types `(X, Y)` matches both:
     //    `fun(A a, Y y)`
     // and:
     //    `fun(X x, B b)`
     fun(new X(), new Y());
}

--
   Simen


More information about the Digitalmars-d mailing list