How to call opCall as template?

Frustrated c1514843 at drdrb.com
Thu Jan 30 12:17:22 PST 2014


import std.stdio;

struct B
{
	template opCall(T)
	{
		void opCall(T x)
		{
			writeln(x);
		}
	}
}

template a(T)
{
	
}

void main() {
	B a;
	a(3);	// works because template parameter can be deduced from
arguments
	a.opCall!(int)(3); // same as about but explicit
	a!(int)(3); // works but calls template because a! refers to a
template
	// no way to use the above syntax to initiate an opCall on a
because it is template notation.
	// at most one might get away with a.!(int)(3) but this is
invalid
}



You'll never be able to do a!()() for the reasons give above. At
most it would have to be implemented the compiler and I doubt it
will ever happen. (for example, one could have the opExclamation
but then one has ambiguity, which is why ! was chosen to avoid in
the first place)


I think for your example, the first case works fine using
deduction.


More information about the Digitalmars-d-learn mailing list