Comment #0 by eric.estievenart — 2011-01-08T06:18:19Z
You can write:
template Tpl ( T1, T2 ) {...}
void FuncTpl ( T1, T2 )( <args> ) {...}
But you should also be able to write:
template Tpl!T1 {...}
template Tpl!(T1,T2) {...}
void FuncTpl!T1 (<args>) {...}
void FuncTpl!(T1,T2) (<args>) {...}
The rationale behind that is that:
- Simpler syntax when there is only one parameter
- Instantiations and declarations would be more consistent
- Easier to type when instantiating : you can copy
Tpl!(T1,T2) => Tpl!(int,string)
FuncTpl!T1( int a ) => FuncTpl!string( 3 )
(with the current grammar, you have to add the bang,
maybe remove the parenthesis if there is a single arg; This
may become tedious)
- Easier to read: when there is a bang in the declaration, you immediately
know that template params follow, your brain does not have do the analysis:
parenthesis... seems to be function args...
the arguments have no name... it's probably template parameters
yes there is a second group (T1 p1, T2 p2) after, so I'm reading the
template parameters...
Instead: you go through:
bang => template params -> read them -> read the args (if func tpl)
- It could improve the parser speed when the ! is present
(less look ahead since faster decision during analysis)
The change is completely backward compatible.
TODO: Investigate
- (optional?) compiler warning if missing bang
- schedule a transition period to make it mandatory in the language
(the warning or the use of the bang; to decide)
(certainly not for D1)
so that all D code (libraries, ...) look similar
Comment #1 by dmitry.olsh — 2018-05-22T09:22:01Z
This is a set of highly dubious advantages for essentially introducing a syntax change across all of the langauge.
Easier to read? - Bleh, 7 years in, everybdoy loves the current one.
Parser lookahead is trivial, and parsing speed it not even remotely the bottlneck. Lexing surprisingly is importnant, but parsing is mostly meh.
Simpler syntax for 1 parameter is not enough benefit and it we'd have to stick with both for an enternity until code is migrated to "superior" syntax.
So, a clear WONTFIX.