opDispatch and compile time parameters
Jack Applegame via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 19 01:41:43 PDT 2015
D template system is very powerful. This is more generic
solution:
import std.stdio;
class B {
auto p1(T)(T arg) { writeln( "p1: ", arg ); }
auto p2(T, int C)(T s) { writeln( "p2: ", s, " / ", C); }
}
class C(T) {
T b = new T;
template opDispatch(string s) {
template opDispatch(TARGS...) {
auto opDispatch(ARGS...)(ARGS args) {
static if(TARGS.length) return mixin("b." ~ s ~
"!TARGS(args)");
else return mixin("b." ~ s ~ "(args)");
}
}
}
}
void main() {
auto b = new C!(B)();
b.p1("abc");
b.p2!(int, 10)(5);
}
http://dpaste.dzfl.pl/791c65d0e4ee
More information about the Digitalmars-d
mailing list