mp-units
mp-units copied to clipboard
feat: improve error message with unknown units
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?
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...
Do you mean the double mention of unknown_unit
? That can probably be simplified somehow.
Done in V2