forked from mpusz/mp-units
refactor: square and cubic are now functions (not variable templates)
This commit is contained in:
@@ -78,7 +78,7 @@ inline constexpr bool is_specialization_of_scaled_unit<scaled_unit<M, U>> = true
|
||||
* inline constexpr struct second : named_unit<"s", time> {} second;
|
||||
* inline constexpr struct metre : named_unit<"m", length> {} metre;
|
||||
* inline constexpr struct hertz : named_unit<"Hz", 1 / second> {} hertz;
|
||||
* inline constexpr struct newton : named_unit<"N", kilogram * metre / square<second>> {} newton;
|
||||
* inline constexpr struct newton : named_unit<"N", kilogram * metre / square(second)> {} newton;
|
||||
* inline constexpr struct degree_Celsius : named_unit<basic_symbol_text{"°C", "`C"}, kelvin> {} degree_Celsius;
|
||||
* inline constexpr struct minute : named_unit<"min", mag<60> * second> {} minute;
|
||||
* @endcode
|
||||
@@ -180,7 +180,7 @@ struct named_unit<Symbol, U, QS> : std::remove_const_t<decltype(U)> {
|
||||
*
|
||||
* @code{.cpp}
|
||||
* inline constexpr struct standard_gravity_unit :
|
||||
* constant_unit<"g", mag<ratio{980'665, 100'000}> * metre / square<second>> {} standard_gravity_unit;
|
||||
* constant_unit<"g", mag<ratio{980'665, 100'000}> * metre / square(second)> {} standard_gravity_unit;
|
||||
* @endcode
|
||||
*
|
||||
* @note A common convention in this library is to assign the same name for a type and an object of this type.
|
||||
@@ -253,7 +253,7 @@ struct is_one : std::false_type {};
|
||||
* static_assert(is_of_type<metre * metre, derived_unit<power<metre, 2>>>);
|
||||
* static_assert(is_of_type<metre * second, derived_unit<metre, second>>);
|
||||
* static_assert(is_of_type<metre / second, derived_unit<metre, per<second>>>);
|
||||
* static_assert(is_of_type<metre / square<second>, derived_unit<metre, per<power<second, 2>>>>);
|
||||
* static_assert(is_of_type<metre / square(second), derived_unit<metre, per<power<second, 2>>>>);
|
||||
* static_assert(is_of_type<watt / joule, derived_unit<watt, per<joule>>>);
|
||||
* @endcode
|
||||
*
|
||||
@@ -564,18 +564,30 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Unit U>
|
||||
else
|
||||
return derived_unit<power<U, Num, Den>>{};
|
||||
} else if constexpr (detail::is_specialization_of_scaled_unit<U>) {
|
||||
return scaled_unit<pow<ratio{Num, Den}>(U::mag), std::remove_const_t<decltype(pow<Num, Den>(U::reference_unit))>>{};
|
||||
return scaled_unit<pow<Num, Den>(U::mag), std::remove_const_t<decltype(pow<Num, Den>(U::reference_unit))>>{};
|
||||
} else {
|
||||
return detail::expr_pow<Num, Den, derived_unit, struct one, detail::type_list_of_unit_less>(u);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper variable templates to create common powers
|
||||
template<Unit auto U>
|
||||
inline constexpr decltype(U * U) square;
|
||||
/**
|
||||
* @brief Computes the square power of a unit
|
||||
*
|
||||
* @param u Unit being the base of the operation
|
||||
*
|
||||
* @return Unit The result of computation
|
||||
*/
|
||||
[[nodiscard]] consteval Unit auto square(Unit auto u) { return pow<2>(u); }
|
||||
|
||||
/**
|
||||
* @brief Computes the cubic power of a unit
|
||||
*
|
||||
* @param u Unit being the base of the operation
|
||||
*
|
||||
* @return Unit The result of computation
|
||||
*/
|
||||
[[nodiscard]] consteval Unit auto cubic(Unit auto u) { return pow<3>(u); }
|
||||
|
||||
template<Unit auto U>
|
||||
inline constexpr decltype(U * U * U) cubic;
|
||||
|
||||
// common dimensionless units
|
||||
// clang-format off
|
||||
|
||||
@@ -37,7 +37,7 @@ inline constexpr struct radian : named_unit<"rad", kind_of<angle>> {} radian;
|
||||
inline constexpr struct revolution : named_unit<"rev", mag<2> * mag_pi * radian> {} revolution;
|
||||
inline constexpr struct degree : named_unit<basic_symbol_text{"°", "deg"}, mag<ratio{1, 360}> * revolution> {} degree;
|
||||
inline constexpr struct gradian : named_unit<basic_symbol_text{"ᵍ", "grad"}, mag<ratio{1, 400}> * revolution> {} gradian;
|
||||
inline constexpr struct steradian : named_unit<"sr", square<radian>> {} steradian;
|
||||
inline constexpr struct steradian : named_unit<"sr", square(radian)> {} steradian;
|
||||
// clang-format on
|
||||
|
||||
namespace unit_symbols {
|
||||
@@ -47,8 +47,8 @@ inline constexpr auto rev = revolution;
|
||||
inline constexpr auto deg = degree;
|
||||
inline constexpr auto grad = gradian;
|
||||
inline constexpr auto sr = steradian;
|
||||
inline constexpr auto rad2 = square<radian>;
|
||||
inline constexpr auto deg2 = square<degree>;
|
||||
inline constexpr auto rad2 = square(radian);
|
||||
inline constexpr auto deg2 = square(degree);
|
||||
|
||||
} // namespace unit_symbols
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ namespace mp_units::cgs {
|
||||
inline constexpr struct centimetre : decltype(si::centi<si::metre>) {} centimetre;
|
||||
inline constexpr struct gram : decltype(si::gram) {} gram;
|
||||
inline constexpr struct second : decltype(si::second) {} second;
|
||||
inline constexpr struct gal : named_unit<"Gal", centimetre / square<second>> {} gal;
|
||||
inline constexpr struct dyne : named_unit<"dyn", gram * centimetre / square<second>> {} dyne;
|
||||
inline constexpr struct gal : named_unit<"Gal", centimetre / square(second)> {} gal;
|
||||
inline constexpr struct dyne : named_unit<"dyn", gram * centimetre / square(second)> {} dyne;
|
||||
inline constexpr struct erg : named_unit<"erg", dyne * centimetre> {} erg;
|
||||
inline constexpr struct barye : named_unit<"Ba", gram / (centimetre * square<second>)> {} barye;
|
||||
inline constexpr struct barye : named_unit<"Ba", gram / (centimetre * square(second))> {} barye;
|
||||
inline constexpr struct poise : named_unit<"P", gram / (centimetre * second)> {} poise;
|
||||
inline constexpr struct stokes : named_unit<"St", square<centimetre> / second> {} stokes;
|
||||
inline constexpr struct stokes : named_unit<"St", square(centimetre) / second> {} stokes;
|
||||
inline constexpr struct kayser : named_unit<"K", 1 / centimetre> {} kayser;
|
||||
// clang-format on
|
||||
|
||||
@@ -53,10 +53,10 @@ inline constexpr auto St = stokes;
|
||||
inline constexpr auto K = kayser;
|
||||
|
||||
// commonly used squared and cubic units
|
||||
inline constexpr auto cm2 = square<centimetre>;
|
||||
inline constexpr auto cm3 = cubic<centimetre>;
|
||||
inline constexpr auto s2 = square<second>;
|
||||
inline constexpr auto s3 = cubic<second>;
|
||||
inline constexpr auto cm2 = square(centimetre);
|
||||
inline constexpr auto cm3 = cubic(centimetre);
|
||||
inline constexpr auto s2 = square(second);
|
||||
inline constexpr auto s3 = cubic(second);
|
||||
|
||||
} // namespace unit_symbols
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ using si::electronvolt;
|
||||
// effective cross-sectional area according to EU council directive 80/181/EEC
|
||||
// https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:01980L0181-20090527#page=10
|
||||
// https://www.fedlex.admin.ch/eli/cc/1994/3109_3109_3109/de
|
||||
inline constexpr struct barn : named_unit<"b", mag_power<10, -28> * square<si::metre>> {} barn;
|
||||
inline constexpr struct barn : named_unit<"b", mag_power<10, -28> * square(si::metre)> {} barn;
|
||||
|
||||
// mass
|
||||
inline constexpr struct electron_mass : named_unit<"m_e", mag<ratio{9'109'383'701'528, 1'000'000'000'000}> * mag_power<10, -31> * si::kilogram> {} electron_mass;
|
||||
@@ -90,7 +90,7 @@ inline constexpr auto m_p = proton_mass;
|
||||
inline constexpr auto m_n = neutron_mass;
|
||||
|
||||
inline constexpr auto c = si::si2019::speed_of_light_in_vacuum_unit;
|
||||
inline constexpr auto c2 = square<si::si2019::speed_of_light_in_vacuum_unit>;
|
||||
inline constexpr auto c2 = square(si::si2019::speed_of_light_in_vacuum_unit);
|
||||
|
||||
} // namespace unit_symbols
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ inline constexpr struct link : named_unit<"li", mag<ratio{1, 100}> * chain> {} l
|
||||
inline constexpr struct rod : named_unit<"rd", mag<25> * link> {} rod;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Imperial_units#Area
|
||||
inline constexpr struct perch : decltype(square<rod>) {} perch;
|
||||
inline constexpr struct perch : decltype(square(rod)) {} perch;
|
||||
inline constexpr struct rood : decltype(mag<40> * perch) {} rood;
|
||||
inline constexpr struct acre : decltype(mag<4> * rood) {} acre;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ inline constexpr struct knot : named_unit<"kn", nautical_mile / si::hour> {} kno
|
||||
|
||||
// force
|
||||
// https://en.wikipedia.org/wiki/Poundal
|
||||
inline constexpr struct poundal : named_unit<"pdl", pound * foot / square<si::second>> {} poundal;
|
||||
inline constexpr struct poundal : named_unit<"pdl", pound * foot / square(si::second)> {} poundal;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Pound_(force)
|
||||
inline constexpr struct pound_force : named_unit<"lbf", pound * si::standard_gravity_unit> {} pound_force;
|
||||
@@ -61,7 +61,7 @@ inline constexpr struct pound_force : named_unit<"lbf", pound * si::standard_gra
|
||||
inline constexpr struct kip : decltype(si::kilo<pound_force>) {} kip;
|
||||
|
||||
// pressure
|
||||
inline constexpr struct psi : named_unit<"psi", pound_force / square<inch>> {} psi;
|
||||
inline constexpr struct psi : named_unit<"psi", pound_force / square(inch)> {} psi;
|
||||
|
||||
// power
|
||||
// https://en.wikipedia.org/wiki/Horsepower#Definitions
|
||||
|
||||
@@ -43,7 +43,7 @@ inline constexpr struct velocity : system_reference<isq::velocity, one> {} veloc
|
||||
inline constexpr struct speed : system_reference<isq::speed, one> {} speed;
|
||||
inline constexpr struct acceleration : system_reference<isq::acceleration, gigaelectronvolt> {} acceleration;
|
||||
inline constexpr struct momentum : system_reference<isq::momentum, gigaelectronvolt> {} momentum;
|
||||
inline constexpr struct force : system_reference<isq::force, square<gigaelectronvolt>> {} force;
|
||||
inline constexpr struct force : system_reference<isq::force, square(gigaelectronvolt)> {} force;
|
||||
inline constexpr struct energy : system_reference<isq::mechanical_energy, gigaelectronvolt> {} energy;
|
||||
// clang-format on
|
||||
|
||||
@@ -53,7 +53,7 @@ inline constexpr auto speed_of_light_in_vacuum = speed[one];
|
||||
namespace unit_symbols {
|
||||
|
||||
inline constexpr auto GeV = gigaelectronvolt;
|
||||
inline constexpr auto GeV2 = square<gigaelectronvolt>;
|
||||
inline constexpr auto GeV2 = square(gigaelectronvolt);
|
||||
|
||||
} // namespace unit_symbols
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ inline constexpr auto avogadro_constant = (1 / isq::amount_of_substance)[avogadr
|
||||
|
||||
// clang-format off
|
||||
inline constexpr struct standard_gravity_unit :
|
||||
constant_unit<basic_symbol_text{"g₀", "g_0"}, mag<ratio{980'665, 100'000}> * metre / square<second>> {} standard_gravity_unit;
|
||||
constant_unit<basic_symbol_text{"g₀", "g_0"}, mag<ratio{980'665, 100'000}> * metre / square(second)> {} standard_gravity_unit;
|
||||
inline constexpr struct magnetic_constant_unit :
|
||||
constant_unit<basic_symbol_text{"μ₀", "u_0"}, mag<4> * mag_pi * mag_power<10, -7> * henry / metre> {} magnetic_constant_unit;
|
||||
// clang-format on
|
||||
|
||||
@@ -747,10 +747,10 @@ inline constexpr auto h = hour;
|
||||
inline constexpr auto d = day;
|
||||
|
||||
// commonly used squared and cubic units
|
||||
inline constexpr auto m2 = square<metre>;
|
||||
inline constexpr auto m3 = cubic<metre>;
|
||||
inline constexpr auto m2 = square(metre);
|
||||
inline constexpr auto m3 = cubic(metre);
|
||||
inline constexpr auto m4 = pow<4>(metre);
|
||||
inline constexpr auto s2 = square<second>;
|
||||
inline constexpr auto s3 = cubic<second>;
|
||||
inline constexpr auto s2 = square(second);
|
||||
inline constexpr auto s3 = cubic(second);
|
||||
|
||||
} // namespace mp_units::si::unit_symbols
|
||||
|
||||
@@ -42,15 +42,15 @@ inline constexpr struct candela : named_unit<"cd", kind_of<isq::luminous_intensi
|
||||
|
||||
// derived named units
|
||||
inline constexpr struct radian : named_unit<"rad", metre / metre, kind_of<isq::angular_measure>> {} radian;
|
||||
inline constexpr struct steradian : named_unit<"sr", square<metre> / square<metre>, kind_of<isq::solid_angular_measure>> {} steradian;
|
||||
inline constexpr struct steradian : named_unit<"sr", square(metre) / square(metre), kind_of<isq::solid_angular_measure>> {} steradian;
|
||||
inline constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of<isq::frequency>> {} hertz;
|
||||
inline constexpr struct newton : named_unit<"N", kilogram * metre / square<second>> {} newton;
|
||||
inline constexpr struct newton : named_unit<"N", kilogram * metre / square(second)> {} newton;
|
||||
#ifdef pascal
|
||||
#pragma push_macro("pascal")
|
||||
#undef pascal
|
||||
#define UNITS_REDEFINE_PASCAL
|
||||
#endif
|
||||
inline constexpr struct pascal : named_unit<"Pa", newton / square<metre>> {} pascal;
|
||||
inline constexpr struct pascal : named_unit<"Pa", newton / square(metre)> {} pascal;
|
||||
#ifdef UNITS_REDEFINE_PASCAL
|
||||
#pragma pop_macro("pascal")
|
||||
#undef UNITS_REDEFINE_PASCAL
|
||||
@@ -63,12 +63,12 @@ inline constexpr struct farad : named_unit<"F", coulomb / volt> {} farad;
|
||||
inline constexpr struct ohm : named_unit<basic_symbol_text{"Ω", "ohm"}, volt / ampere> {} ohm;
|
||||
inline constexpr struct siemens : named_unit<"S", 1 / ohm> {} siemens;
|
||||
inline constexpr struct weber : named_unit<"Wb", volt * second> {} weber;
|
||||
inline constexpr struct tesla : named_unit<"T", weber / square<metre>> {} tesla;
|
||||
inline constexpr struct tesla : named_unit<"T", weber / square(metre)> {} tesla;
|
||||
inline constexpr struct henry : named_unit<"H", weber / ampere> {} henry;
|
||||
// inline constexpr struct degree_Celsius : named_unit<basic_symbol_text{"°C", "`C"}, kelvin, offset<-mag<273150> * milli<kelvin>, only_for<isq::Celsius_temperature> {} degree_Celsius;
|
||||
inline constexpr struct degree_Celsius : named_unit<basic_symbol_text{"°C", "`C"}, kelvin> {} degree_Celsius;
|
||||
inline constexpr struct lumen : named_unit<"lm", candela * steradian> {} lumen;
|
||||
inline constexpr struct lux : named_unit<"lx", lumen / square<metre>> {} lux;
|
||||
inline constexpr struct lux : named_unit<"lx", lumen / square(metre)> {} lux;
|
||||
// inline constexpr struct becquerel : named_unit<"Bq", 1 / second, kind_of<activity>> {} becquerel;
|
||||
inline constexpr struct becquerel : named_unit<"Bq", 1 / second> {} becquerel;
|
||||
inline constexpr struct gray : named_unit<"Gy", joule / kilogram> {} gray;
|
||||
@@ -84,9 +84,9 @@ inline constexpr struct degree : named_unit<basic_symbol_text{"°", "deg"}, mag_
|
||||
// TODO how to disambiguate below angular units from time units (inline namespace `plane_angle`?)
|
||||
// inline constexpr struct minute : named_unit<basic_symbol_text{"′", "'"}, mag<ratio{1, 60}> * degree> {} minute;
|
||||
// inline constexpr struct second : named_unit<basic_symbol_text{"″", "''"}, mag<ratio{1, 60}> * minute> {} second;
|
||||
inline constexpr struct are : named_unit<"a", square<deca<metre>>> {} are;
|
||||
inline constexpr struct are : named_unit<"a", square(deca<metre>)> {} are;
|
||||
inline constexpr struct hectare : decltype(hecto<are>) {} hectare;
|
||||
inline constexpr struct litre : named_unit<"l", cubic<deci<metre>>> {} litre;
|
||||
inline constexpr struct litre : named_unit<"l", cubic(deci<metre>)> {} litre;
|
||||
inline constexpr struct tonne : named_unit<"t", mag<1000> * kilogram> {} tonne;
|
||||
inline constexpr struct dalton : named_unit<"Da", mag<ratio{16'605'390'666'050, 10'000'000'000'000}> * mag_power<10, -27> * kilogram> {} dalton;
|
||||
// TODO A different value is provided in the SI Brochure and different in the ISO 80000
|
||||
|
||||
@@ -68,11 +68,11 @@ inline constexpr struct league : named_unit<"lea", mag<3> * us_survey_mile> {} l
|
||||
|
||||
// clang-format off
|
||||
// https://en.wikipedia.org/wiki/United_States_customary_units#Area
|
||||
inline constexpr struct acre : named_unit<"acre", mag<10> * square<survey1893::chain>> {} acre;
|
||||
inline constexpr struct acre : named_unit<"acre", mag<10> * square(survey1893::chain)> {} acre;
|
||||
inline constexpr struct section : named_unit<"section", mag<640> * acre> {} section;
|
||||
|
||||
// https://en.wikipedia.org/wiki/United_States_customary_units#Fluid_volume
|
||||
inline constexpr struct gallon : named_unit<"gal", mag<231> * cubic<inch>> {} gallon;
|
||||
inline constexpr struct gallon : named_unit<"gal", mag<231> * cubic(inch)> {} gallon;
|
||||
inline constexpr struct pottle : named_unit<"pot", mag<ratio{1, 2}> * gallon> {} pottle;
|
||||
inline constexpr struct quart : named_unit<"qt", mag<ratio{1, 2}> * pottle> {} quart;
|
||||
inline constexpr struct pint : named_unit<"pt", mag<ratio{1, 2}> * quart> {} pint;
|
||||
@@ -89,7 +89,7 @@ inline constexpr struct oil_barrel : named_unit<"bbl", mag<ratio{4, 3}> * barrel
|
||||
inline constexpr struct hogshead : decltype(mag<63> * gallon) {} hogshead;
|
||||
|
||||
// https://en.wikipedia.org/wiki/United_States_customary_units#Dry_volume
|
||||
inline constexpr struct dry_barrel : named_unit<"bbl", mag<7056> * cubic<inch>> {} dry_barrel;
|
||||
inline constexpr struct dry_barrel : named_unit<"bbl", mag<7056> * cubic(inch)> {} dry_barrel;
|
||||
inline constexpr struct bushel : named_unit<"bu", mag<ratio{3'523'907'016'688, 100'000'000'000}> * si::litre> {} bushel;
|
||||
inline constexpr struct peck : named_unit<"pk", mag<ratio{1, 4}> * bushel> {} peck;
|
||||
inline constexpr struct dry_gallon : named_unit<"gal", mag<ratio{1, 2}> * peck> {} dry_gallon;
|
||||
|
||||
Reference in New Issue
Block a user