feat!: 💥 dimensionless quantities refactored

Dimensionless quantities are now represented by quantity types rather
than by plain representation types. Only dimensionless quantities with
`unitless` unit are implicitly convertible from representation types.

`units::exp()` now is a function doing std::exp() on a representation
type (previous `units::exp` class template was renamed to
`units::exponent`).

BREAKING_CHANGE: gcc-9.3 support removed
BREAKING_CHANGE: `exp` and `Exp` renamed to `exponent` and `Exponent`
Resolves #27
Resolves #42
This commit is contained in:
Mateusz Pusz
2020-09-08 11:02:16 +02:00
parent c8b60b80c1
commit 563b358d5e
47 changed files with 599 additions and 422 deletions
+3 -3
View File
@@ -13,9 +13,9 @@ The most important concepts in the library are `Unit`, `Dimension`,
http://www.nomnoml.com
[<abstract>Dimension|
[base_dimension<Symbol, Unit>]<-[exp<Dimension, Num, Den>]
[derived_dimension<Child, Unit, Exponent...>]<-[exp<Dimension, Num, Den>]
[exp<Dimension, Num, Den>]<-[derived_dimension<Child, Unit, Exponent...>]
[base_dimension<Symbol, Unit>]<-[exponent<Dimension, Num, Den>]
[derived_dimension<Child, Unit, Exponent...>]<-[exponent<Dimension, Num, Den>]
[exponent<Dimension, Num, Den>]<-[derived_dimension<Child, Unit, Exponent...>]
]
[<abstract>Quantity|
+4 -4
View File
@@ -147,9 +147,9 @@ The above dimensions can be defined in the library with the
namespace si {
struct dim_area : derived_dimension<dim_area, square_metre,
exp<dim_length, 2>> {};
exponent<dim_length, 2>> {};
struct dim_speed : derived_dimension<dim_speed, metre_per_second,
exp<dim_length, 1>, exp<dim_time, -1>> {};
exponent<dim_length, 1>, exponent<dim_time, -1>> {};
}
@@ -179,9 +179,9 @@ matter. Even if we define the above as:
namespace si {
struct dim_area : derived_dimension<dim_area, square_metre,
exp<dim_length, 1>, exp<dim_length, 1>> {};
exponent<dim_length, 1>, exponent<dim_length, 1>> {};
struct dim_speed : derived_dimension<dim_speed, metre_per_second,
exp<dim_time, -1>, exp<dim_length, 1>> {};
exponent<dim_time, -1>, exponent<dim_length, 1>> {};
}
+14 -14
View File
@@ -120,17 +120,17 @@ will result in a different unnamed unit symbol:
:emphasize-lines: 2-4, 6-8, 10-12
struct dim_momentum : derived_dimension<dim_momentum, kilogram_metre_per_second,
exp<si::dim_mass, 1>,
exp<si::dim_length, 1>,
exp<si::dim_time, -1>> {}; // kg ⋅ m/s
exponent<si::dim_mass, 1>,
exponent<si::dim_length, 1>,
exponent<si::dim_time, -1>> {}; // kg ⋅ m/s
struct dim_momentum : derived_dimension<dim_momentum, kilogram_metre_per_second,
exp<si::dim_length, 1>,
exp<si::dim_mass, 1>,
exp<si::dim_time, -1>> {}; // m ⋅ kg/s
exponent<si::dim_length, 1>,
exponent<si::dim_mass, 1>,
exponent<si::dim_time, -1>> {}; // m ⋅ kg/s
struct dim_momentum : derived_dimension<dim_momentum, kilogram_metre_per_second,
exp<si::dim_time, -1>,
exp<si::dim_length, 1>,
exp<si::dim_mass, 1>> {}; // 1/s ⋅ m ⋅ kg
exponent<si::dim_time, -1>,
exponent<si::dim_length, 1>,
exponent<si::dim_mass, 1>> {}; // 1/s ⋅ m ⋅ kg
where ``kilogram_metre_per_second`` is defined as::
@@ -143,8 +143,8 @@ However, the easiest way to define momentum is just to use the
:emphasize-lines: 3
struct dim_momentum : derived_dimension<dim_momentum, kilogram_metre_per_second,
exp<si::dim_mass, 1>,
exp<si::dim_speed, 1>> {}; // kg ⋅ m/s
exponent<si::dim_mass, 1>,
exponent<si::dim_speed, 1>> {}; // kg ⋅ m/s
In such a case the library will do its magic and will automatically
unpack a provided derived dimension to its base dimensions in order to
@@ -161,8 +161,8 @@ of ``N/m``):
:emphasize-lines: 2
struct dim_surface_tension : derived_dimension<dim_surface_tension, newton_per_metre,
exp<si::dim_force, 1>,
exp<si::dim_length, -1>> {}; // N/m
exponent<si::dim_force, 1>,
exponent<si::dim_length, -1>> {}; // N/m
If we defined the above in terms of base units we would end up with
a ``kg/s²`` derived unit symbol.
@@ -194,7 +194,7 @@ where `no_prefix` is a special tag type describing that the library should
not allow to define a new prefixed unit that would use this unit as a
reference ("kilohours" does not have much sense, right?). The `ratio` type
used in the definition is really similar to ``std::ratio`` but it takes
an additional ``Exp`` template parameter that defines the exponent of the ratio.
an additional ``Exponent`` template parameter that defines the exponent of the ratio.
Another important difference is the fact that the objects of that class are used
as class NTTPs rather then a type template parameter kind.