Closed
Description
The more I think about the "number" concept (#28) the more doubts I have. I see 2 solutions here:
-
Option 1
template<Unit U, Number Rep = double> class quantity { public: template<Number Value> constexpr quantity& operator%=(const Value& rhs); // ... };
In this case,
Rep
has to satisfy all of the requirements of theNumber
concepts. It means that even if the user is never going to useoperator %=
on aquantity
his/her representation type has to provide it or thequantity
class template instantiation will fail. -
Option 2
template<typename T> concept UnitRep = std::regular<T> && std::totally_ordered<T>; template<Unit U, UnitRep Rep = double> class quantity { public: template<Number Value> constexpr quantity& operator%=(const Value& rhs) requires requires(Rep v) { { v %= rhs } -> std::same_as<Rep&>; }; // ... };
In this case, the user will be able to instantiate the
quantity
class template for every "sane" type and will be able to use only those arithmetic operations that are supported by the underlyingRep
type.
Which option do you prefer?
(please vote only once by clicking on the correct bar above)