mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
1.07k stars 85 forks source link

`base_units<si_system>` #442

Open mpusz opened 1 year ago

mpusz commented 1 year ago

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).

chiphogg commented 1 year ago

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.

mpusz commented 1 year ago

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.