How to call opCall as template?
Namespace
rswhite4 at googlemail.com
Thu Jan 30 07:59:26 PST 2014
Here: http://dlang.org/operatoroverloading.html#FunctionCall
is this example:
----
import std.stdio;
struct F {
int opCall() {
return 0;
}
int opCall(int x, int y, int z) {
return x * y * z;
}
}
void main() {
F f;
int i;
i = f(); // same as i = f.opCall();
i = f(3,4,5); // same as i = f.opCall(3,4,5);
}
----
And it works of course. But what if I want to templatize opCall?
How can I call it?
----
import std.stdio;
struct F {
T opCall(T = int)(int a, int b, int c) {
return cast(T)(a * b * c);
}
}
void main() {
F f;
int i = f(3,4,5);
float f_ = f!float(6, 7, 8);
}
----
Does not work, it fails with:
Error: template instance f!float f is not a template declaration,
it is a variable
More information about the Digitalmars-d-learn
mailing list