-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
implement std.traits.isInstanceOf for non-types #4739
Conversation
@aG0aep6G, thanks for your PR! By analyzing the annotation information on this pull request, we identified @dsimcha, @9rnsr and @sinfu to be potential reviewers. @dsimcha: The PR was automatically assigned to you, please reassign it if you were identified mistakenly. |
f3b8679
to
a024716
Compare
static assert(isInstanceOf!(Foo, Foo!int)); | ||
static assert(!isInstanceOf!(Foo, Bar!int)); | ||
static assert(!isInstanceOf!(Foo, int)); | ||
static assert(isInstanceOf!(Doo, Doo!int)); | ||
static assert(isInstanceOf!(ABC, ABC!1)); | ||
static assert(!__traits(compiles, isInstanceOf!(Foo, Foo))); | ||
static assert(!isInstanceOf!(Foo, Foo)); |
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.
This might need some attention. I don't see a reason why isInstanceOf!(Foo, Foo)
should fail compilation, but since this was specifically stated here, maybe there is a reason.
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 guess it's because the original implementation did not handle things different from types as second parameter, and Foo
is not a type, so it wouldn't compile.
The autotester fail seems unrelated to the changes made here: problems with a file descriptors, probably due to the test machine being short of disk space. |
FYI you can deprecate such builds by pressing on the "deprecate" link |
enum impl(alias T : S!Args, Args...) = true; | ||
enum impl(alias T) = false; | ||
enum isInstanceOf = impl!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 would have written this as
enum bool isInstanceOf(alias S, alias T : S!Args, Args...) = true;
enum bool isInstanceOf(alias S, alias T) = false;
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.
noice
Well, until two minutes ago I didn't even know that I can log in the autotester... Thank you! |
You might also be interested in reading #4585 then ;-) |
|
@burner: The template already exists, and there is no UFCS for templates anyway. |
whoops my bad. Sorry for the noise. still reads funny though |
cool thx |
Sparked by @lodo1995 showing me in a Learn thread that
TemplateOf
supports this.