logoalt Hacker News

do_not_redeemlast Sunday at 6:29 PM1 replyview on HN

Why is omitting the fact that T is a type useful? T could be a normal value too.

This reminds me of C in the 1970s where the compiler assumed every typo was a new variable of type int. Explicit is good.


Replies

WalterBrightlast Sunday at 7:36 PM

> Why is omitting the fact that T is a type useful?

It's the default, because most templates are templated on types. If you want a constant int as part of the template type,

    ArrayListType(int I)
> This reminds me of C in the 1970s where the compiler assumed every typo was a new variable of type int

I think you're referring to function declarations without prototypes. D's syntax does not suffer from that issue.

BTW,

    T func(T)(T x) { return x + 1; }
is a declaration of a "function template". The first parameter list consists of the template parameters, and are compile time types and constants. The second parameter list is the conventional function parameter list. If the first parameter list is omitted, then it's a function.