www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Alias overload of function

reply Andrey <saasecondbox yandex.ru> writes:
Hello,
I have got 2 functions:
 void myFunc(string name, int a)(wstring value) {}
 void myFunc(string name, int a)() {}
I want to make an alias (for example for second function without argument):
 alias myAlias(int a) = myFunc!("Name", a);
but compiler says:
 ... matches more than one template declaration
So how solve this problem?
Jun 09 2019
parent reply Basile-z <b2.temp gmx.com> writes:
On Sunday, 9 June 2019 at 10:22:36 UTC, Andrey wrote:
 Hello,
 I have got 2 functions:
 void myFunc(string name, int a)(wstring value) {}
 void myFunc(string name, int a)() {}
I want to make an alias (for example for second function without argument):
 alias myAlias(int a) = myFunc!("Name", a);
but compiler says:
 ... matches more than one template declaration
So how solve this problem?
use __traits(getOverloads) to apply to all of them in a static foreach.
Jun 09 2019
parent Andrey <saasecondbox yandex.ru> writes:
On Sunday, 9 June 2019 at 10:42:12 UTC, Basile-z wrote:
 On Sunday, 9 June 2019 at 10:22:36 UTC, Andrey wrote:
 Hello,
 I have got 2 functions:
 void myFunc(string name, int a)(wstring value) {}
 void myFunc(string name, int a)() {}
I want to make an alias (for example for second function without argument):
 alias myAlias(int a) = myFunc!("Name", a);
but compiler says:
 ... matches more than one template declaration
So how solve this problem?
use __traits(getOverloads) to apply to all of them in a static foreach.
Hmm... Cannot understand how to write getOverloads. My case:
 struct Outer
 {
    static template Inner(alias a, alias b, T)
    {
        void myFunc() {}
    }
 }
This doesn't work (inside Outer):
 pragma(msg, __traits(getOverloads, Inner, "myFunc", true));
Jun 09 2019