-
-
Notifications
You must be signed in to change notification settings - Fork 741
Issue 11706 - Add a TypedefType trait to extract the underlying type of a std.typecons.Typedef #2116
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
I'm unsure about this change to OriginalType. I think code that uses it assumes enum now, and have forgotten about typedefs. Sure, it originally supported In particular, an enum is implicitly castable to the I do agree a trait should be available, but I'm not sure it should be packaged into ... Well, that's my "Shields Up!" reaction anyways. |
I didn't quite check the failing unittest, but the fact they are failing seems like an indication this isn't exactly a trivial change. |
Yeah, I don't quite understand what's going on with the failures. This code works fine in a simplified test-case. I'll investigate. |
What's your suggestion for a name. Maybe |
Updated by implementing |
Nice. Very nice. We need to do the same with |
Shouldn't this accept any type, and be a no-op for non-Typedefs? It makes generic code much easier. I've "abused" this for alias TT = TypedefType!T; //Is T a typedef? Don't care.
static if (is(TT == class)
...
else if (is(TT == struct)
...
...
} |
No-op? You mean alias itself to the passed-in type? |
Updated with |
Should I be concerned about: alias T = TypedefType!(Typedef!int, 75, int, 5, ubyte); Does that even behave according to spec? |
I'll fix this up. But it looks like |
Filed as Issue 12651. It might be a compiler bug, CC'ed Kenji. |
The linked bug is fixed, so ... is it good to go? |
*/ | ||
template TypedefType(T) | ||
{ | ||
static if (is(T : Typedef!Args, Args...)) |
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.
Should match exact Typedef
template parameter list.
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.
Oh you mean = Args
rather than = Args[0]
? I can't remember why I used [0]
here, should be fixed.
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 mean that Typedef
takes fixed amount of template arguments, not any variadic 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.
Ah I thought I had to use the ...
syntax.
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, it is generic pattern matching thing:
struct ZZZ (T1, T2) { }
alias Z = ZZZ!(int, double);
static if (is(Z == ZZZ!(int, T), T))
{
pragma(msg, T);
}
Anything that can be in template parameter list can go after comma
Ping @AndrejMitrovic |
Updated: Let's see if it passes the tester. |
Please add test case for typedef with custom initializer (i.e. |
of a std.typecons.Typedef.
Updated. |
Unrelated test failure? |
Yeah I think so. |
Ok, I'll mark it for merging, will see if it eventually gets to a green state on its own. |
Auto-merge toggled on |
Issue 11706 - Add a TypedefType trait to extract the underlying type of a std.typecons.Typedef
https://issues.dlang.org/show_bug.cgi?id=11706
Thanks to some compiler improvements this can be entirely implemented outside the
Typedef
definition.