Given a function declaration in D, is it possible to introspect at compile time the string representation of any function parameter names, for use in say automatic function reflection. E.g.
void foo(int a, double b, string c) { }
register_function!(foo)()
Can register_function extract "a","b","c" at compile time in a similar way that __traits(allMembers,someClass) can for a class?
The parameter name is a string of alphanumeric characters starting with a letter that does not contain spaces or special characters.
Function Parameters Parameters are variables that are defined in the function definition. They are assigned the values which were passed as arguments when the function was called, elsewhere in the code.
The inspect module helps in checking the objects present in the code that we have written. We are going to use two methods i.e. signature() and getargspec() methods from the inspect module to get the list of parameters name of function or method passed as an argument in one of the methods.
You can use std.traits.ParameterTypeTuple!()
to get the types of the parameters, but I'm not aware of any way to get their names. std.traits
is continuously being improved, however, so that my get added. Odds are that is just that no one working on it has thought of that particular need, so they haven't added it yet. I would suggest creating an enhancement request for it, and there's a good chance that they'll add it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With