Bug 8364 – Allow exclamation mark in template definition

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-09T13:12:42Z
Last change time
2022-09-08T08:30:09Z
Assigned to
No Owner
Creator
David Piepgrass

Comments

Comment #0 by qwertie256 — 2012-07-09T13:12:42Z
The syntax of templates should be similar at the definition as it is at the call site: T sum!(T,R)(R range) if (isInputRange!R...) { ... } Of course, the existing syntax must be kept too.
Comment #1 by bearophile_hugs — 2012-07-09T13:17:24Z
(In reply to comment #0) > The syntax of templates should be similar at the definition as it is at the > call site: Why?
Comment #2 by issues.dlang — 2012-07-09T13:25:16Z
Of what value is that? The current situation is wonderfully unambiguous. This proposal would make the parser's life harder and would probably make it so that the grammar could no longer be context free (which would be very bad). And from the perspective of the programmer (not just the compiler), it's _useful_ to be able to tell the difference between a template and a template instantiation at a glance.
Comment #3 by timon.gehr — 2012-07-09T13:36:26Z
(In reply to comment #2) > Of what value is that? The current situation is wonderfully unambiguous. > True. > This proposal would make the parser's life harder Not really. Having this as the only template declaration syntax would even make the parser's life easier. (and if both were legal, parsing the kind that has the '!' would be slighly more efficient.) > and would probably make it so that the grammar could no longer be context free This is not the case. The grammar would stay context free. > (which would be very bad). > And from the perspective of the programmer (not just the compiler), it's > _useful_ to be able to tell the difference between a template and a template > instantiation at a glance. The proposal does not put this ability in danger. Anyway, I don't prefer either scheme and in my opinion it is fine to either leave the template declaration grammar as it is, or to change it to always require '!'. The latter is not going to happen though. (I remember that when I wrote my very first function template in D, I used the proposed syntax and was confused that it didn't work.)
Comment #4 by qwertie256 — 2012-07-10T12:31:37Z
> Why? Because one syntax is easier to learn than two. Timon said "when I wrote my very first function template in D, I used the proposed syntax and was confused that it didn't work", and that makes two of us (well, I quickly realized why the compiler complained, but my first instinct is to use !, and it feels really dumb that I can't). Plus, the parser might be able to handle ! more quickly, since it will know to expect "TemplateParameterList" instead of "Parameters".
Comment #5 by razvan.nitu1305 — 2022-09-08T08:30:09Z
We have had the syntax without ! in the declaration and things have went very well. This will not be changed.