Skip to content

Commit

Permalink
fix: inline restored for non-template constexpr global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Sep 5, 2024
1 parent 2e840cf commit 45013f6
Show file tree
Hide file tree
Showing 63 changed files with 1,634 additions and 1,632 deletions.
18 changes: 9 additions & 9 deletions docs/blog/posts/2.1.0-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ As a side effect, we introduced a :boom: **breaking change** :boom:. We can't us
hertz anymore:

```cpp
constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of<isq::frequency>> {} hertz;
inline constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of<isq::frequency>> {} hertz;
```
and have to type either:
```cpp
constexpr struct hertz : named_unit<"Hz", one / second, kind_of<isq::frequency>> {} hertz;
inline constexpr struct hertz : named_unit<"Hz", one / second, kind_of<isq::frequency>> {} hertz;
```

or

```cpp
constexpr struct hertz : named_unit<"Hz", inverse(second), kind_of<isq::frequency>> {} hertz;
inline 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
Expand All @@ -70,13 +70,13 @@ specifications definitions. Now, to define a _frequency_ we have to type:
=== "C++23"
```cpp
constexpr struct frequency : quantity_spec<inverse(period_duration)> {} frequency;
inline constexpr struct frequency : quantity_spec<inverse(period_duration)> {} frequency;
```
=== "C++20"
```cpp
constexpr struct frequency : quantity_spec<frequency, inverse(period_duration)> {} frequency;
inline constexpr struct frequency : quantity_spec<frequency, inverse(period_duration)> {} frequency;
```
=== "Portable"
Expand Down Expand Up @@ -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
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 absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
inline constexpr struct zeroth_kelvin : decltype(absolute_zero) {} zeroth_kelvin;

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;
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;
```
Please note that this is a :boom: **breaking change** :boom: as well.
Expand Down
46 changes: 23 additions & 23 deletions docs/blog/posts/2.2.0-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,21 @@ is why it was renamed to `symbol_text` (:boom: **breaking change** :boom:).
=== "Now"

```cpp
constexpr struct ohm final : named_unit<symbol_text{u8"Ω", "ohm"}, volt / ampere> {} ohm;
inline constexpr struct ohm final : named_unit<symbol_text{u8"Ω", "ohm"}, volt / ampere> {} ohm;
```

=== "Before"

```cpp
constexpr struct ohm : named_unit<basic_symbol_text{"Ω", "ohm"}, volt / ampere> {} ohm;
inline constexpr struct ohm : named_unit<basic_symbol_text{"Ω", "ohm"}, volt / ampere> {} ohm;
```

!!! note

On C++20-compliant compilers it should be enough to type the following in the unit's definition:

```cpp
constexpr struct ohm final : named_unit<{u8"Ω", "ohm"}, volt / ampere> {} ohm;
inline constexpr struct ohm final : named_unit<{u8"Ω", "ohm"}, volt / ampere> {} ohm;
```


Expand All @@ -307,31 +307,31 @@ marked `final` (:boom: **breaking change** :boom:).
=== "Now"

```cpp
constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
constexpr struct length final : quantity_spec<dim_length> {} length;
inline constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
inline constexpr struct length final : quantity_spec<dim_length> {} length;

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 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 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;
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;
```

=== "Before"

```cpp
constexpr struct dim_length : base_dimension<"L"> {} dim_length;
constexpr struct length : quantity_spec<dim_length> {} length;
inline constexpr struct dim_length : base_dimension<"L"> {} dim_length;
inline constexpr struct length : quantity_spec<dim_length> {} length;

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 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 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;
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;
```

Please also note, that the `absolute_point_origin` does not use CRTP idiom anymore (:boom: **breaking change** :boom:).
Expand Down Expand Up @@ -509,13 +509,13 @@ conversion factor. Here is a comparison of the code with previous and current de
=== "Now"

```cpp
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;
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;
```

=== "Before"

