Thread overview
function overload with mixin template bug?
May 17
1)

struct T{
    void f1(){writeln("default f1");}
    void f1(int x){writeln("overload f1");}
}
//main
T().f1();
T().f1(1);
//compiles and output as expected.


2)

mixin template add_function(){
    void f1(){writeln("default f1");}
}
struct T{
    mixin add_function;
    void f1(int x){writeln("overload f1");}
}
//main
T().f1();
T().f1(1);
//Error: function f355.T.f1 (int x) is not callable using argument types ()
/* What? i´m missing something here? */


3)

mixin template add_function(){
    void f1(){writeln("default f1");}
}
struct T{
    mixin add_function;
}
//main
T().f1();
//compiles and output as expected.


Function overloads coming from mixin templates are not being detected ?


May 17
On Wednesday, 17 May 2017 at 13:13:06 UTC, Patric Dexheimer wrote:
> Function overloads coming from mixin templates are not being detected ?

A name being present in the struct means that name is NOT pulled from the mixin template. This is a feature, not a bug. It allows overriding of mixin template individual behavior. see: http://arsdnet.net/this-week-in-d/sep-27.html


To bring in the mixin overloads in addition to your current ones instead of overriding, use alias:

mixin Foo some_name;
alias foo = some_name.foo;
void foo() {} // now they are all combined
May 17
On Wednesday, 17 May 2017 at 13:26:36 UTC, Adam D. Ruppe wrote:
> On Wednesday, 17 May 2017 at 13:13:06 UTC, Patric Dexheimer wrote:
>> Function overloads coming from mixin templates are not being detected ?
>
> A name being present in the struct means that name is NOT pulled from the mixin template. This is a feature, not a bug. It allows overriding of mixin template individual behavior. see: http://arsdnet.net/this-week-in-d/sep-27.html
>
>
> To bring in the mixin overloads in addition to your current ones instead of overriding, use alias:
>
> mixin Foo some_name;
> alias foo = some_name.foo;
> void foo() {} // now they are all combined

Oh, thank you, didn´t know about it.
didn´t know about this syntax also "mixin Foo some_name;"