How to get type qualifiers of D-style variadic parameter

dave dave at dave.com
Thu May 7 10:16:30 UTC 2026


On Tuesday, 5 May 2026 at 03:52:32 UTC, H. S. Teoh wrote:
> On Tue, May 05, 2026 at 03:25:25AM +0000, IchorDev via 
> Digitalmars-d-learn 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.
>
> Code:
>
> ```d
> template getParamTypeQualifier(T, size_t paramIdx) {
> 	static if (is(T Params == __parameters)) {
> 		alias Param = Params[paramIdx];
> 		static if (is(Param U == const U)) {
> 			enum getParamTypeQualifier = "const";
> 		}
> 		else static if (is(Param U == immutable U)) {
> 			enum getParamTypeQualifier = "immutable";
> 		}
> 		else static if (is(Param U == shared U)) {
> 			enum getParamTypeQualifier = "shared";
> 		}
> 		else
> 			enum getParamTypeQualifier = "none";
> 	} else static assert(0, T.stringof ~ " is not a function 
> type");
> }
>
> void fnA(const int param1){}
> void fnB(immutable int param1){}
> void fnC(shared int param1){}
> void fnD(shared int param1, const float param2, immutable 
> double param3, int x){}
>
> pragma(msg, getParamTypeQualifier!(typeof(fnA), 0));
> pragma(msg, getParamTypeQualifier!(typeof(fnB), 0));
> pragma(msg, getParamTypeQualifier!(typeof(fnC), 0));
> pragma(msg, getParamTypeQualifier!(typeof(fnD), 0));
> pragma(msg, getParamTypeQualifier!(typeof(fnD), 1));
> pragma(msg, getParamTypeQualifier!(typeof(fnD), 2));
> pragma(msg, getParamTypeQualifier!(typeof(fnD), 3));
> ```
>
> Output:
> ```
> const
> immutable
> shared
> shared
> const
> immutable
> none
> ```
>
>
> T

I'm not so sure.


More information about the Digitalmars-d-learn mailing list