diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 517aa742..ecf9cb70 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -30,39 +30,47 @@ namespace units { // is_quantity - - template - requires std::Same - class quantity; - namespace detail { template inline constexpr bool is_quantity = false; - template - inline constexpr bool is_quantity> = true; - - } // namespace detail + } template concept bool Quantity = detail::is_quantity; + // Scalar + + template + concept bool Scalar = Number && !Quantity; + + template + requires std::Same + class quantity; + + namespace detail { + + template + inline constexpr bool is_quantity> = true; + + } // namespace detail + // common_quantity - template + template struct common_quantity; - template + template struct common_quantity, quantity, Rep> { using type = quantity; }; - template + template struct common_quantity, quantity, Rep> { using type = quantity>>, Rep>; }; - template> + template> using common_quantity_t = typename common_quantity::type; // treat_as_floating_point @@ -74,7 +82,7 @@ namespace units { namespace detail { - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -84,7 +92,7 @@ namespace units { } }; - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -93,7 +101,7 @@ namespace units { } }; - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -102,7 +110,7 @@ namespace units { } }; - template + template struct quantity_cast_impl { template static constexpr To cast(const Q& q) @@ -113,7 +121,7 @@ namespace units { } // namespace detail - template + template requires std::Same constexpr To quantity_cast(const quantity& q) { @@ -125,7 +133,7 @@ namespace units { // quantity_values - template + template struct quantity_values { static constexpr Rep zero() noexcept { return Rep(0); } static constexpr Rep one() noexcept { return Rep(1); } @@ -135,7 +143,7 @@ namespace units { // quantity - template + template requires std::Same class quantity { Rep value_; @@ -230,7 +238,7 @@ namespace units { }; // clang-format off - template + template [[nodiscard]] constexpr Quantity operator+(const quantity& lhs, const quantity& rhs) { @@ -239,7 +247,7 @@ namespace units { return ret(ret(lhs).count() + ret(rhs).count()); } - template + template [[nodiscard]] constexpr Quantity operator-(const quantity& lhs, const quantity& rhs) { @@ -248,7 +256,7 @@ namespace units { return ret(ret(lhs).count() - ret(rhs).count()); } -// template +// template template requires !Quantity /* [[nodiscard]]*/ constexpr Quantity operator*(const quantity& q, @@ -259,7 +267,7 @@ namespace units { return ret(ret(q).count() * v); } - //template + //template template requires !Quantity /* [[nodiscard]]*/ constexpr Quantity operator*(const Rep1& v, @@ -268,7 +276,7 @@ namespace units { return q * v; } - template + template [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, const quantity& rhs) requires treat_as_floating_point || @@ -280,7 +288,7 @@ namespace units { return ret(lhs.count() * rhs.count()); } -// template +// template template [[nodiscard]] constexpr Quantity operator/(const Rep1& v, const quantity& q) @@ -294,7 +302,7 @@ namespace units { return ret(v / den(q).count()); } -// template +// template template [[nodiscard]] constexpr Quantity operator/(const quantity& q, const Rep2& v) @@ -306,8 +314,8 @@ namespace units { return ret(ret(q).count() / v); } - template - [[nodiscard]] constexpr Number operator/(const quantity& lhs, + template + [[nodiscard]] constexpr Scalar operator/(const quantity& lhs, const quantity& rhs) { Expects(rhs != std::decay_t(0)); @@ -317,7 +325,7 @@ namespace units { return cq(lhs).count() / cq(rhs).count(); } - template + template [[nodiscard]] constexpr Quantity operator/(const quantity& lhs, const quantity& rhs) requires treat_as_floating_point || @@ -331,7 +339,7 @@ namespace units { return ret(lhs.count() / rhs.count()); } - template + template [[nodiscard]] constexpr Quantity operator%(const quantity& q, const Rep2& v) { @@ -340,7 +348,7 @@ namespace units { return ret(ret(q).count() % v); } - template + template [[nodiscard]] constexpr Quantity operator%(const quantity& lhs, const quantity& rhs) { @@ -351,39 +359,39 @@ namespace units { // clang-format on - template + template [[nodiscard]] constexpr bool operator==(const quantity& lhs, const quantity& rhs) { using ct = common_quantity_t, quantity>; return ct(lhs).count() == ct(rhs).count(); } - template + template [[nodiscard]] constexpr bool operator!=(const quantity& lhs, const quantity& rhs) { return !(lhs == rhs); } - template + template [[nodiscard]] constexpr bool operator<(const quantity& lhs, const quantity& rhs) { using ct = common_quantity_t, quantity>; return ct(lhs).count() < ct(rhs).count(); } - template + template [[nodiscard]] constexpr bool operator<=(const quantity& lhs, const quantity& rhs) { return !(rhs < lhs); } - template + template [[nodiscard]] constexpr bool operator>(const quantity& lhs, const quantity& rhs) { return rhs < lhs; } - template + template [[nodiscard]] constexpr bool operator>=(const quantity& lhs, const quantity& rhs) { return !(lhs < rhs);