D的有函数
template supportsCall(T, string func) {
import std.format : format;
import std.traits : isIntegral;
enum expr = format!q{
enum supportsCall = isIntegral!(typeof(T.init.%s()));
}(func);
mixin (expr);
}
class AARL (T, string func = "ndx")
if (supportsCall!(T, func)) {
}
int ndx(int i) {
return 42;
}
struct S {
long ndx() {
return 100;
}
}
void main() {
auto a = new AARL!int();
auto b = new AARL!S();
}
浙公网安备 33010602011771号