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

feat: improve error message with unknown units

Open JohelEGP opened this issue 2 years ago • 2 comments

An example at https://mpusz.github.io/units/use_cases/unknown_dimensions.html includes:

constexpr auto result = 144 * km / (2 * h);
static_assert(std::is_same_v<decltype(result)::dimension,
                             unknown_dimension<exponent<dim_length, 1>, exponent<dim_time, -1>>>);
static_assert(std::is_same_v<decltype(result)::unit,
                             scaled_unit<ratio(1, 36, 1), unknown_coherent_unit>>);

Error messages containing unknown units could be improved if instead the unit's type were formed like expression templates. In this case, it could be something like unknown_unit<kilometre, per<hour>>. What do you think?

JohelEGP avatar Mar 29 '22 16:03 JohelEGP

In this specific case it looks like a nice solution but what about more complicated units? Will the following:

constexpr auto result = 144 * km / (2 * h) / (2 * h);

look like unknown_unit<unknown_unit<kilometre, per<hour>>, per<hour>>? I am not sure if it is better? Units can be even more complicated than that...

mpusz avatar May 09 '22 10:05 mpusz

Do you mean the double mention of unknown_unit? That can probably be simplified somehow.

JohelEGP avatar May 09 '22 13:05 JohelEGP

Done in V2

mpusz avatar Jun 15 '23 07:06 mpusz