mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 10:57:16 +02:00
feat: propagation of point origins for scaled units added
This commit is contained in:
@ -40,6 +40,18 @@
|
|||||||
|
|
||||||
namespace mp_units {
|
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
|
* @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.
|
* instantiate this type automatically based on the unit arithmetic equation provided by the user.
|
||||||
*/
|
*/
|
||||||
template<Magnitude auto M, Unit U>
|
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 MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(Magnitude) auto mag = M;
|
||||||
static constexpr U reference_unit{};
|
static constexpr U reference_unit{};
|
||||||
};
|
};
|
||||||
|
@ -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<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);
|
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
|
// class invariants
|
||||||
|
Reference in New Issue
Block a user