fix: relative_point_origin::quantity_spec setting fixed

This commit is contained in:
Mateusz Pusz
2023-08-23 11:42:43 +02:00
parent 71981172c3
commit 7594048850
2 changed files with 26 additions and 4 deletions

View File

@@ -29,16 +29,21 @@
namespace mp_units {
template<QuantitySpec auto Q>
template<QuantitySpec auto QS>
struct absolute_point_origin {
static constexpr QuantitySpec auto quantity_spec = Q;
static constexpr QuantitySpec auto quantity_spec = QS;
};
template<QuantityPoint auto QP>
struct relative_point_origin {
static constexpr QuantityPoint auto quantity_point = QP;
static constexpr QuantitySpec auto quantity_spec =
common_quantity_spec(QP.quantity_spec, QP.point_origin.quantity_spec);
static constexpr QuantitySpec auto quantity_spec = [](){
// select the strongest of specs
if constexpr (detail::QuantityKindSpec<std::remove_const_t<decltype(QP.quantity_spec)>>)
return QP.point_origin.quantity_spec;
else
return QP.quantity_spec;
}();
static constexpr PointOrigin auto absolute_point_origin = QP.absolute_point_origin;
};

View File

@@ -1156,5 +1156,22 @@ static_assert(invalid_addition(5 * activity[Bq], 10 / (2 * isq::time[s]), zero_H
static_assert(invalid_subtraction(zero_Bq + 5 * activity[Bq], 10 / (2 * isq::time[s]), 5 * isq::frequency[Hz]));
/////////////////////////
// relative point origin
/////////////////////////
template<auto QS>
struct absolute_po_ : absolute_point_origin<QS> {};
template<auto QS>
inline constexpr absolute_po_<QS> absolute_po;
template<auto QP>
struct relative_po_ : relative_point_origin<QP> {};
template<auto QP>
inline constexpr relative_po_<QP> relative_po;
static_assert(relative_po<absolute_po<isq::length> + isq::height(42 * m)>.quantity_spec == isq::height);
static_assert(relative_po<absolute_po<kind_of<isq::length>> + isq::height(42 * m)>.quantity_spec == isq::height);
static_assert(relative_po<absolute_po<isq::height> + 42 * m>.quantity_spec == isq::height);
} // namespace