Re: Template sequence parameter and default value

2022-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 1/26/22 18:49, Andrey Zherikov wrote: > I want something like this: > ```d > void foo(MODULES... = __MODULE__)() {} Two other options: 1) void foo(MODULES_...)() { static if (MODULES_.length == 0) { import std.meta : AliasSeq; alias MODULES = AliasSeq!__MODULE__; } else { a

Re: Template sequence parameter and default value

2022-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/22 10:21 AM, Andrey Zherikov wrote: So is it possible to get rid of the alias? I'm not sure it's worth the effort? Yours is a pretty straightforward solution. -Steve

Re: Template sequence parameter and default value

2022-01-27 Thread Andrey Zherikov via Digitalmars-d-learn
On Thursday, 27 January 2022 at 03:19:59 UTC, Jaime wrote: You can accomplish this by heading off the template sequence parameter with several default template parameters. If you need them all under one name, you can recombine them in the function body with std.meta.AliasSeq, the effective "kin

Re: Template sequence parameter and default value

2022-01-26 Thread Jaime via Digitalmars-d-learn
On Thursday, 27 January 2022 at 02:49:22 UTC, Andrey Zherikov wrote: What is the best way to emulate a default value for template sequence parameter of a function? I want something like this: ```d void foo(MODULES... = __MODULE__)() {} // these should work: foo!(module1, module2); foo!(module1

Template sequence parameter and default value

2022-01-26 Thread Andrey Zherikov via Digitalmars-d-learn
What is the best way to emulate a default value for template sequence parameter of a function? I want something like this: ```d void foo(MODULES... = __MODULE__)() {} // these should work: foo!(module1, module2); foo!(module1); foo(); // this should use current module (__MODULE__) acc