-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we encourage deriving from quantity
and quantity_point
?
#680
Comments
I assume we want to disallow inheriting from Do you (or does anyone else) have a concrete use case where deriving from |
@chiphogg, my understanding is that some users derive from mp-units/test/static/quantity_test.cpp Lines 400 to 432 in 7102a4f
|
That looks incredibly complex and error prone! I also couldn't tell what new information was actually being added, or whether this is all just boilerplate. My instinct is still to lean on standard guidance to "prefer composition to inheritance". I'm wary of having other types that purport to model the "is-a" relationship with |
A long time ago, one of the contributors changed the
Quantity
concept to allow also classes derived from thequantity
class template. At this point, I thought this idea was OK. However, as C++ standardization approaches fast, we may have to reconsider this decision.The problem with concept-based programming is that concepts do not allow implicit conversion for function arguments. So the following two function templates are not equivalent:
C++ library never encouraged deriving from its own class templates, but all operators worked fine if someone did, thanks to the
foo
approach.In mp-units, in some places, we use
boo
approach. Directly or indirectly, we require a template dependent name to satisfyQuantity
orQuantityPoint
concepts. This would prevent the derived classes from working if those concepts were refactored to accept the type explicitly.On the other hand, explicitly stating that a
Quantity
is also everything derived fromquantity
may be controversial.We should consider changing
Quantity
andQuantityPoint
concepts to do explicit match and carefully refactor the cases where it is used incorrectly.The text was updated successfully, but these errors were encountered: