mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
docs: "Interface Introduction" chapter updated
This commit is contained in:
@@ -22,6 +22,9 @@ behind this is that:
|
|||||||
a user's written code, a new idiom in the library is to use the same identifier for
|
a user's written code, a new idiom in the library is to use the same identifier for
|
||||||
a type and its instance.
|
a type and its instance.
|
||||||
|
|
||||||
|
Also, to prevent possible issues in compile-time logic, all of the library's entities must be
|
||||||
|
marked `final`. This prevents the users to derive own strong types from them, which would
|
||||||
|
prevent expression template simplification of equivalent entities.
|
||||||
|
|
||||||
## Strong types instead of aliases
|
## Strong types instead of aliases
|
||||||
|
|
||||||
@@ -234,6 +237,17 @@ the resulting expression template.
|
|||||||
| `power<A, 3>, per<A>` | `power<A, 2>` |
|
| `power<A, 3>, per<A>` | `power<A, 2>` |
|
||||||
| `A, per<power<A, 2>>` | `{identity}, per<A>` |
|
| `A, per<power<A, 2>>` | `{identity}, per<A>` |
|
||||||
|
|
||||||
|
It is important to notice here that only the elements with exactly the same type are being
|
||||||
|
simplified. This means that, for example, `m/m` results in `one`, but `km/m` will not be
|
||||||
|
simplified. The resulting derived unit will preserve both symbols and their relative
|
||||||
|
magnitude. This allows us to properly print symbols of some units or constants that require
|
||||||
|
such behavior. For example, the Hubble constant is expressed in `km⋅s⁻¹⋅Mpc⁻¹`, where both
|
||||||
|
`km` and `Mpc` are units of _length_.
|
||||||
|
|
||||||
|
Also, to prevent possible issues in compile-time logic, all of the library's entities must be
|
||||||
|
marked `final`. This prevents the users to derive own strong types from them, which would
|
||||||
|
prevent expression template simplification of equivalent entities.
|
||||||
|
|
||||||
4. **Repacking**
|
4. **Repacking**
|
||||||
|
|
||||||
In case an expression uses two results of other operations, the components of its arguments are repacked
|
In case an expression uses two results of other operations, the components of its arguments are repacked
|
||||||
|
Reference in New Issue
Block a user