diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index d4f60ea3..fe386d1e 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -223,6 +223,7 @@ public: constexpr quantity& operator/=(const Rep2& rhs) requires requires(rep a, const Rep2 b) { { a /= b } -> std::same_as; } { + gsl_ExpectsAudit(rhs != quantity_values::zero()); value_ /= rhs; return *this; } @@ -230,6 +231,7 @@ public: constexpr quantity& operator/=(const dimensionless& rhs) requires requires(rep a, const Rep2 b) { { a /= b } -> std::same_as; } { + gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); value_ /= rhs.count(); return *this; } @@ -239,6 +241,7 @@ public: requires (!floating_point_) && (!floating_point_) && requires(rep a, const Rep2 b) { { a %= b } -> std::same_as; } { + gsl_ExpectsAudit(rhs != quantity_values::zero()); value_ %= rhs; return *this; } @@ -247,6 +250,7 @@ public: requires (!floating_point_) && requires(rep a, rep b) { { a %= b } -> std::same_as; } { + gsl_ExpectsAudit(q.count() != quantity_values::zero()); value_ %= q.count(); return *this; } @@ -328,6 +332,7 @@ public: invoke_result_convertible_to_, rep, const Value&> [[nodiscard]] friend constexpr Quantity auto operator%(const quantity& q, const Value& v) { + gsl_ExpectsAudit(v != quantity_values::zero()); using ret = quantity, rep, Value>>; return ret(q.count() % v); } @@ -336,6 +341,7 @@ public: requires (!floating_point_) && is_same_v && invoke_result_convertible_to_, rep, rep> { + gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); return units::quantity(lhs.count() % rhs.count()); } @@ -402,6 +408,7 @@ template quantity_value_for_, Rep1, Rep2> [[nodiscard]] constexpr Quantity auto operator%(const quantity& lhs, const quantity& rhs) { + gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); using unit = downcast_unit; using ret = quantity, Rep1, Rep2>>; return ret(lhs.count() % rhs.count()); @@ -412,6 +419,7 @@ template Q2> quantity_value_for_, typename Q1::rep, typename Q2::rep> [[nodiscard]] constexpr Quantity auto operator%(const Q1& lhs, const Q2& rhs) { + gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); using ret = common_quantity_for, Q1, Q2>; return ret(ret(lhs).count() % ret(rhs).count()); } diff --git a/src/include/units/quantity_kind.h b/src/include/units/quantity_kind.h index 71b968b1..e8ec9fb5 100644 --- a/src/include/units/quantity_kind.h +++ b/src/include/units/quantity_kind.h @@ -185,6 +185,7 @@ public: constexpr quantity_kind& operator/=(const Rep2& rhs) requires requires(quantity_type q) { q /= rhs; } { + gsl_ExpectsAudit(rhs != quantity_values::zero()); q_ /= rhs; return *this; } @@ -193,6 +194,7 @@ public: constexpr quantity_kind& operator%=(const Rep2& rhs) requires (!Quantity) && requires(quantity_type q, const Rep2 r) { q %= r; } { + gsl_ExpectsAudit(rhs != quantity_values::zero()); q_ %= rhs; return *this; } @@ -200,6 +202,7 @@ public: constexpr quantity_kind& operator%=(const quantity_kind& qk) requires requires(quantity_type q) { q %= qk.common(); } { + gsl_ExpectsAudit(qk.common().count() != quantity_values::zero()); q_ %= qk.common(); return *this; } @@ -224,6 +227,7 @@ public: [[nodiscard]] friend constexpr QuantityKind auto operator/(const quantity_kind& qk, const Value& v) requires requires { { qk.common() / v } -> Quantity; } { + gsl_ExpectsAudit(v != quantity_values::zero()); return detail::make_quantity_kind(qk.common() / v); } @@ -231,6 +235,7 @@ public: [[nodiscard]] friend constexpr QuantityKind auto operator/(const Value& v, const quantity_kind& qk) requires requires { { v / qk.common() } -> Quantity; } { + gsl_ExpectsAudit(qk.common().count() != quantity_values::zero()); return detail::downcasted_kind(v / qk.common()); } @@ -238,6 +243,7 @@ public: [[nodiscard]] friend constexpr QuantityKind auto operator%(const quantity_kind& qk, const Value& v) requires requires { qk.common() % v; } { + gsl_ExpectsAudit(v != quantity_values::zero()); return detail::make_quantity_kind(qk.common() % v); } @@ -285,6 +291,7 @@ template [[nodiscard]] constexpr QuantityKind auto operator/(const QK& lhs, const Q& rhs) requires requires { lhs.common() / rhs; } { + gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); return detail::downcasted_kind(lhs.common() / rhs); } @@ -292,6 +299,7 @@ template [[nodiscard]] constexpr QuantityKind auto operator/(const Q& lhs, const QK& rhs) requires requires { lhs / rhs.common(); } { + gsl_ExpectsAudit(rhs.common().count() != quantity_values::zero()); return detail::downcasted_kind(lhs / rhs.common()); } @@ -299,6 +307,7 @@ template [[nodiscard]] constexpr QuantityKind auto operator%(const QK& lhs, const D& rhs) requires requires { lhs.common() % rhs; } { + gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); return detail::make_quantity_kind(lhs.common() % rhs); } @@ -306,6 +315,7 @@ template QK2> [[nodiscard]] constexpr QuantityKind auto operator%(const QK1& lhs, const QK2& rhs) requires requires { lhs.common() % rhs.common(); } { + gsl_ExpectsAudit(rhs.common().count() != quantity_values::zero()); return detail::make_quantity_kind(lhs.common() % rhs.common()); }