D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8364 - Allow exclamation mark in template definition
Summary: Allow exclamation mark in template definition
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-09 13:12 UTC by David Piepgrass
Modified: 2022-09-08 08:30 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Piepgrass 2012-07-09 13:12:42 UTC
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 bearophile_hugs 2012-07-09 13:17:24 UTC
(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 Jonathan M Davis 2012-07-09 13:25:16 UTC
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 timon.gehr 2012-07-09 13:36:26 UTC
(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 David Piepgrass 2012-07-10 12:31:37 UTC
> 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 RazvanN 2022-09-08 08:30:09 UTC
We have had the syntax without ! in the declaration and things have went very well. This will not be changed.