-
-
Notifications
You must be signed in to change notification settings - Fork 116
Description
A long time ago, one of the contributors changed the Quantity concept to allow also classes derived from the quantity 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:
template<auto R, typename Rep>
void foo(const quantity<R, Rep>& q);
template<Quantity Q>
void boo(const Q& q);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 satisfy Quantity or QuantityPoint 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 from quantity may be controversial.
We should consider changing Quantity and QuantityPoint concepts to do explicit match and carefully refactor the cases where it is used incorrectly.