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!(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.
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.
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.
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;
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
TemplateOfsupports this.