Extracting user defined attributes on function parameters

Jean-Louis Leroy jl at leroy.nyc
Fri Apr 17 16:40:15 UTC 2020


Alas the presence of parameter UDAs breaks 
std.traits.ParameterDefaults:

import std.traits;

struct attr;
void f(@attr int);

pragma(msg, ParameterDefaults!f.stringof);

Error:

dmd -c bug.d
bug.d(4): Error: undefined identifier `attr`, did you mean 
variable `ptr`?
/home/jll/dlang/dmd-2.090.1/linux/bin64/../../src/phobos/std/traits.d(1526): Error: template instance `std.traits.ParameterDefaults!(f).Get!0LU` error instantiating
/home/jll/dlang/dmd-2.090.1/linux/bin64/../../src/phobos/std/traits.d(1529):        instantiated from here: `Impl!0LU`
bug.d(6):        instantiated from here: `ParameterDefaults!(f)`
bug.d(6):        while evaluating `pragma(msg, 
ParameterDefaults!(f).stringof)`

I filed a bug report (20744). And examined the code of 
ParameterDefaults. I think I understand how it works, for the 
most part, but I haven't been able to find a fix yet.

I'd like to understand why taking a slice of __parameters vs 
fetching the first element matters. What is the (meta?) type of 
__parameters[0..1]? I think I'd need to make a copy of it, minus 
the UDAs tucked at the beginning. But I haven't found a way of 
splitting it into smaller components. I tried using indexation 
and variadic template parameters, but it always collapses into a 
string. Makes me think of wave functions in quantum mechanics ;-)



More information about the Digitalmars-d-learn mailing list