mirror of
https://github.com/mpusz/mp-units.git
synced 2026-05-05 12:24:15 +02:00
refactor: Repetitive inline constexpr removed as no longer needed
Not needed anymore as stated in cplusplus/draft#4601
This commit is contained in:
@@ -49,19 +49,19 @@ As a side effect, we introduced a :boom: **breaking change** :boom:. We can't us
|
||||
hertz anymore:
|
||||
|
||||
```cpp
|
||||
inline constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of<isq::frequency>> {} hertz;
|
||||
constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of<isq::frequency>> {} hertz;
|
||||
```
|
||||
|
||||
and have to type either:
|
||||
|
||||
```cpp
|
||||
inline constexpr struct hertz : named_unit<"Hz", one / second, kind_of<isq::frequency>> {} hertz;
|
||||
constexpr struct hertz : named_unit<"Hz", one / second, kind_of<isq::frequency>> {} hertz;
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```cpp
|
||||
inline constexpr struct hertz : named_unit<"Hz", inverse(second), kind_of<isq::frequency>> {} hertz;
|
||||
constexpr struct hertz : named_unit<"Hz", inverse(second), kind_of<isq::frequency>> {} hertz;
|
||||
```
|
||||
|
||||
To be consistent, we applied the same change to the dimensions and quantity
|
||||
@@ -70,13 +70,13 @@ specifications definitions. Now, to define a _frequency_ we have to type:
|
||||
=== "C++23"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct frequency : quantity_spec<inverse(period_duration)> {} frequency;
|
||||
constexpr struct frequency : quantity_spec<inverse(period_duration)> {} frequency;
|
||||
```
|
||||
|
||||
=== "C++20"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct frequency : quantity_spec<frequency, inverse(period_duration)> {} frequency;
|
||||
constexpr struct frequency : quantity_spec<frequency, inverse(period_duration)> {} frequency;
|
||||
```
|
||||
|
||||
=== "Portable"
|
||||
@@ -145,11 +145,11 @@ If we derive from the same instantiation of `absolute_point_origin` we end up wi
|
||||
point origin. This change allows us to provide different names for the same temperature points:
|
||||
|
||||
```cpp
|
||||
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;
|
||||
constexpr struct absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
|
||||
constexpr struct zeroth_kelvin : decltype(absolute_zero) {} zeroth_kelvin;
|
||||
|
||||
inline constexpr struct ice_point : relative_point_origin<absolute_zero + 273.15 * kelvin> {} ice_point;
|
||||
inline constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius;
|
||||
constexpr struct ice_point : relative_point_origin<absolute_zero + 273.15 * kelvin> {} ice_point;
|
||||
constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius;
|
||||
```
|
||||
|
||||
Please note that this is a :boom: **breaking change** :boom: as well.
|
||||
|
||||
@@ -281,13 +281,13 @@ is why it was renamed to `symbol_text` (:boom: **breaking change** :boom:).
|
||||
=== "Now"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct ohm final : named_unit<symbol_text{u8"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
constexpr struct ohm final : named_unit<symbol_text{u8"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
```
|
||||
|
||||
=== "Before"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct ohm : named_unit<basic_symbol_text{"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
constexpr struct ohm : named_unit<basic_symbol_text{"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
```
|
||||
|
||||
!!! note
|
||||
@@ -295,7 +295,7 @@ is why it was renamed to `symbol_text` (:boom: **breaking change** :boom:).
|
||||
On C++20-compliant compilers it should be enough to type the following in the unit's definition:
|
||||
|
||||
```cpp
|
||||
inline constexpr struct ohm final : named_unit<{u8"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
constexpr struct ohm final : named_unit<{u8"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
```
|
||||
|
||||
|
||||
@@ -307,31 +307,31 @@ marked `final` (:boom: **breaking change** :boom:).
|
||||
=== "Now"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
|
||||
inline constexpr struct length final : quantity_spec<dim_length> {} length;
|
||||
constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
|
||||
constexpr struct length final : quantity_spec<dim_length> {} length;
|
||||
|
||||
inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
inline constexpr auto zeroth_kelvin = absolute_zero;
|
||||
inline constexpr struct kelvin final : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;
|
||||
constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
|
||||
constexpr auto zeroth_kelvin = absolute_zero;
|
||||
constexpr struct kelvin final : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;
|
||||
|
||||
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;
|
||||
inline constexpr struct degree_Celsius final : named_unit<symbol_text{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
constexpr struct ice_point final : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
|
||||
constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
constexpr struct degree_Celsius final : named_unit<symbol_text{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
```
|
||||
|
||||
=== "Before"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct dim_length : base_dimension<"L"> {} dim_length;
|
||||
inline constexpr struct length : quantity_spec<dim_length> {} length;
|
||||
constexpr struct dim_length : base_dimension<"L"> {} dim_length;
|
||||
constexpr struct length : quantity_spec<dim_length> {} length;
|
||||
|
||||
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 kelvin : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;
|
||||
constexpr struct absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
|
||||
constexpr struct zeroth_kelvin : decltype(absolute_zero) {} zeroth_kelvin;
|
||||
constexpr struct kelvin : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;
|
||||
|
||||
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 degree_Celsius : named_unit<symbol_text{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
constexpr struct ice_point : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
|
||||
constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius;
|
||||
constexpr struct degree_Celsius : named_unit<symbol_text{u8"℃", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
```
|
||||
|
||||
Please also note, that the `absolute_point_origin` does not use CRTP idiom anymore (:boom: **breaking change** :boom:).
|
||||
@@ -509,13 +509,13 @@ conversion factor. Here is a comparison of the code with previous and current de
|
||||
=== "Now"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct yard final : named_unit<"yd", mag_ratio<9'144, 10'000> * si::metre> {} yard;
|
||||
inline constexpr struct foot final : named_unit<"ft", mag_ratio<1, 3> * yard> {} foot;
|
||||
constexpr struct yard final : named_unit<"yd", mag_ratio<9'144, 10'000> * si::metre> {} yard;
|
||||
constexpr struct foot final : named_unit<"ft", mag_ratio<1, 3> * yard> {} foot;
|
||||
```
|
||||
|
||||
=== "Before"
|
||||
|
||||
```cpp
|
||||
inline constexpr struct yard : named_unit<"yd", mag<ratio{9'144, 10'000}> * si::metre> {} yard;
|
||||
inline constexpr struct foot : named_unit<"ft", mag<ratio{1, 3}> * yard> {} foot;
|
||||
constexpr struct yard : named_unit<"yd", mag<ratio{9'144, 10'000}> * si::metre> {} yard;
|
||||
constexpr struct foot : named_unit<"ft", mag<ratio{1, 3}> * yard> {} foot;
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user