www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.ideas - Traits for named varargs

reply monkyyy <crazymonkyyy gmail.com> writes:
I dont know what progress there been on named arguments, but... 
it seems like its been a while

As a bandaid, just vomit some sort of ugly details at me in a 
trait

```d
import std;
void foo(T...)(T args,bool magic=true){
	args.writeln;
         magic.writeln;
}
unittest{
	foo(1,2,3);
	foo(1,2,magic:false);
}
```

I know of no way to make even this simple code work

so, `__traits(namesofvarargs,T)==["","","magic"]`; give me one 
piece of data and I can figure it out and make some better apis 
until full named tuples come.
May 15
parent Nick Treleaven <nick geany.org> writes:
On Thursday, 15 May 2025 at 22:08:45 UTC, monkyyy wrote:
 ```d
 import std;
 void foo(T...)(T args,bool magic=true){
 	args.writeln;
         magic.writeln;
 }
 unittest{
 	foo(1,2,3);
 	foo(1,2,magic:false);
 }
 ```

 I know of no way to make even this simple code work
The only way I know is to provide the type sequence for T: ```d alias Seq(S...) = S; foo!(Seq!(int, int))(1, 2, magic:false); ```
 so, `__traits(namesofvarargs,T)==["","","magic"]`; give me one 
 piece of data and I can figure it out and make some better apis 
 until full named tuples come.
T doesn't know anything about `magic`, it's just a type sequence. Also, `args` is not a variadic parameter.
May 16