-
-
Notifications
You must be signed in to change notification settings - Fork 113
Closed
Labels
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,
Rephas to satisfy all of the requirements of theNumberconcepts. It means that even if the user is never going to useoperator %=on aquantityhis/her representation type has to provide it or thequantityclass 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
quantityclass template for every "sane" type and will be able to use only those arithmetic operations that are supported by the underlyingReptype.
Which option do you prefer?
(please vote only once by clicking on the correct bar above)