feat: convertibility of a quantity with a unit one with the raw value added

Resolves #553
This commit is contained in:
Mateusz Pusz
2024-07-14 18:31:11 +02:00
parent 0dfd323c4b
commit fcc16ae282
5 changed files with 191 additions and 11 deletions
@@ -164,6 +164,21 @@ inline constexpr struct parts_per_million final : named_unit<"ppm", mag_ratio<1,
inline constexpr auto ppm = parts_per_million;
```
### Superpowers of the unit `one`
Quantities of the unit `one` are the only ones that are implicitly convertible from a raw value
and explicitly convertible to it. This property also expands to usual arithmetic operators.
Thanks to the above, we can type:
```cpp
quantity<one> inc(quantity<one> q) { return q + 1; }
void legacy(double) { /* ... */ }
if (auto q = inc(42); q != 0)
legacy(static_cast<int>(q));
```
## Angular quantities