Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add isAggegregateType and isInstantiationOf to phobos.sys.traits. (#8981
) 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.
- Loading branch information
Showing
1 changed file
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters