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 the Number concepts. It means that even if the user is never going to use operator %= on a quantity his/her representation type has to provide it or the quantity 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 underlying Rep type.
Which option do you prefer?


(please vote only once by clicking on the correct bar above)
The more I think about the "number" concept (#28) the more doubts I have. I see 2 solutions here:
Option 1
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
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)