shouting versus dotting

Michel Fortin michel.fortin at michelf.com
Sun Oct 5 19:23:16 PDT 2008


On 2008-10-05 20:57:31 -0400, "Chris R. Miller" 
<lordsauronthegreat at gmail.com> said:

> The !() syntax seems to serve only as a heads up that it's a template. 
> Otherwise (as far as I can tell) a simple foo(int)(bar, baaz) would 
> work just as well as foo!(int)(bar, baaz).

Well, not so sure about that: I'm pretty sure it's needed for 
disambiguation too. Let's say you have:

	void foo(int x)();
	void foo(T)(T x);

	foo(5);

Is foo(5) a the same as foo!(5), or does it call foo!(int).foo(5) ? 
Under the current rules, it's the second (you can write foo!(5) to call 
the first). If you allow templates to be instanciated without the "!", 
then I guess both will match and you'll have ambiguity.

If you could avoid having sets of parameters, one for the function and 
one for the template, then you could get rid of the "!" in a snap...

Well, maybe not. You'll still have to resolve the same issues for constructors:

	class A(int x) {
		this() {}
	}
	class A() {
		this(int x) {}
	}

	auto a = new A(5);

Perhaps this is not a problem however: the only two valid ways to 
create an instance of one or the other are "new A!(5)" or "new 
A!()(5)", which would translate in non-"!" syntax as: "new A(5)" and 
"new A()(5)". Unfortunately, we don't have this "luck" with functions.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list