forked from mpusz/mp-units
refactor: 💥 from now on point origins must be marked final + absolute_point_origin does not use CRTP anymore
This commit is contained in:
@@ -16,6 +16,8 @@ or derived [quantity](../../appendix/glossary.md#quantity):
|
||||
by the library's framework based on the [quantity equation](../../appendix/glossary.md#quantity-equation)
|
||||
provided in the [quantity specification](../../appendix/glossary.md#quantity_spec).
|
||||
|
||||
All of the above dimensions have to be marked as `final`.
|
||||
|
||||
|
||||
### `DimensionOf<T, V>` { #DimensionOf }
|
||||
|
||||
@@ -42,6 +44,8 @@ including:
|
||||
- Intermediate [derived quantity](../../appendix/glossary.md#derived-quantity) specifications being
|
||||
a result of a [quantity equations](../../appendix/glossary.md#quantity-equation) on other specifications.
|
||||
|
||||
All of the above quantity specifications have to be marked as `final`.
|
||||
|
||||
|
||||
### `QuantitySpecOf<T, V>` { #QuantitySpecOf }
|
||||
|
||||
@@ -237,7 +241,7 @@ implicitly convertible from quantity specification `V`, which means that `V` mus
|
||||
However, if we define `mean_sea_level` in the following way:
|
||||
|
||||
```cpp
|
||||
inline constexpr struct mean_sea_level : absolute_point_origin<isq::altitude> {} mean_sea_level;
|
||||
inline constexpr struct mean_sea_level final : absolute_point_origin<isq::altitude> {} mean_sea_level;
|
||||
```
|
||||
|
||||
then it can't be used as a point origin for _points_ of `isq::length` or `isq::width` as none of them
|
||||
@@ -330,7 +334,7 @@ for which an instantiation of `quantity_point_like_traits` type trait yields a v
|
||||
struct mp_units::quantity_point_like_traits<std::chrono::time_point<C, std::chrono::seconds>> {
|
||||
using T = std::chrono::time_point<C, std::chrono::seconds>;
|
||||
static constexpr auto reference = si::second;
|
||||
static constexpr struct point_origin : absolute_point_origin<isq::time> {} point_origin{};
|
||||
static constexpr struct point_origin final : absolute_point_origin<isq::time> {} point_origin{};
|
||||
using rep = std::chrono::seconds::rep;
|
||||
|
||||
[[nodiscard]] static constexpr convert_implicitly<quantity<reference, rep>> to_quantity(const T& qp)
|
||||
|
||||
@@ -346,13 +346,13 @@ For example:
|
||||
- the absolute point origin can be defined in the following way:
|
||||
|
||||
```cpp
|
||||
inline constexpr struct absolute_zero : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
```
|
||||
|
||||
- the relative point origin can be defined in the following way:
|
||||
|
||||
```cpp
|
||||
inline constexpr struct ice_point : relative_point_origin<absolute_zero + 273'150 * milli<kelvin>> {} ice_point;
|
||||
inline constexpr struct ice_point final : relative_point_origin<absolute_zero + 273'150 * milli<kelvin>> {} ice_point;
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ origin.
|
||||
{style="width:80%;display: block;margin: 0 auto;"}
|
||||
|
||||
```cpp
|
||||
inline constexpr struct origin : absolute_point_origin<origin, isq::distance> {} origin;
|
||||
inline constexpr struct origin final : absolute_point_origin<isq::distance> {} origin;
|
||||
|
||||
// quantity_point<si::metre, origin> qp1{100 * m}; // Compile-time error
|
||||
// quantity_point<si::metre, origin> qp2{120 * m}; // Compile-time error
|
||||
@@ -197,14 +197,6 @@ assert(origin - qp2 == -120 * m);
|
||||
// assert(origin - origin == 0 * m); // Compile-time error
|
||||
```
|
||||
|
||||
!!! info
|
||||
|
||||
The `absolute_point_origin` class template uses the CRTP idiom to enforce the uniqueness of
|
||||
such a type. You should pass the type of a derived class as the first argument of the template
|
||||
instantiation.
|
||||
|
||||
*[CRTP]: Curiously Recurring Template Parameter
|
||||
|
||||
We can't construct a quantity point directly from the quantity anymore when a custom, named origin
|
||||
is used. To prevent potential safety and maintenance issues, we always need to
|
||||
explicitly provide both a compatible origin and a quantity measured from it to construct a quantity
|
||||
@@ -249,8 +241,8 @@ type and unit is being used:
|
||||
{style="width:80%;display: block;margin: 0 auto;"}
|
||||
|
||||
```cpp
|
||||
inline constexpr struct origin1 : absolute_point_origin<origin1, isq::distance> {} origin1;
|
||||
inline constexpr struct origin2 : absolute_point_origin<origin2, isq::distance> {} origin2;
|
||||
inline constexpr struct origin1 final : absolute_point_origin<isq::distance> {} origin1;
|
||||
inline constexpr struct origin2 final : absolute_point_origin<isq::distance> {} origin2;
|
||||
|
||||
quantity_point qp1 = origin1 + 100 * m;
|
||||
quantity_point qp2 = origin2 + 120 * m;
|
||||
@@ -284,10 +276,10 @@ For such cases, relative point origins should be used:
|
||||
{style="width:80%;display: block;margin: 0 auto;"}
|
||||
|
||||
```cpp
|
||||
inline constexpr struct A : absolute_point_origin<A, isq::distance> {} A;
|
||||
inline constexpr struct B : relative_point_origin<A + 10 * m> {} B;
|
||||
inline constexpr struct C : relative_point_origin<B + 10 * m> {} C;
|
||||
inline constexpr struct D : relative_point_origin<A + 30 * m> {} D;
|
||||
inline constexpr struct A final : absolute_point_origin<isq::distance> {} A;
|
||||
inline constexpr struct B final : relative_point_origin<A + 10 * m> {} B;
|
||||
inline constexpr struct C final : relative_point_origin<B + 10 * m> {} C;
|
||||
inline constexpr struct D final : relative_point_origin<A + 30 * m> {} D;
|
||||
|
||||
quantity_point qp1 = C + 100 * m;
|
||||
quantity_point qp2 = D + 120 * m;
|
||||
@@ -392,17 +384,17 @@ point origins for this purpose:
|
||||
```cpp
|
||||
namespace si {
|
||||
|
||||
inline constexpr struct absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr struct zeroth_kelvin : decltype(absolute_zero) {} zeroth_kelvin;
|
||||
inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr auto zeroth_kelvin = absolute_zero;
|
||||
|
||||
inline constexpr struct ice_point : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
|
||||
inline constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius;
|
||||
inline constexpr struct ice_point final : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
|
||||
inline constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
|
||||
}
|
||||
|
||||
namespace usc {
|
||||
|
||||
inline constexpr struct zeroth_degree_Fahrenheit :
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final :
|
||||
relative_point_origin<quantity_point{-32 * (mag_ratio<5, 9> * si::degree_Celsius)}> {} zeroth_degree_Fahrenheit;
|
||||
|
||||
}
|
||||
@@ -481,7 +473,7 @@ the following way:
|
||||
{style="width:80%;display: block;margin: 0 auto;"}
|
||||
|
||||
```cpp
|
||||
constexpr struct room_reference_temp : relative_point_origin<quantity_point{21 * deg_C}> {} room_reference_temp;
|
||||
constexpr struct room_reference_temp final : relative_point_origin<quantity_point{21 * deg_C}> {} room_reference_temp;
|
||||
using room_temp = quantity_point<isq::Celsius_temperature[deg_C], room_reference_temp>;
|
||||
|
||||
constexpr auto step_delta = isq::Celsius_temperature(0.5 * deg_C);
|
||||
|
||||
Reference in New Issue
Block a user