Mixin template functions are ignored in struct
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Oct 14 14:41:32 PDT 2014
On Tuesday, 14 October 2014 at 21:21:33 UTC, tcak wrote:
> Anyway, that suggested usage is making my work harder. I am
> putting that mixin in many struct and defining each method one
> by one in that way doesn't seem like suitable to me.
You could rename the method in the struct then mixin the rest.
Like
private mixin template TestCommonMethods(){
public bool apply( int d, int e ){
return false;
}
}
public struct Test{
public mixin TestCommonMethods;
public bool apply2( char c ){ // now named apply2
return true;
}
}
void main(){
Test t;
t.apply( 5, 3 ); // works
t.apply2('c'); // also works
}
The mixin template might also define an apply function that just
forwards the call to the other name, similarly to how a final
method in a class or interface might call a virtual function to
allow customization.
More information about the Digitalmars-d-learn
mailing list