-
-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 9608 - Implement template parameter introspection traits #5201
Conversation
53fc0cb
to
c5f8e63
Compare
|
|
Status of this? |
|
Does this work for lambdas or templated classes, structs, functions and so on? If that's the case, then I think there should be tests for that. |
Needs a rebase. Will do soon.
I'll try them out, stay tuned. :) |
The list of traits and their usage: isTemplateTypeParam - Check whether the template parameter is a type parameter. E.g. template Foo(T) isTemplateValueParam - Check whether the template parameter is a value parameter. E.g. template Foo(int Val) isTemplateAliasParam - Check whether the template parameter is an alias parameter. E.g. template Foo(alias symbol) isTemplateThisParam - Check whether the template parameter is a 'this' parameter. E.g. template Foo(this T) isTemplateVariadicParam - Check whether the template parameter is a variadic parameter. E.g. template Foo(Args...) getTemplateParamCount - Get the number of template parameters. E.g. template(A, B, C) => 3 parameters getTemplateParamIdent - Get the name of a specific template parameter. E.g. template(A, B) => 0 == "A", 1 == "B" getTemplateParamType - If the template parameter is a value parameter, get its type. E.g. template(int Val) => int getTemplateParamSpec - If the template parameter has a specialization, retrieve it. E.g. template(T : int) => int getTemplateParamDefault - If the template parameter has a default value, retrieve it. E.g. template(T = int) => int
c5f8e63
to
9c61a4b
Compare
It seems to work for everything but lambdas, where it only supports As far as I can tell lambdas do not support things like type defaults and specializations, or alias parameters. And that kind of makes sense since you can't really "overload" lambdas against each other (although the topic in itself could be interesting). Rebased against master. |
|
Shouldn't |
|
Well for some reason for lambdas they all seem to be type parameters. Also, for alias fun = (a, int b) => a + b;Here only 'a' is the templated type, and you will get an internal string out of this like |
|
Ok, fair enough. It's not up to this PR to change any behavior. |
|
LGTM 👌 |
|
@andralex: It's green now. |
|
@AndrejMitrovic it's red again |
|
Thanks! I'll toggle approval. |
|
Auto-merge toggled on |
|
I submitted a fixed version of this pull request: #5496 |
|
Can we please rediscuss the design before adding 10 new traits and 600+LOC. Also test cases for overloaded templates are missing. Can those be used with |
|
Auto-merge toggled off |
The problem I had with this is that we can't get specialization or default values stored in the tuple that this trait would return. |
|
I agree with @MartinNowak here. |
What's the use-case for specializations? You could add a separate |
|
What introspection features for parameters are we truly missing right now? Let's try to find the use-cases and then implement something based on that. In the meantime we could even close this, it's adding too much in any case.
I better file a new patent.. :P |
|
Ok, I'll start a discussion in the forums soon with a proposal of a (sub)set of the new traits and see which ones we really need, and whether we could implement as many of these in the library instead of adding additional compiler code. Closing for now. :) |
|
@AndrejMitrovic any news on this? It's coming up again in the newsgroups: https://forum.dlang.org/post/awjuoemsnmxbfgzhgkgx@forum.dlang.org. |
|
Well of course it does.. :) Anyway thinking about this I don't really know what another discussion will do. All we'll end up with is a couple of votes in favor, a couple against, and then a big off-topic thread derailment. Implementation-wise this isn't a complex feature, anyone could submit another PR with a subset of features introduced here. And then later one could add more support when it's needed.. |
I think that's a good start. Perhaps get the number of parameters and the names for a lambda/template function. |
|
Yes let's do it piece-meal and introduce one trait at a time. |
|
@AndrejMitrovic came up again [1]. Any progress? [1] http://forum.dlang.org/post/zlkbvnrfncokhzpmtlfn@forum.dlang.org |
|
I'm still very interested in this. It would make templatized open methods much nicer. |
|
Revived interest in the forum: https://forum.dlang.org/post/rfjr11$2uj6$1@digitalmars.com |
Implements https://issues.dlang.org/show_bug.cgi?id=9608
Recreated from #3515
As @andralex suggested, we could keep these undocumented for now and expose them in
std.traitsand/or use them only internally until we're ok with supporting and documenting these new features.