Template Usage with Eponymous Trick
MoonlightSentinel
moonlightsentinel at disroot.org
Thu Jan 30 20:00:05 UTC 2020
On Thursday, 30 January 2020 at 17:00:08 UTC, ShadoLight wrote:
> Agreed. My question though is should the 'shorthand' notation
> _replace_ the 'longhand' notation, or be available _in
> addition_ to the 'longhand' notation in the eponymous case (so
> the eponymous notation is just 'syntax sugar' if you will).
>
Consider the following example:
T foo(T = int)(T val = T.init)
{
return val + 1;
}
void main()
{
auto i = foo!().foo();
writeln(i);
}
What should be the value of i?
1: foo!() is the template instantiation, foo() the method call
2: foo!() and foo() are method calls.
The answer is 2 (because empty braces are optional) but with your
proposed change it would be ambigous (unless one interpreation
was prioritized which would probably be more confusing).
Maybe we should rather ask what benefit results from allowing
this explicit notation? IMHO the entire purpose of epynemous
templates is to make templates containing one public* symbol less
verbose which is a common use case.
*public ~ useful outside of the templated symbol
> And, in that case some of the examples in the documentation
> needs fixing.
Agreed, the documentation could use some polishing.
More information about the Digitalmars-d-learn
mailing list