On Wed, Sep 18, 2019 at 12:37:28PM +0000, Simen Kjærås via Digitalmars-d-learn 
wrote:
[...]
> template MergeOverloads(T...) {
>     alias MergeOverloads = T[0];
>     static if (T.length > 1) {
>         alias MergeOverloads = MergeOverloads!(T[1..$]);
>     }
> }
> 
> I would however label that a horrible hack.
> 
> FWIW, I've filed this issue: https://issues.dlang.org/show_bug.cgi?id=20226
[...]

Horrible or not, it's very clever. I wouldn't have thought of that!

But yeah, the way alias can't be overloaded inside a function body is
kinda stupid, esp. seeing that aliasing an overload is exactly how you
resolve an analogous problem inside class scope:

        class Base {
                int abs(int);
        }
        class Derived : Base {
                float abs(float); // causes ambiguity
                alias abs = Base.abs; // brings Base.abs into overload set
                void func() {
                        // now abs(...) will correctly use overload sets
                }
        }

I would have expected you could do this in function scope as well, and
was surprised the compiler rejected it.


T

-- 
Famous last words: I wonder what will happen if I do *this*...

Reply via email to