mp-units icon indicating copy to clipboard operation
mp-units copied to clipboard

Implement expression templates for units magnitudes

Open mpusz opened this issue 8 months ago • 1 comments

Right now, magnitudes expand in the user-facing types, which makes them verbose and hard to understand. We could incorporate the same generic approach that we use for other entities as well. Those could either be resolved to prime numbers lazily or be expanded to prime numbers in an invisible base class that will be used for all the arithmetics?

With this, we could get decent types and all the features of the current design. For example instead of quantity<reference<fuel_consumption{}, scaled_unit<magnitude<power_v<2, -2>{}, power_v<5, -2>{}>{}, derived_unit<non_si::litre, per<si::kilo_<si::metre{}>>>>{}>{}, double>> we could get quantity<reference<fuel_consumption{}, scaled_unit<magnitude<1, per<100>>{}, derived_unit<non_si::litre, per<si::kilo_<si::metre{}>>>>{}>{}, double>>.

Also, common units could work fine as we could try to find the GCD for an equation (like std::ratio does).

mpusz avatar Oct 17 '23 17:10 mpusz