Merge branch 'mpusz:master' into master

This commit is contained in:
Jörn Seaman
2025-01-11 17:12:58 +01:00
committed by GitHub
2 changed files with 21 additions and 16 deletions

View File

@@ -51,17 +51,24 @@ template<PointOrigin PO>
return is_specialization_of_zeroth_point_origin<PO>; return is_specialization_of_zeroth_point_origin<PO>;
} }
template<typename FwdQ, PointOrigin PO, QuantityOf<PO::_quantity_spec_> Q = std::remove_cvref_t<FwdQ>>
[[nodiscard]] constexpr QuantityPoint auto make_quantity_point(FwdQ&& q, PO po)
{
if constexpr (detail::is_zeroth_point_origin(PO{}))
return quantity_point{std::forward<FwdQ>(q)};
else
return quantity_point{std::forward<FwdQ>(q), po};
}
struct point_origin_interface { struct point_origin_interface {
template<PointOrigin PO, typename FwdQ, QuantityOf<PO::_quantity_spec_> Q = std::remove_cvref_t<FwdQ>> template<PointOrigin PO, typename FwdQ, QuantityOf<PO::_quantity_spec_> Q = std::remove_cvref_t<FwdQ>>
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep> [[nodiscard]] friend constexpr QuantityPoint auto operator+(PO po, FwdQ&& q)
operator+(PO, FwdQ&& q)
{ {
return quantity_point{std::forward<FwdQ>(q), PO{}}; return quantity_point{std::forward<FwdQ>(q), po};
} }
template<Quantity FwdQ, PointOrigin PO, QuantityOf<PO::_quantity_spec_> Q = std::remove_cvref_t<FwdQ>> template<Quantity FwdQ, PointOrigin PO, QuantityOf<PO::_quantity_spec_> Q = std::remove_cvref_t<FwdQ>>
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep> [[nodiscard]] friend constexpr QuantityPoint auto operator+(FwdQ&& q, PO po)
operator+(FwdQ&& q, PO po)
{ {
return po + std::forward<FwdQ>(q); return po + std::forward<FwdQ>(q);
} }
@@ -264,7 +271,7 @@ public:
template<detail::SameAbsolutePointOriginAs<absolute_point_origin> NewPO> template<detail::SameAbsolutePointOriginAs<absolute_point_origin> NewPO>
[[nodiscard]] constexpr QuantityPointOf<(NewPO{})> auto point_for(NewPO new_origin) const [[nodiscard]] constexpr QuantityPointOf<(NewPO{})> auto point_for(NewPO new_origin) const
{ {
if constexpr (is_same_v<NewPO, decltype(point_origin)>) if constexpr (is_same_v<NewPO, MP_UNITS_NONCONST_TYPE(point_origin)>)
return *this; return *this;
else else
return ::mp_units::quantity_point{*this - new_origin, new_origin}; return ::mp_units::quantity_point{*this - new_origin, new_origin};
@@ -456,10 +463,7 @@ public:
[[nodiscard]] friend constexpr QuantityPoint auto operator+(const QP& qp, const quantity<R2, Rep2>& q) [[nodiscard]] friend constexpr QuantityPoint auto operator+(const QP& qp, const quantity<R2, Rep2>& q)
requires requires { qp.quantity_ref_from(PO) + q; } requires requires { qp.quantity_ref_from(PO) + q; }
{ {
if constexpr (detail::is_zeroth_point_origin(PO)) return detail::make_quantity_point(qp.quantity_ref_from(PO) + q, PO);
return ::mp_units::quantity_point{qp.quantity_ref_from(PO) + q};
else
return ::mp_units::quantity_point{qp.quantity_ref_from(PO) + q, PO};
} }
template<auto R1, typename Rep1, std::derived_from<quantity_point> QP> template<auto R1, typename Rep1, std::derived_from<quantity_point> QP>
@@ -477,10 +481,7 @@ public:
[[nodiscard]] friend constexpr QuantityPoint auto operator-(const QP& qp, const quantity<R2, Rep2>& q) [[nodiscard]] friend constexpr QuantityPoint auto operator-(const QP& qp, const quantity<R2, Rep2>& q)
requires requires { qp.quantity_ref_from(PO) - q; } requires requires { qp.quantity_ref_from(PO) - q; }
{ {
if constexpr (detail::is_zeroth_point_origin(PO)) return detail::make_quantity_point(qp.quantity_ref_from(PO) - q, PO);
return ::mp_units::quantity_point{qp.quantity_ref_from(PO) - q};
else
return ::mp_units::quantity_point{qp.quantity_ref_from(PO) - q, PO};
} }
template<std::derived_from<quantity_point> QP, QuantityPointOf<absolute_point_origin> QP2> template<std::derived_from<quantity_point> QP, QuantityPointOf<absolute_point_origin> QP2>

View File

@@ -444,12 +444,16 @@ template<Unit auto To, auto R, typename Rep>
* @brief Computes the inverse of a quantity in a provided unit * @brief Computes the inverse of a quantity in a provided unit
*/ */
template<Unit auto To, auto R, typename Rep> template<Unit auto To, auto R, typename Rep>
[[nodiscard]] constexpr QuantityOf<dimensionless / get_quantity_spec(R)> auto inverse(const quantity<R, Rep>& q) [[nodiscard]] constexpr Quantity auto inverse(const quantity<R, Rep>& q)
requires requires { requires requires {
representation_values<Rep>::one(); representation_values<Rep>::one();
value_cast<To>(representation_values<Rep>::one() / q); value_cast<To>(representation_values<Rep>::one() / q);
} }
{ {
if constexpr (AssociatedUnit<MP_UNITS_REMOVE_CONST(decltype(To))>) {
constexpr QuantitySpec auto qs = get_quantity_spec(To) * quantity<R, Rep>::quantity_spec;
return qs(representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
} else
return (representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q; return (representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
} }