fix: inline restored for non-template constexpr global variables

This commit is contained in:
Mateusz Pusz
2024-09-05 10:06:43 +02:00
parent 2e840cfdb4
commit 45013f6752
63 changed files with 1591 additions and 1589 deletions

View File

@@ -42,9 +42,9 @@ using namespace mp_units;
using namespace mp_units::angular;
using namespace mp_units::angular::unit_symbols;
constexpr struct half_revolution final : named_unit<"hrev", mag_pi * radian> {
inline constexpr struct half_revolution final : named_unit<"hrev", mag_pi * radian> {
} half_revolution;
constexpr auto hrev = half_revolution;
inline constexpr auto hrev = half_revolution;
// constexpr auto revb6 = mag_ratio<1,3> * mag_pi * rad;

View File

@@ -44,12 +44,12 @@ namespace {
using namespace mp_units;
constexpr struct my_origin final : absolute_point_origin<isq::length> {
inline constexpr struct my_origin final : absolute_point_origin<isq::length> {
} my_origin;
constexpr struct my_relative_origin final : relative_point_origin<my_origin + isq::length(42 * si::metre)> {
inline constexpr struct my_relative_origin final : relative_point_origin<my_origin + isq::length(42 * si::metre)> {
} my_relative_origin;
constexpr auto dim_speed = isq::dim_length / isq::dim_time;
inline constexpr auto dim_speed = isq::dim_length / isq::dim_time;
// BaseDimension
static_assert(detail::BaseDimension<struct isq::dim_length>);
@@ -78,7 +78,7 @@ static_assert(!Dimension<int>);
// TODO add tests
// QuantitySpec
constexpr auto speed = isq::length / isq::time;
inline constexpr auto speed = isq::length / isq::time;
static_assert(QuantitySpec<struct isq::length>);
static_assert(QuantitySpec<struct isq::radius>);

View File

@@ -36,31 +36,31 @@ using namespace mp_units;
using dimension_one_ = struct dimension_one;
// clang-format off
constexpr struct length_ final : base_dimension<"L"> {} length;
constexpr struct mass_ final : base_dimension<"M"> {} mass;
constexpr struct time_ final : base_dimension<"T"> {} time;
inline constexpr struct length_ final : base_dimension<"L"> {} length;
inline constexpr struct mass_ final : base_dimension<"M"> {} mass;
inline constexpr struct time_ final : base_dimension<"T"> {} time;
constexpr auto my_length1 = length;
constexpr auto my_length2 = length;
inline constexpr auto my_length1 = length;
inline constexpr auto my_length2 = length;
QUANTITY_SPEC_(q_time, time);
constexpr struct second_ final : named_unit<"s", kind_of<q_time>> {} second;
inline constexpr struct second_ final : named_unit<"s", kind_of<q_time>> {} second;
constexpr auto frequency = inverse(time);
constexpr auto action = inverse(time);
constexpr auto area = length * length;
constexpr auto volume = area * length;
constexpr auto speed = length / time;
constexpr auto acceleration = speed / time;
constexpr auto force = mass * acceleration;
constexpr auto moment_of_force = length * force;
constexpr auto torque = moment_of_force;
constexpr auto pressure = force / area;
constexpr auto stress = pressure;
constexpr auto strain = stress / stress;
constexpr auto power = force * speed;
constexpr auto efficiency = power / power;
constexpr auto energy = force * length;
inline constexpr auto frequency = inverse(time);
inline constexpr auto action = inverse(time);
inline constexpr auto area = length * length;
inline constexpr auto volume = area * length;
inline constexpr auto speed = length / time;
inline constexpr auto acceleration = speed / time;
inline constexpr auto force = mass * acceleration;
inline constexpr auto moment_of_force = length * force;
inline constexpr auto torque = moment_of_force;
inline constexpr auto pressure = force / area;
inline constexpr auto stress = pressure;
inline constexpr auto strain = stress / stress;
inline constexpr auto power = force * speed;
inline constexpr auto efficiency = power / power;
inline constexpr auto energy = force * length;
// clang-format on
// concepts verification

View File

@@ -71,11 +71,11 @@ namespace {
// CHECK(round_trip == R);
// }
constexpr struct mag_2_ : magnitude<2> {
inline constexpr struct mag_2_ : magnitude<2> {
} mag_2;
// constexpr struct mag_2_other : magnitude<2> {
// inline constexpr struct mag_2_other : magnitude<2> {
// } mag_2_other;
// constexpr struct mag_3 : magnitude<2> {
// inline constexpr struct mag_3 : magnitude<2> {
// } mag_3;
// concepts verification

View File

@@ -50,38 +50,38 @@ using namespace std::chrono_literals;
using sys_seconds = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>;
#endif
constexpr struct zeroth_length final : absolute_point_origin<isq::length> {
inline constexpr struct zeroth_length final : absolute_point_origin<isq::length> {
} zeroth_length;
constexpr struct mean_sea_level final : absolute_point_origin<isq::height> {
inline constexpr struct mean_sea_level final : absolute_point_origin<isq::height> {
} mean_sea_level;
constexpr auto my_mean_sea_level = mean_sea_level;
inline constexpr auto my_mean_sea_level = mean_sea_level;
constexpr struct same_mean_sea_level final : relative_point_origin<mean_sea_level + 0 * isq::height[m]> {
inline constexpr struct same_mean_sea_level final : relative_point_origin<mean_sea_level + 0 * isq::height[m]> {
} same_mean_sea_level;
constexpr struct ground_level final : relative_point_origin<mean_sea_level + 42 * isq::height[m]> {
inline constexpr struct ground_level final : relative_point_origin<mean_sea_level + 42 * isq::height[m]> {
} ground_level;
constexpr auto my_ground_level = ground_level;
inline constexpr auto my_ground_level = ground_level;
constexpr struct same_ground_level1 final : relative_point_origin<mean_sea_level + 42 * isq::height[m]> {
inline constexpr struct same_ground_level1 final : relative_point_origin<mean_sea_level + 42 * isq::height[m]> {
} same_ground_level1;
constexpr struct same_ground_level2 final : relative_point_origin<my_mean_sea_level + 42 * isq::height[m]> {
inline constexpr struct same_ground_level2 final : relative_point_origin<my_mean_sea_level + 42 * isq::height[m]> {
} same_ground_level2;
constexpr struct tower_peak final : relative_point_origin<ground_level + 42 * isq::height[m]> {
inline constexpr struct tower_peak final : relative_point_origin<ground_level + 42 * isq::height[m]> {
} tower_peak;
constexpr struct other_ground_level final : relative_point_origin<mean_sea_level + 123 * isq::height[m]> {
inline constexpr struct other_ground_level final : relative_point_origin<mean_sea_level + 123 * isq::height[m]> {
} other_ground_level;
constexpr struct other_absolute_level final : absolute_point_origin<isq::height> {
inline constexpr struct other_absolute_level final : absolute_point_origin<isq::height> {
} other_absolute_level;
constexpr struct zero final : absolute_point_origin<dimensionless> {
inline constexpr struct zero final : absolute_point_origin<dimensionless> {
} zero;
QUANTITY_SPEC(special_height, isq::height);
@@ -122,7 +122,7 @@ static_assert(relative_po<absolute_po<isq::length> + isq::height(42 * m)>.quanti
static_assert(relative_po<absolute_po<kind_of<isq::length>> + isq::height(42 * m)>.quantity_spec == isq::height);
static_assert(relative_po<absolute_po<isq::height> + 42 * m>.quantity_spec == isq::height);
constexpr struct my_kelvin final : named_unit<"my_K", mag<10> * si::kelvin> {
inline constexpr struct my_kelvin final : named_unit<"my_K", mag<10> * si::kelvin> {
} my_kelvin;
static_assert(default_point_origin(si::kelvin) == si::absolute_zero);
@@ -1516,7 +1516,7 @@ static_assert(ground_level - other_ground_level == -81 * m);
static_assert(other_ground_level - tower_peak == 39 * m);
static_assert(tower_peak - other_ground_level == -39 * m);
constexpr struct zero_m_per_s final : absolute_point_origin<kind_of<isq::speed>> {
inline constexpr struct zero_m_per_s final : absolute_point_origin<kind_of<isq::speed>> {
} zero_m_per_s;
// commutativity and associativity
@@ -1604,7 +1604,7 @@ static_assert(
is_of_type<quantity_point{10 * isq::height[m] / (2 * isq::time[s])} + (10 * isq::height[m] / (2 * isq::time[s])),
quantity_point<(isq::height / isq::time)[m / s], zeroth_point_origin<isq::height / isq::time>, int>>);
constexpr struct zero_Hz final : absolute_point_origin<kind_of<isq::frequency>> {
inline constexpr struct zero_Hz final : absolute_point_origin<kind_of<isq::frequency>> {
} zero_Hz;
static_assert(((zero_Hz + 10 / (2 * isq::period_duration[s])) + 5 * isq::frequency[Hz]).quantity_from(zero_Hz) ==
@@ -1688,7 +1688,7 @@ consteval bool invalid_subtraction(Ts... ts)
return !requires { (... - ts); };
}
constexpr struct zero_Bq final : absolute_point_origin<kind_of<isq::activity>> {
inline constexpr struct zero_Bq final : absolute_point_origin<kind_of<isq::activity>> {
} zero_Bq;
static_assert(invalid_addition(zero_Bq + 5 * isq::activity[Bq], 5 * isq::frequency[Hz]));

View File

@@ -37,22 +37,22 @@ using dimensionless_ = struct dimensionless;
using dim_one_ = struct dimension_one;
// clang-format off
constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length;
constexpr struct dim_mass_ final : base_dimension<"M"> {} dim_mass;
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_mass_ final : base_dimension<"M"> {} dim_mass;
inline constexpr struct dim_time_ final : base_dimension<"T"> {} dim_time;
// quantities specification
QUANTITY_SPEC_(length, dim_length);
QUANTITY_SPEC_(mass, dim_mass);
QUANTITY_SPEC_(time, dim_time);
constexpr struct second_ final : named_unit<"s", kind_of<time>> {} second;
inline constexpr struct second_ final : named_unit<"s", kind_of<time>> {} second;
QUANTITY_SPEC_(height, length);
QUANTITY_SPEC_(width, length);
QUANTITY_SPEC_(radius, width);
QUANTITY_SPEC_(path_length, length);
constexpr auto arc_length = path_length;
inline constexpr auto arc_length = path_length;
QUANTITY_SPEC_(distance, path_length);
QUANTITY_SPEC_(position_vector, length, quantity_character::vector);
QUANTITY_SPEC_(period_duration, time);

View File

@@ -39,9 +39,9 @@ using one_ = struct one;
// base dimensions
// clang-format off
constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length;
constexpr struct dim_mass_ final : base_dimension<"M"> {} dim_mass;
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_mass_ final : base_dimension<"M"> {} dim_mass;
inline constexpr struct dim_time_ final : base_dimension<"T"> {} dim_time;
// quantities specification
QUANTITY_SPEC_(length, dim_length);
@@ -64,37 +64,37 @@ QUANTITY_SPEC_(power, force* speed);
QUANTITY_SPEC_(storage_capacity, dimensionless, is_kind);
// base units
constexpr struct second_ final : named_unit<"s", kind_of<time>> {} second;
constexpr struct metre_ final : named_unit<"m", kind_of<length>> {} metre;
constexpr struct gram_ final : named_unit<"g", kind_of<mass>> {} gram;
constexpr auto kilogram = si::kilo<gram>;
inline constexpr struct second_ final : named_unit<"s", kind_of<time>> {} second;
inline constexpr struct metre_ final : named_unit<"m", kind_of<length>> {} metre;
inline constexpr struct gram_ final : named_unit<"g", kind_of<mass>> {} gram;
inline constexpr auto kilogram = si::kilo<gram>;
namespace nu {
// hypothetical natural system of units for c=1
constexpr struct second_ final : named_unit<"s"> {} second;
constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
inline constexpr struct second_ final : named_unit<"s"> {} second;
inline constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
constexpr struct time : system_reference<time_{}, second> {} time;
constexpr struct length : system_reference<length_{}, second> {} length;
constexpr struct speed : system_reference<speed_{}, second / second> {} speed;
inline constexpr struct time : system_reference<time_{}, second> {} time;
inline constexpr struct length : system_reference<length_{}, second> {} length;
inline constexpr struct speed : system_reference<speed_{}, second / second> {} speed;
}
// derived named units
constexpr struct radian_ final : named_unit<"rad", metre / metre, kind_of<angular_measure>> {} radian;
constexpr struct steradian_ final : named_unit<"sr", square(metre) / square(metre), kind_of<solid_angular_measure>> {} steradian;
constexpr struct hertz_ final : named_unit<"Hz", inverse(second), kind_of<frequency>> {} hertz;
constexpr struct becquerel_ final : named_unit<"Bq", inverse(second), kind_of<activity>> {} becquerel;
constexpr struct newton_ final : named_unit<"N", kilogram * metre / square(second)> {} newton;
constexpr struct joule_ final : named_unit<"J", newton * metre> {} joule;
constexpr struct watt_ final : named_unit<"W", joule / second> {} watt;
inline constexpr struct radian_ final : named_unit<"rad", metre / metre, kind_of<angular_measure>> {} radian;
inline constexpr struct steradian_ final : named_unit<"sr", square(metre) / square(metre), kind_of<solid_angular_measure>> {} steradian;
inline constexpr struct hertz_ final : named_unit<"Hz", inverse(second), kind_of<frequency>> {} hertz;
inline constexpr struct becquerel_ final : named_unit<"Bq", inverse(second), kind_of<activity>> {} becquerel;
inline constexpr struct newton_ final : named_unit<"N", kilogram * metre / square(second)> {} newton;
inline constexpr struct joule_ final : named_unit<"J", newton * metre> {} joule;
inline constexpr struct watt_ final : named_unit<"W", joule / second> {} watt;
constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
constexpr struct hour_ final : named_unit<"h", mag<60> * minute> {} hour;
constexpr auto kilometre = si::kilo<metre>;
inline constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
inline constexpr struct hour_ final : named_unit<"h", mag<60> * minute> {} hour;
inline constexpr auto kilometre = si::kilo<metre>;
constexpr struct bit_ final : named_unit<"bit", one, kind_of<storage_capacity>> {} bit;
inline constexpr struct bit_ final : named_unit<"bit", one, kind_of<storage_capacity>> {} bit;
// clang-format on

View File

@@ -36,14 +36,14 @@ constexpr bool is_of_type = std::is_same_v<MP_UNITS_REMOVE_CONST(decltype(V)), T
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#if MP_UNITS_API_NO_CRTP
#define QUANTITY_SPEC_(name, ...) \
constexpr struct name##_ final : quantity_spec<__VA_ARGS__> { \
#define QUANTITY_SPEC_(name, ...) \
inline constexpr struct name##_ final : quantity_spec<__VA_ARGS__> { \
} name
#else
#define QUANTITY_SPEC_(name, ...) \
constexpr struct name##_ final : quantity_spec<name##_, __VA_ARGS__> { \
#define QUANTITY_SPEC_(name, ...) \
inline constexpr struct name##_ final : quantity_spec<name##_, __VA_ARGS__> { \
} name
#endif

View File

@@ -40,10 +40,10 @@ using percent_ = struct percent;
// base dimensions
// clang-format off
constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length;
constexpr struct dim_mass_ final : base_dimension<"M"> {} dim_mass;
constexpr struct dim_time_ final : base_dimension<"T"> {} dim_time;
constexpr struct dim_thermodynamic_temperature_ final : base_dimension<symbol_text{u8"Θ", "O"}> {} dim_thermodynamic_temperature;
inline constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length;
inline constexpr struct dim_mass_ final : base_dimension<"M"> {} dim_mass;
inline constexpr struct dim_time_ final : base_dimension<"T"> {} dim_time;
inline constexpr struct dim_thermodynamic_temperature_ final : base_dimension<symbol_text{u8"Θ", "O"}> {} dim_thermodynamic_temperature;
// quantities specification
QUANTITY_SPEC_(length, dim_length);
@@ -52,39 +52,39 @@ QUANTITY_SPEC_(time, dim_time);
QUANTITY_SPEC_(thermodynamic_temperature, dim_thermodynamic_temperature);
// base units
constexpr struct second_ final : named_unit<"s", kind_of<time>> {} second;
constexpr struct metre_ final : named_unit<"m", kind_of<length>> {} metre;
constexpr struct gram_ final : named_unit<"g", kind_of<mass>> {} gram;
constexpr auto kilogram = si::kilo<gram>;
constexpr struct kelvin_ final : named_unit<"K", kind_of<thermodynamic_temperature>> {} kelvin;
inline constexpr struct second_ final : named_unit<"s", kind_of<time>> {} second;
inline constexpr struct metre_ final : named_unit<"m", kind_of<length>> {} metre;
inline constexpr struct gram_ final : named_unit<"g", kind_of<mass>> {} gram;
inline constexpr auto kilogram = si::kilo<gram>;
inline constexpr struct kelvin_ final : named_unit<"K", kind_of<thermodynamic_temperature>> {} kelvin;
// hypothetical natural units for c=1
constexpr struct nu_second_ final : named_unit<"s"> {} nu_second;
inline constexpr struct nu_second_ final : named_unit<"s"> {} nu_second;
// derived named units
constexpr struct radian_ final : named_unit<"rad", metre / metre> {} radian;
constexpr struct steradian_ final : named_unit<"sr", square(metre) / square(metre)> {} steradian;
constexpr struct hertz_ final : named_unit<"Hz", inverse(second)> {} hertz;
constexpr struct becquerel_ final : named_unit<"Bq", inverse(second)> {} becquerel;
constexpr struct newton_ final : named_unit<"N", kilogram * metre / square(second)> {} newton;
constexpr struct pascal_ final : named_unit<"Pa", newton / square(metre)> {} pascal;
constexpr struct joule_ final : named_unit<"J", newton * metre> {} joule;
constexpr struct watt_ final : named_unit<"W", joule / second> {} watt;
constexpr struct degree_Celsius_ final : named_unit<symbol_text{u8"", "`C"}, kelvin> {} degree_Celsius;
inline constexpr struct radian_ final : named_unit<"rad", metre / metre> {} radian;
inline constexpr struct steradian_ final : named_unit<"sr", square(metre) / square(metre)> {} steradian;
inline constexpr struct hertz_ final : named_unit<"Hz", inverse(second)> {} hertz;
inline constexpr struct becquerel_ final : named_unit<"Bq", inverse(second)> {} becquerel;
inline constexpr struct newton_ final : named_unit<"N", kilogram * metre / square(second)> {} newton;
inline constexpr struct pascal_ final : named_unit<"Pa", newton / square(metre)> {} pascal;
inline constexpr struct joule_ final : named_unit<"J", newton * metre> {} joule;
inline constexpr struct watt_ final : named_unit<"W", joule / second> {} watt;
inline constexpr struct degree_Celsius_ final : named_unit<symbol_text{u8"", "`C"}, kelvin> {} degree_Celsius;
constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
constexpr struct hour_ final : named_unit<"h", mag<60> * minute> {} hour;
constexpr struct degree_ final : named_unit<symbol_text{u8"°", "deg"}, mag_pi / mag<180> * radian> {} degree;
inline constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
inline constexpr struct hour_ final : named_unit<"h", mag<60> * minute> {} hour;
inline constexpr struct degree_ final : named_unit<symbol_text{u8"°", "deg"}, mag_pi / mag<180> * radian> {} degree;
constexpr struct yard_ final : named_unit<"yd", mag_ratio<9'144, 10'000> * metre> {} yard;
constexpr struct mile_ final : named_unit<"mi", mag<1760> * yard> {} mile;
inline constexpr struct yard_ final : named_unit<"yd", mag_ratio<9'144, 10'000> * metre> {} yard;
inline constexpr struct mile_ final : named_unit<"mi", mag<1760> * yard> {} mile;
constexpr auto kilometre = si::kilo<metre>;
constexpr auto kilojoule = si::kilo<joule>;
inline constexpr auto kilometre = si::kilo<metre>;
inline constexpr auto kilojoule = si::kilo<joule>;
// physical constant units
constexpr struct standard_gravity_ final : named_unit<symbol_text{u8"g₀", "g_0"}, mag_ratio<980'665, 100'000> * metre / square(second)> {} standard_gravity;
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 standard_gravity_ final : named_unit<symbol_text{u8"g₀", "g_0"}, mag_ratio<980'665, 100'000> * metre / square(second)> {} standard_gravity;
inline constexpr struct speed_of_light_in_vacuum_ final : named_unit<"c", mag<299'792'458> * metre / second> {} speed_of_light_in_vacuum;
// clang-format on