How to get type qualifiers of D-style variadic parameter
monkyyy
crazymonkyyy at gmail.com
Thu May 7 15:18:30 UTC 2026
On Tuesday, 5 May 2026 at 03:25:25 UTC, IchorDev wrote:
> If I have a type qualifier on a D-style variadic parameter,
> like so:
> ```d
> void fnA(const ...){}
> void fnB(immutable ...){}
> void fnC(shared ...){}
> ```
> ... then how do I get that type qualifier using compile-time
> reflection?
> Ideally I need to be able to do this on function/function
> pointer/delegate TYPES, not just the actual function symbols.
that style of varargs is runtime, nothing compiletime is possible
my test code:
```d
import std;
extern(D) void func1() {}
extern(C) void func2(int, ...) {}
extern(D) void func3(...) {}
extern(D) void func4(int[]...) {}
extern(C) void func5(int,const ...) {}
extern(D) void func6(const ...) {}
extern(D) void func7(const int[]...) {}
static assert( is(typeof(func3)==typeof(func6)));
template func(int I){
alias func=mixin("func"~I.stringof);
}
unittest{
static foreach(I;1..8){
pragma(msg,variadicFunctionStyle!(func!I).stringof);
pragma(msg,Parameters!(func!I).stringof);
pragma(msg,"---");
}}
void foo(...){
import core.vararg;
_arguments.writeln;
foreach(i;0.._arguments.length){
_argptr[i].writeln;
auto z = va_arg!int(_argptr);
z.writeln(typeof(z).stringof);
}}
unittest{
int a=1;
int b=2;
int c=3;
foo(a,b,c);
}
```
I believe `const ...` is a no op; all "d-style" varargs are
lvalues as far as I can tell
you should use "func7" as that shows up as `const(int[])` to the
traits
lets see if Im still effectively banned for "impoliteness"
More information about the Digitalmars-d-learn
mailing list