[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 23:04:06 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24892

--- Comment #4 from Dennis <dkorpel at live.nl> ---
The first point about it providing new information is false, you can already
use std.traits.BaseClassesTuple to find parents.

The second point reasons as follows:

1. Static arrays implicitly converting to slices leads to problems
2. Also, programmers might implement `alias this` functions with bad
performance
3. Therefore implicit conversion happening in template functions is bad in
general
4. Therefore we should thwart implicit conversion by making our template
constraints more strict
5. Therefore we should provide a new construct to accommodate this check

I agree with 1, but that's a separate issue. 
2 is just how generic code works: if you implement an interface in a bad way,
the resulting code using that interface will be bad as a consequence. You reap
what you sow. 

Regarding 3 and 4: I'm not a fan of alias this with classes, but if we want to
get rid of it, we should deprecate it proper. (This has actually been tried but
reverted because there wasn't a good migration path.) I don't think we should
try to sabotage it by making our templates gatekeep one kind of implicit
conversion in favor of another.

Templates constraints should simply ask what they need, which brings me back to
the unaddressed question: What actual function do you need it for? It's really
hard to reason about handwavy scenarios. When you propose a new feature, there
should be at least one real, concrete use case for it.

--


More information about the Digitalmars-d-bugs mailing list