Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix issue 3309 parameter names trait #951
Interesting ideas. I went with string names only because that was the biggest piece missing from the introspection capabilities. And of course, there was already a bug report on it with a patch that I used as the starting point.
Perhaps we should be considering a more generalized getParameters trait? We can already get argument types from std.traits. If you add parameterNames, the only thing missing would be default arguments. Is that enough of a reason for a more generalized trait?
@mrmonday, aye, I think that would be great, and I know of at least two people who have asked about exactly this kind of thing before on IRC (using the parameters to the current function as an expression tuple). Retrieving the symbol for the current function is also a frequently requested feature (simplifying interfaces for a lot of mixin-style code).
Either way, I want to thank @jmaschme for taking on these important issues. Your effort is greatly appreciated!
@mrmonday Only working within a function/method may not be sufficient.
void someOtherFunction(int x, float y = 10.0);
In this case, newFunc should be: newFunc(bool test, int x, float y = 10.0), ie, the copied parameters are NOT a tuple argument, they are 1st class parameters, retaining their names and default args.
Note: Syntax in my example is for illustration only. I don't care at all how it's implemented, assuming the result is the same...
@JakobOvrum, Yeah, I've often needed typeof(this_function), or something to that effect.