```cpp
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;
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;
```
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The library source code is hosted on [GitHub](https://github.com/mpusz/mp-units)

using namespace mp_units;

constexpr struct smoot final : named_unit<"smoot", mag<67> * usc::inch> {} smoot;
inline constexpr struct smoot final : named_unit<"smoot", mag<67> * usc::inch> {} smoot;

int main()
{
Expand All @@ -53,7 +53,7 @@ The library source code is hosted on [GitHub](https://github.com/mpusz/mp-units)

using namespace mp_units;

constexpr struct smoot final : named_unit<"smoot", mag<67> * usc::inch> {} smoot;
inline constexpr struct smoot final : named_unit<"smoot", mag<67> * usc::inch> {} smoot;

int main()
{
Expand Down
12 changes: 6 additions & 6 deletions docs/users_guide/framework_basics/character_of_a_quantity.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ enumeration can be appended to the `quantity_spec` describing such a quantity ty
=== "C++23"

```cpp
constexpr struct position_vector final : quantity_spec<length, quantity_character::vector> {} position_vector;
constexpr struct displacement final : quantity_spec<length, quantity_character::vector> {} displacement;
inline constexpr struct position_vector final : quantity_spec<length, quantity_character::vector> {} position_vector;
inline constexpr struct displacement final : quantity_spec<length, quantity_character::vector> {} displacement;
```

=== "C++20"

```cpp
constexpr struct position_vector final : quantity_spec<position_vector, length, quantity_character::vector> {} position_vector;
constexpr struct displacement final : quantity_spec<displacement, length, quantity_character::vector> {} displacement;
inline constexpr struct position_vector final : quantity_spec<position_vector, length, quantity_character::vector> {} position_vector;
inline constexpr struct displacement final : quantity_spec<displacement, length, quantity_character::vector> {} displacement;
```

=== "Portable"
Expand All @@ -126,13 +126,13 @@ character override is needed):
=== "C++23"

```cpp
constexpr struct velocity final : quantity_spec<speed, position_vector / duration> {} velocity;
inline constexpr struct velocity final : quantity_spec<speed, position_vector / duration> {} velocity;
```

=== "C++20"

```cpp
constexpr struct velocity final : quantity_spec<velocity, speed, position_vector / duration> {} velocity;
inline constexpr struct velocity final : quantity_spec<velocity, speed, position_vector / duration> {} velocity;
```

=== "Portable"
Expand Down
2 changes: 1 addition & 1 deletion docs/users_guide/framework_basics/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ implicitly convertible from quantity specification `V`, which means that `V` mus
However, if we define `mean_sea_level` in the following way:

```cpp
constexpr struct mean_sea_level final : 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
Expand Down
44 changes: 22 additions & 22 deletions docs/users_guide/framework_basics/design_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ For example:
the following way:

```cpp
constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
constexpr struct dim_time final : base_dimension<"T"> {} dim_time;
inline constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
inline constexpr struct dim_time final : base_dimension<"T"> {} dim_time;
```
[Derived dimensions](../../appendix/glossary.md#derived-dimension) are implicitly created
Expand All @@ -71,19 +71,19 @@ provided in the [quantity specification](../../appendix/glossary.md#quantity_spe
=== "C++23"
```cpp
constexpr struct length final : quantity_spec<dim_length> {} length;
constexpr struct time final : quantity_spec<dim_time> {} time;
constexpr struct speed final : quantity_spec<length / time> {} speed;
inline constexpr struct length final : quantity_spec<dim_length> {} length;
inline constexpr struct time final : quantity_spec<dim_time> {} time;
inline constexpr struct speed final : quantity_spec<length / time> {} speed;
static_assert(speed.dimension == dim_length / dim_time);
```
=== "C++20"
```cpp
constexpr struct length final : quantity_spec<length, dim_length> {} length;
constexpr struct time final : quantity_spec<time, dim_time> {} time;
constexpr struct speed final : quantity_spec<speed, length / time> {} speed;
inline constexpr struct length final : quantity_spec<length, dim_length> {} length;
inline constexpr struct time final : quantity_spec<time, dim_time> {} time;
inline constexpr struct speed final : quantity_spec<speed, length / time> {} speed;
static_assert(speed.dimension == dim_length / dim_time);
```
Expand Down Expand Up @@ -183,17 +183,17 @@ Quantity specification can be defined by the user in one of the following ways:
=== "C++23"
```cpp
constexpr struct length final : quantity_spec<dim_length> {} length;
constexpr struct height final : quantity_spec<length> {} height;
constexpr struct speed final : quantity_spec<length / time> {} speed;
inline constexpr struct length final : quantity_spec<dim_length> {} length;
inline constexpr struct height final : quantity_spec<length> {} height;
inline constexpr struct speed final : quantity_spec<length / time> {} speed;
```
=== "C++20"
```cpp
constexpr struct length final : quantity_spec<length, dim_length> {} length;
constexpr struct height final : quantity_spec<height, length> {} height;
constexpr struct speed final : quantity_spec<speed, length / time> {} speed;
inline constexpr struct length final : quantity_spec<length, dim_length> {} length;
inline constexpr struct height final : quantity_spec<height, length> {} height;
inline constexpr struct speed final : quantity_spec<speed, length / time> {} speed;
```
=== "Portable"
Expand Down Expand Up @@ -234,13 +234,13 @@ A unit can be defined by the user in one of the following ways:
template<PrefixableUnit U> struct kilo_ : prefixed_unit<"k", mag_power<10, 3>, U{}> {};
template<PrefixableUnit auto U> constexpr kilo_<decltype(U)> kilo;
constexpr struct second final : named_unit<"s", kind_of<isq::time>> {} second;
constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
constexpr struct gram final : named_unit<"g", kind_of<isq::mass>> {} gram;
constexpr auto kilogram = kilo<gram>;
constexpr struct newton final : named_unit<"N", kilogram * metre / square(second)> {} newton;
inline constexpr struct second final : named_unit<"s", kind_of<isq::time>> {} second;
inline constexpr struct minute final : named_unit<"min", mag<60> * second> {} minute;
inline constexpr struct gram final : named_unit<"g", kind_of<isq::mass>> {} gram;
inline constexpr auto kilogram = kilo<gram>;
inline constexpr struct newton final : named_unit<"N", kilogram * metre / square(second)> {} newton;
constexpr struct speed_of_light_in_vacuum final : named_unit<"c", mag<299'792'458> * metre / second> {} speed_of_light_in_vacuum;
inline constexpr struct speed_of_light_in_vacuum final : named_unit<"c", mag<299'792'458> * metre / second> {} speed_of_light_in_vacuum;
```

The [unit equation](../../appendix/glossary.md#unit-equation) of `si::metre / si::second` results
Expand Down Expand Up @@ -346,13 +346,13 @@ For example:
- the absolute point origin can be defined in the following way:

```cpp
constexpr struct absolute_zero final : 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
constexpr struct ice_point final : 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;
```


Expand Down
28 changes: 14 additions & 14 deletions docs/users_guide/framework_basics/dimensionless_quantities.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ that uses a unit that is proportional to the ratio of kilometers per megaparsecs
units of _length_:
```cpp
constexpr struct hubble_constant final :
inline constexpr struct hubble_constant final :
named_unit<{u8"H₀", "H_0"}, mag_ratio<701, 10> * si::kilo<si::metre> / si::second / si::mega<parsec>> {} hubble_constant;
```

Expand Down Expand Up @@ -158,10 +158,10 @@ Besides the unit `one`, there are a few other scaled units predefined in the lib
with dimensionless quantities:

```cpp
constexpr struct percent final : named_unit<"%", mag_ratio<1, 100> * one> {} percent;
constexpr struct per_mille final : named_unit<{u8"‰", "%o"}, mag_ratio<1, 1000> * one> {} per_mille;
constexpr struct parts_per_million final : named_unit<"ppm", mag_ratio<1, 1'000'000> * one> {} parts_per_million;
constexpr auto ppm = parts_per_million;
inline constexpr struct percent final : named_unit<"%", mag_ratio<1, 100> * one> {} percent;
inline constexpr struct per_mille final : named_unit<{u8"‰", "%o"}, mag_ratio<1, 1000> * one> {} per_mille;
inline constexpr struct parts_per_million final : named_unit<"ppm", mag_ratio<1, 1'000'000> * one> {} parts_per_million;
inline constexpr auto ppm = parts_per_million;
```
### Superpowers of the unit `one`
Expand Down Expand Up @@ -271,17 +271,17 @@ to the quantity specification:
=== "C++23"

```cpp
constexpr struct angular_measure final : quantity_spec<dimensionless, arc_length / radius, is_kind> {} angular_measure;
constexpr struct solid_angular_measure final : quantity_spec<dimensionless, area / pow<2>(radius), is_kind> {} solid_angular_measure;
constexpr struct storage_capacity final : quantity_spec<dimensionless, is_kind> {} storage_capacity;
inline constexpr struct angular_measure final : quantity_spec<dimensionless, arc_length / radius, is_kind> {} angular_measure;
inline constexpr struct solid_angular_measure final : quantity_spec<dimensionless, area / pow<2>(radius), is_kind> {} solid_angular_measure;
inline constexpr struct storage_capacity final : quantity_spec<dimensionless, is_kind> {} storage_capacity;
```

=== "C++20"

```cpp
constexpr struct angular_measure final : quantity_spec<angular_measure, dimensionless, arc_length / radius, is_kind> {} angular_measure;
constexpr struct solid_angular_measure final : quantity_spec<solid_angular_measure, dimensionless, area / pow<2>(radius), is_kind> {} solid_angular_measure;
constexpr struct storage_capacity final : quantity_spec<storage_capacity, dimensionless, is_kind> {} storage_capacity;
inline constexpr struct angular_measure final : quantity_spec<angular_measure, dimensionless, arc_length / radius, is_kind> {} angular_measure;
inline constexpr struct solid_angular_measure final : quantity_spec<solid_angular_measure, dimensionless, area / pow<2>(radius), is_kind> {} solid_angular_measure;
inline constexpr struct storage_capacity final : quantity_spec<storage_capacity, dimensionless, is_kind> {} storage_capacity;
```

=== "Portable"
Expand All @@ -296,9 +296,9 @@ With the above, we can constrain `radian`, `steradian`, and `bit` to be allowed
specific quantity kinds only:

```cpp
constexpr struct radian final : named_unit<"rad", metre / metre, kind_of<isq::angular_measure>> {} radian;
constexpr struct steradian final : named_unit<"sr", square(metre) / square(metre), kind_of<isq::solid_angular_measure>> {} steradian;
constexpr struct bit final : named_unit<"bit", one, kind_of<storage_capacity>> {} bit;
inline constexpr struct radian final : named_unit<"rad", metre / metre, kind_of<isq::angular_measure>> {} radian;
inline constexpr struct steradian final : named_unit<"sr", square(metre) / square(metre), kind_of<isq::solid_angular_measure>> {} steradian;
inline constexpr struct bit final : named_unit<"bit", one, kind_of<storage_capacity>> {} bit;
```
but still allow the usage of `one` and its scaled versions for such quantities.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ namespace si {

namespace si2019 {

constexpr struct speed_of_light_in_vacuum final :
inline constexpr struct speed_of_light_in_vacuum final :
named_unit<"c", mag<299'792'458> * metre / second> {} speed_of_light_in_vacuum;

} // namespace si2019

constexpr struct magnetic_constant final :
inline constexpr struct magnetic_constant final :
named_unit<{u8"μ₀", "u_0"}, mag<4> * mag_pi * mag_power<10, -7> * henry / metre> {} magnetic_constant;

} // namespace mp_units::si
Expand Down
Loading

0 comments on commit 45013f6

Please sign in to comment.