mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
feat: convertibility of a quantity with a unit one
with the raw value added
Resolves #553
This commit is contained in:
@@ -24,7 +24,7 @@ Here is a small example of operations possible on scalar quantities:
|
||||
|
||||
static_assert(2 * m * (3 * m) == 6 * m2);
|
||||
|
||||
static_assert(10 * km / (5 * km) == 2 * one);
|
||||
static_assert(10 * km / (5 * km) == 2);
|
||||
|
||||
static_assert(1000 / (1 * s) == 1 * kHz);
|
||||
```
|
||||
@@ -51,7 +51,7 @@ Here is a small example of operations possible on scalar quantities:
|
||||
|
||||
static_assert(2 * m * (3 * m) == 6 * m2);
|
||||
|
||||
static_assert(10 * km / (5 * km) == 2 * one);
|
||||
static_assert(10 * km / (5 * km) == 2);
|
||||
|
||||
static_assert(1000 / (1 * s) == 1 * kHz);
|
||||
```
|
||||
|
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user