Thread overview
Named template arguments
Aug 08
IchorDev
August 08

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.

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.

August 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, they just haven’t been implemented yet.

August 08

On Thursday, 8 August 2024 at 10:51:29 UTC, IchorDev wrote:

>

Named template parameters were mentioned in the DIP, they just haven’t been implemented yet.

Thanks! Will just wait then.