template syntax

Neia Neutuladh neia at ikeran.org
Wed Jan 30 19:42:06 UTC 2019


On Wed, 30 Jan 2019 19:17:38 +0000, dronord wrote:
> Templates are traditional is {} or <>.

I've never seen {} for templates. I believe I've only seen [], <>, (), 
and !().

> < and > is nice construction. May be add it in D?)

D is a mature language, and part of that is not making changes without a 
good reason.

There is a good reason *not* to use <>: it's ambiguous. Consider:

    A<B> C;

This can be parsed as:

    alias SomeType = A<B>;
    SomeType C;

or:

    bool aLessThanB = A < B;
    aLessThanB > C;

Similarly, the expression:

    Func(A<B, C>(1));

could either be:

    auto tmp1 = A < B;
    auto tmp2 = C > (1);
    Func(tmp1, tmp2);

or:

    alias SomeFunc = A<B, C>;
    Func(SomeFunc(1));

It's generally considered bad if you have to defer parsing until you have 
semantic data available.

D didn't manage to eliminate the lexer hack, unfortunately.


More information about the Digitalmars-d mailing list