How to call opCall as template?
Meta
jared771 at gmail.com
Thu Jan 30 08:55:00 PST 2014
On Thursday, 30 January 2014 at 15:59:28 UTC, Namespace wrote:
> 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
This is probably a bug. You should file it in Bugzilla.
More information about the Digitalmars-d-learn
mailing list