forked from mpusz/mp-units
feat: quantity_point
This commit is contained in:
committed by
Mateusz Pusz
parent
75274e13ca
commit
75119eef3f
@@ -29,6 +29,9 @@ namespace units {
|
||||
template<Dimension D, UnitOf<D> U, Scalar Rep>
|
||||
class quantity;
|
||||
|
||||
template<Dimension D, UnitOf<D> U, Scalar Rep>
|
||||
class quantity_point;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename Q1, typename Q2, typename Rep>
|
||||
@@ -57,12 +60,20 @@ struct common_quantity_impl<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>, Rep>
|
||||
using type = quantity<D1, downcast_unit<D1, common_ratio<ratio1, ratio2>>, Rep>;
|
||||
};
|
||||
|
||||
template<typename D, typename U, typename Rep>
|
||||
quantity_point<D, U, Rep> common_quantity_point_impl(quantity<D, U, Rep>);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
|
||||
requires equivalent_dim<typename Q1::dimension, typename Q2::dimension>
|
||||
using common_quantity = detail::common_quantity_impl<Q1, Q2, Rep>::type;
|
||||
|
||||
template<QuantityPoint QP1, QuantityPoint QP2>
|
||||
requires requires { typename common_quantity<typename QP1::quantity_type, typename QP2::quantity_type>; }
|
||||
using common_quantity_point = decltype(
|
||||
detail::common_quantity_point_impl(common_quantity<typename QP1::quantity_type, typename QP2::quantity_type>{}));
|
||||
|
||||
} // namespace units
|
||||
|
||||
#if COMP_GCC >= 10
|
||||
@@ -81,4 +92,10 @@ struct common_type<Q1, Q2> {
|
||||
using type = units::common_quantity<Q1, Q2>;
|
||||
};
|
||||
|
||||
template<units::QuantityPoint QP1, units::QuantityPoint QP2>
|
||||
requires requires { typename units::common_quantity_point<QP1, QP2>; }
|
||||
struct common_type<QP1, QP2> {
|
||||
using type = units::common_quantity_point<QP1, QP2>;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user