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

How to implement aliased quantity types? #502

Open mpusz opened 11 months ago

mpusz commented 11 months ago

height, depth, altitude are aliases to the same quantity types. Right now, the library implements them as:

inline constexpr struct height : quantity_spec<length> {} height;
inline constexpr auto depth = height;
inline constexpr auto altitude = height;

which means that the user will always see isq::height in the quantity type even when another aliased name was used in the code.

The feature associated with it is the fact that:

static_assert(isq::height / isq::depth == dimensionless);
mpusz commented 11 months ago

We could implement those as:

inline constexpr struct height : quantity_spec<length> {} height;
inline constexpr struct depth : decltype(height) {} height;
inline constexpr struct altitude : decltype(height) {} height;

which would preserve the types in a quantity type.

But the below will not result in dimensionless anymore:

static_assert(isq::height / isq::depth != dimensionless);

which may be a good thing?

Ideas? Comments?