Bug 5175 – Add a way to get parameter names to std.traits
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-11-05T15:14:00Z
Last change time
2015-06-09T05:14:50Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2010-11-05T15:14:08Z
You can use std.traits.ParameterTypeTuple!() to get the types of the parameters to a function, but there is not currently a way to get the names of the parameters. Apparently, this would be useful for creating bindings with other programming languages, so it should be added. It's discussed in this question on stackoverflow: http://is.gd/gLeNf
So, we should have something like std.traits.ParameterNameTuple!() which gives the names of a function's parameters.
Comment #1 by andrej.mitrovich — 2013-01-22T19:37:08Z
Well there is now __parameters, but this gives out both the types, param names, and default values:
void test(int x, int y = 1) { }
template ParameterTuple(alias func)
{
static if(is(typeof(func) P == __parameters))
alias P ParameterTuple;
else
static assert(0);
}
void main()
{
pragma(msg, ParameterTuple!test);
}
> (int x, int y = 1)
I would personally like to wrap ParameterTypeTuple, ParameterStorageClassTuple, and provide a single GetParameters template which would return a tuple of these struct objects:
struct Parameter(Type, alias DefVal)
{
ParameterStorageClass stc;
Type type;
string name;
alias DefVal defaultValue;
}
It's questionable how doable this is but it would make the API easier to use.