How to group similar member functions from different classes?
Marc Schütz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 20 09:39:54 PDT 2016
Untested:
// foo.d
import a, b;
mixin template Foos {
static if(is(typeof(this) == A))
void foo() { /* implementation for A */ }
static if(is(typeof(this) == B))
void foo() { /* implementation for B */ }
}
// a.d
import foo;
class A {
mixin Foos;
}
// b.d
import foo;
class B {
mixin Foos;
}
You must not have static constructors in any of these modules
because you'd likely get problems with circular initialization.
More information about the Digitalmars-d-learn
mailing list