D: introspection of a function parameter name

Given the declaration of the function in D, is it possible at compile time to introspectively present a string representation of any function parameter names for use in the function of automatic reflection of a function. For example.

void foo(int a, double b, string c) { } register_function!(foo)() 

Can register_function retrieve "a", "b", "c" at compile time in the same way that __traits (allMembers, someClass) can for a class?

+6
introspection d
source share
2 answers

You can use std.traits.ParameterTypeTuple!() To get the types of parameters, but I don't know how their names are. However, std.traits constantly improving, so my supplement is being added. The likelihood is that no one who is working on it has thought of this particular need, so they have not added it yet. I would suggest creating an improvement request for him, and there are good chances that they will add it.

+4
source share

I think one of the uses of stringof is giving names. You can make them out with a little work. OTOH stringof is not defined, so it will be a little fragile.

+3
source share

All Articles