Unable to instantiate template with same name as function

Shriramana Sharma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 4 18:49:31 PST 2016


cym13 wrote:

> Note that parentheses are optional when no argument is provided.

Yes I know that but the point is I expected the compiler to identify 
ta!"string" to refer to a different symbol than ta("string") where the one 
is obviously a template and the other is obviously a function call. The fact 
that parantheses are optional for invocations of zero-arity functions or for 
templates taking a single argument or able to infer its arguments is 
irrelevant.

Anyhow, this is all moot, since actually the compiler *is* able to make the 
difference at the point of invocation and the problem was just a limitation 
in name lookup within the template itself:

string ta(string s) { return s ~ "1"; }
template ta(string s) { enum ta = .ta(s); }
void main()
{
    import std.stdio;
    writeln(ta("a"), ' ', ta!"b");
}

outputs a1 b1 as expected.

Filed https://issues.dlang.org/show_bug.cgi?id=15764 just for the record.

-- 
Shriramana Sharma, Penguin #395953


More information about the Digitalmars-d-learn mailing list