Add isAggegregateType and isInstantiationOf to phobos.sys.traits. #8981
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
isAggregateType is the same as isAggregateType from std.traits but with tweaked documentation and examples.
isInstantiationOf is the equivalent of std.traits' isInstanceOf. The documentation and tests have been updated, and an overload for partial instantiation has been added.
The reason for the name change is that "instance" is not normally used with templates (instantiation is typically considered to be the correct term). Rather, instance is normally used to indicate that a value is an instance of a particular type. So, using isInstanceOf to check whether a type is an instantiation of a particular template seems like a misuse of the term and like it could easily cause confusion. The downside of course is that the new name is longer and harder to type, but while it's a trait that is necessary in some situations, IMHO, it's not needed frequently enough for the longer name to be a problem - particularly when it's a clearer name.
I did try to simplify isInstantationOf's implementation so that it didn't need an alias overload, but I failed, because apparently, when typeof is used on the instantiation of a function template, the fact that it's a template instantation is lost. So, unfortunately, we're forced to operate on the function's symbol rather than its type to detect whether it's an instantation of a particular template. The documentation has been updated to include that information.
I also tried to then make the alias overload not need a helper template so that fewer template instantiations would be needed, but that didn't work either, because the alias overload needs a template specialization to work, and I couldn't find a way to write an is expression that would have the same effect. So maybe, someone can improve the implementation later if they can figure that out, but since it's the same implementation as std.traits, we're not any worse off. And the overload which operates on aggregate types probably sees a lot more use anyway.