[Issue 24892] We need a __traits trait to test for whether one class is derived from another
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 6 09:04:50 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24892
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
--- Comment #2 from Dennis <dkorpel at live.nl> ---
Usually when a template function accepts a generic struct/class, the
constraints test for capabilities (like having a certain property or operator
overload) that the function wants to use on a parameter of that type.
Implicitly converting is an operation that you might want to do. Being derived
from a specific class is not an operation on its own. If you do something that
only works with derived classes, like array conversion based on covariance, you
can test for that specifically:
if(is(const(T)[] : const(U)[])
That would also makes it clear *why* you specifically allow derived classes
from `U` but not classes that convert to `U`.
I'm really interested in seeing the function where you want to use this trait,
because I suspect it's trying to solve a problem that should be solved
elsewhere.
--
More information about the Digitalmars-d-bugs
mailing list