feat: common_unit support added

This commit is contained in:
Mateusz Pusz committed 2024-09-26 20:28:41 +02:00
1 parent 25af8c9d8f
commit 3190d15eba
5 files changed
+280 -50

No files matched your search

@@ -268,6 +268,31 @@ The above prints:
kg⋅m⋅s⁻²
```
## Symbols of common units
Some [common units](systems_of_units.md#common-units) expressed with a specialization of the
`common_unit` class template need special printing rules for their symbols. As they represent
a minimum set of common units resulting from the addition or subtraction of multiple quantities,
we print all of them as a scaled version of the source unit. For example the following:
```cpp
std::cout << 1 * km + 1 * mi << "\n";
std::cout << 1 * nmi + 1 * mi << "\n";
std::cout << 1 * km / h + 1 * m / s << "\n";
```
will print:
```text
40771 ([1/25146] mi = [1/15625] km)
108167 ([1/50292] mi = [1/57875] nmi)
23 ([1/5] km/h = [1/18] m/s)
```
Thanks to the above, it might be easier for the user to reason about the magnitude of the resulting
unit and its impact on the value stored in the quantity.
## `space_before_unit_symbol` customization point
The [SI Brochure](../../appendix/references.md#SIBrochure) says: