Named template arguments

Anonymouse zorael at gmail.com
Thu Aug 8 10:45:54 UTC 2024


I've so far been using `std.typecons.Flag` *heavily* to work 
around there not being named arguments in D. As soon as I wanted 
to pass something a bool, I made it a `Flag` instead to make it a 
bit more self-documenting. (Also in general just to idiot-proof 
it a bit, since I don't trust myself not to confuse parameter 
orders, like in `doThing(false, false, true, false)`.)

But now we have named arguments! And as I'm going through my code 
to replace all those `Yes.throwOnFailure` and `No.recursing` and 
the such, I quickly noticed it didn't work with template 
arguments.

```d
void foo(bool bar)(bool baz) {}

void main()
{
     foo!(bar: true)(baz: false);
}

/*
onlineapp.d(5): Error: found `:` when expecting `)` following 
template argument list
onlineapp.d(5): Error: found `true` when expecting `;` following 
expression
onlineapp.d(5):        expression: `foo!(bar)`
onlineapp.d(5): Error: found `)` instead of statement
*/
```

Is there a reason why we can't have named template arguments too? 
I don't particularly mind it if we'd have to limit the ordering 
so that variadics have to be placed last. I just want to avoid 
having to resort to `Flag!"bar" bar` parameters.


More information about the Digitalmars-d-learn mailing list