-
-
Notifications
You must be signed in to change notification settings - Fork 741
Add getSymbolsByUDA template #3421
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
Conversation
import std.typetuple : Filter, staticMap, TypeTuple; | ||
import std.traits : hasMember; | ||
|
||
static enum hasSpecificUDA(alias S) = hasUDA!(S, attribute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nonsense like template instance I!(d) cannot use local 'd' as parameter to non-global template I(alias T)
42d124e
to
b3c2d04
Compare
LGTM |
Maybe add a note that this is not recursive? |
Added. |
|
||
// Finds both UDA attributes. | ||
static assert(getSymbolsByUDA!(B, UDA).length == 2); | ||
// Finds one `100` atribute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo atribute
Anything holding this up? |
import std.typetuple : Filter, staticMap, TypeTuple; | ||
|
||
static enum hasSpecificUDA(alias S) = hasUDA!(S, attribute); | ||
static alias I(alias T) = T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think std.traits.Identity
already does this. Can you import that one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does Identity not have a ddoc comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue. Probably because it exposes a deficiency in the language that may be fixed in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you import that one?
Hah, I didn't even realize this was std.traits
that you were editing :) The edit to remove std.traits
import threw me off too!
nice, LGTM |
@schveiguy: Fixed |
Auto-merge toggled on |
Add getSymbolsByUDA template
int d; | ||
} | ||
|
||
// Also checks the symbol itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If foresee that including the symbol itself per default will lead to a lot of devs having to explicitly do an extra check for excluding the symbol from the result. I also think that is the most common case. So I would exclude the symbol itself and let devs explicitly include it if they need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
This pull request adds the
getSymbolsByUDA
template. It is used for getting a(n) Arguments/TypeTuple from a symbol consisting of that symbol or parts of the symbol that have the specified UDA. This functionality is very important for compile-time reflection.