From 6f0f6b2213d32c48eb1a4285cffde00907b477e9 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 8 Jun 2023 17:41:48 +0200 Subject: [PATCH] feat: `make_quantity()` and `op*(Representation, Unit` are now correctly using quantity constructor constraints --- src/core/include/mp-units/quantity.h | 7 +++++-- src/core/include/mp-units/quantity_spec.h | 2 +- src/core/include/mp-units/reference.h | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/include/mp-units/quantity.h b/src/core/include/mp-units/quantity.h index 748d9efc..6579a5c0 100644 --- a/src/core/include/mp-units/quantity.h +++ b/src/core/include/mp-units/quantity.h @@ -99,6 +99,9 @@ public: static constexpr Unit auto unit = get_unit(reference); using rep = Rep; + // helper used to constrain `make_quantity()` and `operator*(Representation, Unit)` + static constexpr bool _rep_safe_constructible_ = detail::RepSafeConstructibleFrom; + // static member functions [[nodiscard]] static constexpr quantity zero() noexcept requires requires { quantity_values::zero(); } @@ -319,7 +322,7 @@ public: private: template - requires RepresentationOf, get_quantity_spec(R2).character> + requires quantity>::_rep_safe_constructible_ friend constexpr quantity> make_quantity(Rep2&& v); template @@ -488,7 +491,7 @@ template // make_quantity template - requires RepresentationOf, get_quantity_spec(R).character> + requires quantity>::_rep_safe_constructible_ [[nodiscard]] constexpr quantity> make_quantity(Rep&& v) { return quantity>(std::forward(v)); diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index 89e27c7b..e6e3013e 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -37,7 +37,7 @@ namespace mp_units { template - requires RepresentationOf, get_quantity_spec(R).character> + requires quantity>::_rep_safe_constructible_ [[nodiscard]] constexpr quantity> make_quantity(Rep&& v); namespace detail { diff --git a/src/core/include/mp-units/reference.h b/src/core/include/mp-units/reference.h index c120bb75..120d27be 100644 --- a/src/core/include/mp-units/reference.h +++ b/src/core/include/mp-units/reference.h @@ -30,7 +30,7 @@ namespace mp_units { template - requires RepresentationOf, get_quantity_spec(R).character> + requires quantity>::_rep_safe_constructible_ [[nodiscard]] constexpr quantity> make_quantity(Rep&& v); [[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u) @@ -129,7 +129,7 @@ template Rep> class quantity; template - requires RepresentationOf, get_quantity_spec(R{}).character> + requires quantity>::_rep_safe_constructible_ [[nodiscard]] constexpr quantity> operator*(Rep&& lhs, R) { return make_quantity(std::forward(lhs));