digitalmars.D.learn - Named template arguments
- Anonymouse (29/29) Aug 08 I've so far been using `std.typecons.Flag` *heavily* to work
- IchorDev (3/7) Aug 08 Named template parameters were mentioned in [the
- Anonymouse (2/4) Aug 08 Thanks! Will just wait then.
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.
Aug 08
On Thursday, 8 August 2024 at 10:45:54 UTC, Anonymouse wrote: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.Named template parameters were mentioned in [the DIP](https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1030.md), they just haven’t been implemented yet.
Aug 08
On Thursday, 8 August 2024 at 10:51:29 UTC, IchorDev wrote:Named template parameters were mentioned in [the DIP](https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1030.md), they just haven’t been implemented yet.Thanks! Will just wait then.
Aug 08