How to call opCall as template?

Namespace rswhite4 at googlemail.com
Thu Jan 30 09:59:29 PST 2014


On Thursday, 30 January 2014 at 16:55:01 UTC, Meta wrote:
> 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.

Ok, done:
https://d.puremagic.com/issues/show_bug.cgi?id=12043


More information about the Digitalmars-d-learn mailing list