Template and Type Literals

Nick Treleaven nick at geany.org
Fri May 31 15:24:44 UTC 2024


On Thursday, 30 May 2024 at 18:42:02 UTC, Atila Neves wrote:
> Java inherited the same mistake, namely that we have to repeat 
> the type's name to declare constructor(s) and the destructor. 
> This makes refactoring harder, which is a Bad Thing(tm). In D 
> we use `this` and Bob's your proverbial uncle.
>
> Unfortunately, we then went and did something nearly exactly 
> the same with templates that's caused me hours of debugging 
> when I decide to rename the thing and don't immediately catch 
> it because of reflection or `__traits(compiles)`.
>
> Anyway, all to say that I've long wanted to write template 
> lambdas and use `this` instead of a template's name.

The trouble with using `this` for eponymous templates is that it 
can't be used for eponymous template functions, because it would 
conflict with constructor syntax. Instead I suggested either the 
`template` keyword, or the `__self` identifier:
https://issues.dlang.org/show_bug.cgi?id=7364#c4
https://issues.dlang.org/show_bug.cgi?id=7364#c9

The latter wouldn't need a grammar fix, and could also be useful 
for lambda recursion.


More information about the dip.ideas mailing list