Skip to content

Commit

Permalink
docs: a tip with unit_can_be_prefixed workaround added
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Aug 21, 2024
1 parent ab51b47 commit aab0ef8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/users_guide/framework_basics/systems_of_units.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,21 @@ inline constexpr struct mag_pi final : magnitude<std::numbers::pi_v<long double>
```cpp
inline constexpr struct degree final : named_unit<{u8"°", "deg"}, mag_pi / mag<180> * si::radian> {} degree;
```
!!! tip
The ISO 8000 and [SI](../../appendix/glossary.md#si) standards explicitly forbid using prefixes
with some units (e.g., day, minute, hour, degree Celsius). This is why the library disallows
this as well by providing specializations of the `unit_can_be_prefixed` variable template for
such units. Thanks to it trying to create a prefixed version for them will result in
a compile-time error.
However, some projects are not aware of those limitations and use prefixed version of such units
(e.g., [linux kernel uses millidegrees Celsius](https://github.com/search?q=repo%3Atorvalds%2Flinux+millidegree&type=code)).
To enable compatibility with those projects we can workaround the limitation in **mp-units**
by providing a scaled version of the unit explicitly:
```cpp
inline constexpr struct milli_degree_celsius final : named_unit<symbol_text{u8"m℃", "m`C"}, mag_ratio<1, 1000> * si::degree_Celsius> {} milli_degree_celsius;
inline constexpr auto mdeg_C = milli_degree_celsius;
```

0 comments on commit aab0ef8

Please sign in to comment.