feat: propagation of point origins for scaled units added

This commit is contained in:
Mateusz Pusz
2023-12-21 12:25:09 +01:00
parent 5f840d7079
commit fe099b5ad1
2 changed files with 23 additions and 1 deletions

View File

@ -40,6 +40,18 @@
namespace mp_units {
namespace detail {
template<Unit U, bool = requires { U::point_origin; }>
struct propagate_point_origin {};
template<Unit U>
struct propagate_point_origin<U, true> {
static constexpr auto point_origin = U::point_origin;
};
} // namespace detail
/**
* @brief Unit being a scaled version of another unit
*
@ -50,7 +62,7 @@ namespace mp_units {
* instantiate this type automatically based on the unit arithmetic equation provided by the user.
*/
template<Magnitude auto M, Unit U>
struct scaled_unit {
struct scaled_unit : detail::propagate_point_origin<U> {
static constexpr MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(Magnitude) auto mag = M;
static constexpr U reference_unit{};
};

View File

@ -106,6 +106,16 @@ static_assert(relative_po<absolute_po<isq::length> + isq::height(42 * m)>.quanti
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);
inline constexpr struct my_kelvin : named_unit<"my_K", mag<10> * si::kelvin> {
} my_kelvin;
static_assert(zeroth_point_origin(si::kelvin) == si::absolute_zero);
static_assert(zeroth_point_origin(si::milli<si::kelvin>) == si::absolute_zero);
static_assert(zeroth_point_origin(mag<10> * si::kelvin) == si::absolute_zero);
static_assert(zeroth_point_origin(my_kelvin) == si::absolute_zero);
static_assert(zeroth_point_origin(si::degree_Celsius) == si::ice_point);
static_assert(zeroth_point_origin(mag<10> * si::degree_Celsius) == si::ice_point);
/////////////////////
// class invariants