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

`base_units<si_system>`

Open mpusz opened this issue 1 year ago • 2 comments

Consider adding a feature that allows the conversion of quantity units to base units of a specific system. For example:

std::cout << speed[base_units<si_system>] << "\n";
std::cout << value_cast<base_units<si_system>>(speed) << "\n";

A system could be defined as something like:

template<AssociatedUnit auto U1, AssociatedUnit auto... Us>
struct system {};

inline constexpr struct si_system : system<metre, second, ...> {} si_system;

I am not sure if that is a good idea and how to handle composability (i.e. to extend the SI with IEC80000 units).

mpusz avatar Mar 03 '23 11:03 mpusz

This sounds great!

As you probably know, I hate the idea of "preferred" units, but I love the idea of making it easy for users to request conversion to a specific "basis" of units.

I don't have any insights to offer on how this should interoperate with the subdivisions into "kinds" of units (which is what I think the IEC80000 comment is referring to), but the basic idea sounds very appealing.

chiphogg avatar Mar 06 '23 16:03 chiphogg

I don't have any insights to offer on how this should interoperate with the subdivisions into "kinds" of units (which is what I think the IEC80000 comment is referring to), but the basic idea sounds very appealing.

Actually, that is not the case. IEC80000 adds things like bits, bauds, erlangs, etc, while things like s, W, or Hz are needed from the SI (see here: https://github.com/mpusz/units/blob/v2_framework/test/unit_test/static/iec80000_test.cpp).

Whatever we chose here as a solution, I believe that it should be easy to extend/compose to create custom systems.

mpusz avatar Mar 06 '23 16:03 mpusz