diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index 478c8b86..b8a9d7fd 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -91,10 +91,10 @@ struct conversion_value_traits { * * @tparam To a target quantity type to cast to */ -template> - requires Quantity && (castable(From::quantity_spec, To::quantity_spec)) && - ((From::unit == To::unit && std::constructible_from) || - (From::unit != To::unit)) // && scalable_with_)) +template> + requires(castable(From::quantity_spec, To::quantity_spec)) && + ((From::unit == To::unit && std::constructible_from) || + (From::unit != To::unit)) // && scalable_with_)) // TODO how to constrain the second part here? [[nodiscard]] constexpr To sudo_cast(FwdFrom&& q) { @@ -143,17 +143,17 @@ template> - requires QuantityPoint && (castable(FromQP::quantity_spec, ToQP::quantity_spec)) && - (detail::same_absolute_point_origins(ToQP::point_origin, FromQP::point_origin)) && - ((FromQP::unit == ToQP::unit && std::constructible_from) || - (FromQP::unit != ToQP::unit)) +template> + requires(castable(FromQP::quantity_spec, ToQP::quantity_spec)) && + (detail::same_absolute_point_origins(ToQP::point_origin, FromQP::point_origin)) && + ((FromQP::unit == ToQP::unit && std::constructible_from) || + (FromQP::unit != ToQP::unit)) [[nodiscard]] constexpr QuantityPoint auto sudo_cast(FwdFromQP&& qp) { if constexpr (is_same_v, std::remove_const_t>) { return quantity_point{ - sudo_cast(std::forward(qp).quantity_from(FromQP::point_origin)), + sudo_cast(std::forward(qp).quantity_from(FromQP::point_origin)), FromQP::point_origin}; } else { // it's unclear how hard we should try to avoid truncation here. For now, the only corner case we cater for, @@ -176,7 +176,7 @@ template( - sudo_cast>(std::forward(qp)) + sudo_cast>(std::forward(qp)) .point_for(ToQP::point_origin)); } else { // new unit may have a larger unit magnitude; we first need to convert to the new unit (potentially causing @@ -184,7 +184,7 @@ template( sudo_cast>( - std::forward(qp)) + std::forward(qp)) .point_for(ToQP::point_origin)); } } diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index 3ad048d8..ac24dd57 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -39,22 +39,19 @@ namespace mp_units { template struct delta_ { - template - requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity> operator()(Rep&& lhs) const + template Rep = std::remove_cvref_t> + [[nodiscard]] constexpr quantity operator()(FwdRep&& lhs) const { - return quantity{std::forward(lhs), R{}}; + return quantity{std::forward(lhs), R{}}; } }; template struct absolute_ { - template - requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point> operator()( - Rep&& lhs) const + template Rep = std::remove_cvref_t> + [[nodiscard]] constexpr quantity_point operator()(FwdRep&& lhs) const { - return quantity_point{quantity{std::forward(lhs), R{}}}; + return quantity_point{quantity{std::forward(lhs), R{}}}; } }; diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index 9933a760..c9614266 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -168,22 +168,23 @@ public: quantity(quantity&&) = default; ~quantity() = default; - template - requires detail::SameValueAs, Rep> - constexpr quantity(Value&& v, R2) : numerical_value_is_an_implementation_detail_(std::forward(v)) + template + requires detail::SameValueAs, Rep> + constexpr quantity(FwdValue&& v, R2) : numerical_value_is_an_implementation_detail_(std::forward(v)) { } - template - requires(!detail::SameValueAs, Rep>) && - detail::QuantityConvertibleTo>, quantity> - constexpr quantity(Value&& v, R2) : quantity(quantity>{std::forward(v), R2{}}) + template> + requires(!detail::SameValueAs) && + detail::QuantityConvertibleTo, quantity> + constexpr quantity(FwdValue&& v, R2) : quantity(quantity{std::forward(v), R2{}}) { } - template Value> + template FwdValue> requires(unit == ::mp_units::one) - constexpr explicit(false) quantity(Value&& v) : numerical_value_is_an_implementation_detail_(std::forward(v)) + constexpr explicit(false) quantity(FwdValue&& v) : + numerical_value_is_an_implementation_detail_(std::forward(v)) { } @@ -209,11 +210,11 @@ public: quantity& operator=(const quantity&) = default; quantity& operator=(quantity&&) = default; - template Value> + template FwdValue> requires(unit == ::mp_units::one) - constexpr quantity& operator=(Value&& v) + constexpr quantity& operator=(FwdValue&& v) { - numerical_value_is_an_implementation_detail_ = std::forward(v); + numerical_value_is_an_implementation_detail_ = std::forward(v); return *this; } @@ -355,16 +356,16 @@ public: return ::mp_units::quantity{-numerical_value_is_an_implementation_detail_, reference}; } - template - friend constexpr decltype(auto) operator++(Q&& q) - requires std::derived_from, quantity> && requires(rep v) { + template Q = std::remove_cvref_t> + friend constexpr decltype(auto) operator++(FwdQ&& q) + requires requires(rep v) { { ++v } -> std::same_as; } { ++q.numerical_value_is_an_implementation_detail_; - return std::forward(q); + return std::forward(q); } [[nodiscard]] constexpr QuantityOf auto operator++(int) @@ -377,16 +378,16 @@ public: return ::mp_units::quantity{numerical_value_is_an_implementation_detail_++, reference}; } - template - friend constexpr decltype(auto) operator--(Q&& q) - requires std::derived_from, quantity> && requires(rep v) { + template Q = std::remove_cvref_t> + friend constexpr decltype(auto) operator--(FwdQ&& q) + requires requires(rep v) { { --v } -> std::same_as; } { --q.numerical_value_is_an_implementation_detail_; - return std::forward(q); + return std::forward(q); } [[nodiscard]] constexpr QuantityOf auto operator--(int) @@ -400,97 +401,92 @@ public: } // compound assignment operators - template - requires std::derived_from, quantity> && requires(rep a, rep b) { + template Q = std::remove_cvref_t> + requires requires(rep a, rep b) { { a += b } -> std::same_as; } - friend constexpr decltype(auto) operator+=(Q&& lhs, const quantity& rhs) + friend constexpr decltype(auto) operator+=(FwdQ&& lhs, const quantity& rhs) { lhs.numerical_value_is_an_implementation_detail_ += rhs.numerical_value_is_an_implementation_detail_; - return std::forward(lhs); + return std::forward(lhs); } - template - requires std::derived_from, quantity> && requires(rep a, rep b) { + template Q = std::remove_cvref_t> + requires requires(rep a, rep b) { { a -= b } -> std::same_as; } - friend constexpr decltype(auto) operator-=(Q&& lhs, const quantity& rhs) + friend constexpr decltype(auto) operator-=(FwdQ&& lhs, const quantity& rhs) { lhs.numerical_value_is_an_implementation_detail_ -= rhs.numerical_value_is_an_implementation_detail_; - return std::forward(lhs); + return std::forward(lhs); } - template - requires std::derived_from, quantity> && (!treat_as_floating_point) && - requires(rep a, rep b) { - { - a %= b - } -> std::same_as; - } - friend constexpr decltype(auto) operator%=(Q&& lhs, const quantity& rhs) + template Q = std::remove_cvref_t> + requires(!treat_as_floating_point) && requires(rep a, rep b) { + { + a %= b + } -> std::same_as; + } + friend constexpr decltype(auto) operator%=(FwdQ&& lhs, const quantity& rhs) { MP_UNITS_EXPECTS_DEBUG(rhs != zero()); lhs.numerical_value_is_an_implementation_detail_ %= rhs.numerical_value_is_an_implementation_detail_; - return std::forward(lhs); + return std::forward(lhs); } - template - requires std::derived_from, quantity> && (!Quantity) && - requires(rep a, const Value b) { - { - a *= b - } -> std::same_as; - } - friend constexpr decltype(auto) operator*=(Q&& lhs, const Value& v) + template Q = std::remove_cvref_t> + requires(!Quantity) && requires(rep a, const Value b) { + { + a *= b + } -> std::same_as; + } + friend constexpr decltype(auto) operator*=(FwdQ&& lhs, const Value& v) { lhs.numerical_value_is_an_implementation_detail_ *= v; - return std::forward(lhs); + return std::forward(lhs); } - template Q2> - requires std::derived_from, quantity> && (Q2::unit == ::mp_units::one) && - requires(rep a, const typename Q2::rep b) { - { - a *= b - } -> std::same_as; - } - friend constexpr decltype(auto) operator*=(Q1&& lhs, const Q2& rhs) + template Q2, std::derived_from Q1 = std::remove_cvref_t> + requires(Q2::unit == ::mp_units::one) && requires(rep a, const typename Q2::rep b) { + { + a *= b + } -> std::same_as; + } + friend constexpr decltype(auto) operator*=(FwdQ1&& lhs, const Q2& rhs) { lhs.numerical_value_is_an_implementation_detail_ *= rhs.numerical_value_is_an_implementation_detail_; - return std::forward(lhs); + return std::forward(lhs); } - template - requires std::derived_from, quantity> && (!Quantity) && - requires(rep a, const Value b) { - { - a /= b - } -> std::same_as; - } - friend constexpr decltype(auto) operator/=(Q&& lhs, const Value& v) + template Q = std::remove_cvref_t> + requires(!Quantity) && requires(rep a, const Value b) { + { + a /= b + } -> std::same_as; + } + friend constexpr decltype(auto) operator/=(FwdQ&& lhs, const Value& v) { MP_UNITS_EXPECTS_DEBUG(v != quantity_values::zero()); lhs.numerical_value_is_an_implementation_detail_ /= v; - return std::forward(lhs); + return std::forward(lhs); } - template Q2> - requires std::derived_from, quantity> && (Q2::unit == ::mp_units::one) && - requires(rep a, const typename Q2::rep b) { - { - a /= b - } -> std::same_as; - } - friend constexpr decltype(auto) operator/=(Q1&& lhs, const Q2& rhs) + template Q2, std::derived_from Q1 = std::remove_cvref_t> + requires(Q2::unit == ::mp_units::one) && requires(rep a, const typename Q2::rep b) { + { + a /= b + } -> std::same_as; + } + friend constexpr decltype(auto) operator/=(FwdQ1&& lhs, const Q2& rhs) { MP_UNITS_EXPECTS_DEBUG(rhs != rhs.zero()); lhs.numerical_value_is_an_implementation_detail_ /= rhs.numerical_value_is_an_implementation_detail_; - return std::forward(lhs); + return std::forward(lhs); } // binary operators on quantities diff --git a/src/core/include/mp-units/framework/quantity_cast.h b/src/core/include/mp-units/framework/quantity_cast.h index dc487c32..ba28d193 100644 --- a/src/core/include/mp-units/framework/quantity_cast.h +++ b/src/core/include/mp-units/framework/quantity_cast.h @@ -56,13 +56,11 @@ namespace mp_units { * * @tparam ToQS a quantity specification to use for a target quantity */ -template - requires Quantity> && - detail::QuantitySpecCastableTo::quantity_spec, ToQS> -[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q) +template> + requires detail::QuantitySpecCastableTo +[[nodiscard]] constexpr Quantity auto quantity_cast(FwdQ&& q) { - return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, - make_reference(ToQS, std::remove_reference_t::unit)}; + return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, make_reference(ToQS, Q::unit)}; } /** @@ -82,13 +80,12 @@ template * * @tparam ToQS a quantity specification to use for a target quantity point */ -template - requires QuantityPoint> && - detail::QuantitySpecCastableTo::quantity_spec, ToQS> -[[nodiscard]] constexpr QuantityPoint auto quantity_cast(QP&& qp) +template> + requires detail::QuantitySpecCastableTo +[[nodiscard]] constexpr QuantityPoint auto quantity_cast(FwdQP&& qp) { - return QP{quantity_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), - std::remove_reference_t::point_origin}; + return QP{quantity_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), + QP::point_origin}; } } // namespace mp_units diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index a3d07fed..686563c6 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -52,18 +52,16 @@ template } struct point_origin_interface { - template - requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(PO, Q&& q) + template Q = std::remove_cvref_t> + [[nodiscard]] friend constexpr quantity_point operator+(PO, FwdQ&& q) { - return quantity_point{std::forward(q), PO{}}; + return quantity_point{std::forward(q), PO{}}; } - template - requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(Q&& q, PO po) + template Q = std::remove_cvref_t> + [[nodiscard]] friend constexpr quantity_point operator+(FwdQ&& q, PO po) { - return po + std::forward(q); + return po + std::forward(q); } template @@ -206,27 +204,26 @@ public: quantity_point(quantity_point&&) = default; ~quantity_point() = default; - template - requires QuantityOf, quantity_spec> && std::constructible_from && - (point_origin == default_point_origin(R)) && (implicitly_convertible(Q::quantity_spec, quantity_spec)) - constexpr explicit quantity_point(Q&& q) : quantity_from_origin_is_an_implementation_detail_(std::forward(q)) + template Q = std::remove_cvref_t> + requires std::constructible_from && (point_origin == default_point_origin(R)) && + (implicitly_convertible(Q::quantity_spec, quantity_spec)) + constexpr explicit quantity_point(FwdQ&& q) : quantity_from_origin_is_an_implementation_detail_(std::forward(q)) { } - template - requires QuantityOf, quantity_spec> && std::constructible_from - constexpr quantity_point(Q&& q, decltype(PO)) : quantity_from_origin_is_an_implementation_detail_(std::forward(q)) + template Q = std::remove_cvref_t> + requires std::constructible_from + constexpr quantity_point(FwdQ&& q, decltype(PO)) : + quantity_from_origin_is_an_implementation_detail_(std::forward(q)) { } - template - requires Quantity> && std::constructible_from && - ReferenceOf::reference)>, PO2::quantity_spec> && - detail::SameAbsolutePointOriginAs - constexpr quantity_point(Q&& q, PO2) : + template Q = std::remove_cvref_t> + requires std::constructible_from && detail::SameAbsolutePointOriginAs + constexpr quantity_point(FwdQ&& q, PO2) : quantity_point( quantity_point::reference, PO2{}, typename std::remove_reference_t::rep>{ - std::forward(q), PO2{}}) + std::forward(q), PO2{}}) { } @@ -413,13 +410,12 @@ public: } // member unary operators - template - friend constexpr decltype(auto) operator++(QP&& qp) - requires std::derived_from, quantity_point> && - requires { ++qp.quantity_from_origin_is_an_implementation_detail_; } + template QP = std::remove_cvref_t> + friend constexpr decltype(auto) operator++(FwdQP&& qp) + requires requires { ++qp.quantity_from_origin_is_an_implementation_detail_; } { ++qp.quantity_from_origin_is_an_implementation_detail_; - return std::forward(qp); + return std::forward(qp); } [[nodiscard]] constexpr quantity_point operator++(int) @@ -428,13 +424,12 @@ public: return {quantity_from_origin_is_an_implementation_detail_++, PO}; } - template - friend constexpr decltype(auto) operator--(QP&& qp) - requires std::derived_from, quantity_point> && - requires { --qp.quantity_from_origin_is_an_implementation_detail_; } + template QP = std::remove_cvref_t> + friend constexpr decltype(auto) operator--(FwdQP&& qp) + requires requires { --qp.quantity_from_origin_is_an_implementation_detail_; } { --qp.quantity_from_origin_is_an_implementation_detail_; - return std::forward(qp); + return std::forward(qp); } [[nodiscard]] constexpr quantity_point operator--(int) @@ -444,22 +439,20 @@ public: } // compound assignment operators - template - requires std::derived_from, quantity_point> && - requires(quantity_type q) { quantity_from_origin_is_an_implementation_detail_ += q; } - friend constexpr decltype(auto) operator+=(QP&& qp, const quantity_type& q) + template QP = std::remove_cvref_t> + requires requires(quantity_type q) { quantity_from_origin_is_an_implementation_detail_ += q; } + friend constexpr decltype(auto) operator+=(FwdQP&& qp, const quantity_type& q) { qp.quantity_from_origin_is_an_implementation_detail_ += q; - return std::forward(qp); + return std::forward(qp); } - template - requires std::derived_from, quantity_point> && - requires(quantity_type q) { quantity_from_origin_is_an_implementation_detail_ -= q; } - friend constexpr decltype(auto) operator-=(QP&& qp, const quantity_type& q) + template QP = std::remove_cvref_t> + requires requires(quantity_type q) { quantity_from_origin_is_an_implementation_detail_ -= q; } + friend constexpr decltype(auto) operator-=(FwdQP&& qp, const quantity_type& q) { qp.quantity_from_origin_is_an_implementation_detail_ -= q; - return std::forward(qp); + return std::forward(qp); } // binary operators on quantity points diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index d813b2a6..9510d119 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -159,13 +159,11 @@ struct quantity_spec_interface : quantity_spec_interface_base { return make_reference(self, u); } - template - requires Quantity> && - QuantitySpecExplicitlyConvertibleTo::quantity_spec, Self{}> - [[nodiscard]] constexpr Quantity auto operator()(this Self self, Q&& q) + template> + requires QuantitySpecExplicitlyConvertibleTo + [[nodiscard]] constexpr Quantity auto operator()(this Self self, FwdQ&& q) { - return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, - make_reference(self, std::remove_cvref_t::unit)}; + return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, make_reference(self, Q::unit)}; } #else template U> @@ -174,13 +172,12 @@ struct quantity_spec_interface : quantity_spec_interface_base { return make_reference(Self{}, u); } - template - requires Quantity> && - QuantitySpecExplicitlyConvertibleTo::quantity_spec, Self_{}> - [[nodiscard]] constexpr Quantity auto operator()(Q&& q) const + template, typename Self_ = Self> + requires QuantitySpecExplicitlyConvertibleTo + [[nodiscard]] constexpr Quantity auto operator()(FwdQ&& q) const { - return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, - make_reference(Self{}, std::remove_cvref_t::unit)}; + return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, + make_reference(Self{}, Q::unit)}; } #endif }; @@ -371,13 +368,12 @@ struct quantity_spec : detail::propagate_equation, detail return detail::make_reference(Self{}, u); } - template - requires Quantity> && - detail::QuantitySpecExplicitlyConvertibleTo::quantity_spec, Self_{}> - [[nodiscard]] constexpr Quantity auto operator()(Q&& q) const + template, typename Self_ = Self> + requires detail::QuantitySpecExplicitlyConvertibleTo + [[nodiscard]] constexpr Quantity auto operator()(FwdQ&& q) const { - return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, - detail::make_reference(Self{}, std::remove_cvref_t::unit)}; + return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, + detail::make_reference(Self{}, Q::unit)}; } #endif }; diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index c6424e1f..72d148fa 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -178,36 +178,36 @@ struct reference { }; -template - requires(!detail::OffsetUnit) && - RepresentationOf, get_quantity_spec(R{}).character> -[[nodiscard]] constexpr quantity> operator*(Rep&& lhs, R) +template Rep = std::remove_cvref_t> + requires(!detail::OffsetUnit) +[[nodiscard]] constexpr quantity operator*(FwdRep&& lhs, R) { - return quantity{std::forward(lhs), R{}}; + return quantity{std::forward(lhs), R{}}; } -template - requires(!detail::OffsetUnit) && - RepresentationOf, get_quantity_spec(R{}).character> -[[nodiscard]] constexpr quantity> operator/(Rep&& lhs, R) +template Rep = std::remove_cvref_t> + requires(!detail::OffsetUnit) +[[nodiscard]] constexpr quantity operator/(FwdRep&& lhs, R) { - return quantity{std::forward(lhs), inverse(R{})}; + return quantity{std::forward(lhs), inverse(R{})}; } -template - requires detail::OffsetUnit && - RepresentationOf, get_quantity_spec(R{}).character> -[[noreturn]] constexpr auto operator*(Rep&&, R) +template Rep = std::remove_cvref_t> + requires detail::OffsetUnit +[[noreturn]] constexpr auto operator*(FwdRep&&, R) { static_assert(!detail::OffsetUnit, "References using offset units (e.g., temperatures) may be constructed only with the `delta` or " "`absolute` helpers"); } -template - requires detail::OffsetUnit && - RepresentationOf, get_quantity_spec(R{}).character> -[[noreturn]] constexpr auto operator/(Rep&&, R) +template Rep = std::remove_cvref_t> + requires detail::OffsetUnit +[[noreturn]] constexpr auto operator/(FwdRep&&, R) { static_assert(!detail::OffsetUnit, "References using offset units (e.g., temperatures) may be constructed only with the `delta` or " @@ -234,20 +234,16 @@ constexpr auto operator/(R, Rep&&) = delete; #endif -template - requires Quantity> -[[nodiscard]] constexpr Quantity auto operator*(Q&& q, R) +template> +[[nodiscard]] constexpr Quantity auto operator*(FwdQ&& q, R) { - return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, - std::remove_cvref_t::reference * R{}}; + return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, Q::reference * R{}}; } -template - requires Quantity> -[[nodiscard]] constexpr Quantity auto operator/(Q&& q, R) +template> +[[nodiscard]] constexpr Quantity auto operator/(FwdQ&& q, R) { - return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, - std::remove_cvref_t::reference / R{}}; + return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, Q::reference / R{}}; } template diff --git a/src/core/include/mp-units/framework/value_cast.h b/src/core/include/mp-units/framework/value_cast.h index 6da41b2d..d5ebf69e 100644 --- a/src/core/include/mp-units/framework/value_cast.h +++ b/src/core/include/mp-units/framework/value_cast.h @@ -44,13 +44,12 @@ namespace mp_units { * * @tparam ToU a unit to use for a target quantity */ -template - requires Quantity> && (convertible(std::remove_reference_t::reference, ToU)) -[[nodiscard]] constexpr Quantity auto value_cast(Q&& q) +template> + requires(convertible(Q::reference, ToU)) +[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q) { - using q_type = std::remove_reference_t; - return detail::sudo_cast>( - std::forward(q)); + return detail::sudo_cast>( + std::forward(q)); } /** @@ -63,13 +62,11 @@ template * * @tparam ToRep a representation type to use for a target quantity */ -template - requires Quantity> && - RepresentationOf::quantity_spec.character> && - std::constructible_from::rep> -[[nodiscard]] constexpr quantity::reference, ToRep> value_cast(Q&& q) +template> + requires RepresentationOf && std::constructible_from +[[nodiscard]] constexpr quantity value_cast(FwdQ&& q) { - return detail::sudo_cast::reference, ToRep>>(std::forward(q)); + return detail::sudo_cast>(std::forward(q)); } /** @@ -83,14 +80,12 @@ template * @tparam ToU a unit to use for the target quantity * @tparam ToRep a representation type to use for the target quantity */ -template - requires Quantity> && (convertible(std::remove_reference_t::reference, ToU)) && - RepresentationOf::quantity_spec.character> && - std::constructible_from::rep> -[[nodiscard]] constexpr Quantity auto value_cast(Q&& q) +template> + requires(convertible(Q::reference, ToU)) && RepresentationOf && + std::constructible_from +[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q) { - using q_type = std::remove_reference_t; - return detail::sudo_cast>(std::forward(q)); + return detail::sudo_cast>(std::forward(q)); } @@ -108,13 +103,12 @@ template * * @tparam ToQ a target quantity type to which to cast the representation */ -template - requires Quantity> && (convertible(std::remove_reference_t::reference, ToQ::unit)) && - (ToQ::quantity_spec == std::remove_reference_t::quantity_spec) && - std::constructible_from::rep> -[[nodiscard]] constexpr Quantity auto value_cast(Q&& q) +template> + requires(convertible(Q::reference, ToQ::unit)) && + (ToQ::quantity_spec == Q::quantity_spec) && std::constructible_from +[[nodiscard]] constexpr Quantity auto value_cast(FwdQ&& q) { - return detail::sudo_cast(std::forward(q)); + return detail::sudo_cast(std::forward(q)); } /** @@ -127,12 +121,12 @@ template * * @tparam ToU a unit to use for a target quantity point */ -template - requires QuantityPoint> && (convertible(std::remove_reference_t::reference, ToU)) -[[nodiscard]] constexpr QuantityPoint auto value_cast(QP&& qp) +template> + requires(convertible(QP::reference, ToU)) +[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp) { - return quantity_point{value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), - std::remove_reference_t::point_origin}; + return quantity_point{value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), + QP::point_origin}; } /** @@ -145,16 +139,12 @@ template * * @tparam ToRep a representation type to use for a target quantity point */ -template - requires QuantityPoint> && - RepresentationOf::quantity_spec.character> && - std::constructible_from::rep> -[[nodiscard]] constexpr quantity_point::reference, - std::remove_reference_t::point_origin, ToRep> -value_cast(QP&& qp) +template> + requires RepresentationOf && std::constructible_from +[[nodiscard]] constexpr quantity_point value_cast(FwdQP&& qp) { - return {value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), - std::remove_reference_t::point_origin}; + return {value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), + QP::point_origin}; } /** @@ -168,14 +158,14 @@ value_cast(QP&& qp) * @tparam ToU a unit to use for the target quantity * @tparam ToRep a representation type to use for the target quantity */ -template - requires QuantityPoint> && (convertible(std::remove_reference_t::reference, ToU)) && - RepresentationOf::quantity_spec.character> && - std::constructible_from::rep> -[[nodiscard]] constexpr QuantityPoint auto value_cast(QP&& qp) +template> + requires(convertible(QP::reference, ToU)) && RepresentationOf && + std::constructible_from +[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp) { - return quantity_point{value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), - std::remove_reference_t::point_origin}; + return quantity_point{ + value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), + QP::point_origin}; } /** @@ -194,14 +184,13 @@ template * * @tparam ToQ a target quantity type to which to cast the representation of the point */ -template - requires QuantityPoint> && (convertible(std::remove_reference_t::reference, ToQ::unit)) && - (ToQ::quantity_spec == std::remove_reference_t::quantity_spec) && - std::constructible_from::rep> -[[nodiscard]] constexpr QuantityPoint auto value_cast(QP&& qp) +template> + requires(convertible(QP::reference, ToQ::unit)) && + (ToQ::quantity_spec == QP::quantity_spec) && std::constructible_from +[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp) { - return quantity_point{value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), - std::remove_reference_t::point_origin}; + return quantity_point{value_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), + QP::point_origin}; } /** @@ -232,16 +221,13 @@ template * * @tparam ToQP a target quantity point type to which to cast the representation of the point */ -template - requires QuantityPoint> && - (convertible(std::remove_reference_t::reference, ToQP::unit)) && - (ToQP::quantity_spec == std::remove_reference_t::quantity_spec) && - (detail::same_absolute_point_origins(ToQP::point_origin, std::remove_reference_t::point_origin)) && - std::constructible_from::rep> -[[nodiscard]] constexpr QuantityPoint auto value_cast(QP&& qp) +template> + requires(convertible(QP::reference, ToQP::unit)) && (ToQP::quantity_spec == QP::quantity_spec) && + (detail::same_absolute_point_origins(ToQP::point_origin, QP::point_origin)) && + std::constructible_from +[[nodiscard]] constexpr QuantityPoint auto value_cast(FwdQP&& qp) { - return detail::sudo_cast(std::forward(qp)); + return detail::sudo_cast(std::forward(qp)); } - } // namespace mp_units