Skip to content

Commit

Permalink
refactor: MSVC workarounds for named prefixed units definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Jan 5, 2024
1 parent 9fd0438 commit 09d923d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/systems/cgs/include/mp-units/systems/cgs/cgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
namespace mp_units::cgs {

// clang-format off
#if MP_UNITS_COMP_MSVC
inline constexpr struct centimetre : si::centi_<si::metre> {} centimetre;
#else
inline constexpr struct centimetre : decltype(si::centi<si::metre>) {} centimetre;
#endif
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ inline constexpr struct poundal : named_unit<"pdl", pound * foot / square(si::se
inline constexpr struct pound_force : named_unit<"lbf", pound * si::standard_gravity> {} pound_force;

// https://en.wikipedia.org/wiki/Kip_(unit),
#if MP_UNITS_COMP_MSVC
inline constexpr struct kip : si::kilo_<pound_force> {} kip;
#else
inline constexpr struct kip : decltype(si::kilo<pound_force>) {} kip;
#endif

// pressure
inline constexpr struct psi : named_unit<"psi", pound_force / square(inch)> {} psi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ namespace mp_units::natural {
// clang-format off
// units
inline constexpr struct electronvolt : named_unit<"eV"> {} electronvolt;
#if MP_UNITS_COMP_MSVC
inline constexpr struct gigaelectronvolt : si::giga_<electronvolt> {} gigaelectronvolt;
#else
inline constexpr struct gigaelectronvolt : decltype(si::giga<electronvolt>) {} gigaelectronvolt;
#endif

// system references
inline constexpr struct time : system_reference<isq::time, inverse(gigaelectronvolt)> {} time;
Expand Down
8 changes: 8 additions & 0 deletions src/systems/si/include/mp-units/systems/si/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ namespace si {
inline constexpr struct second : named_unit<"s", kind_of<isq::time>> {} second;
inline constexpr struct metre : named_unit<"m", kind_of<isq::length>> {} metre;
inline constexpr struct gram : named_unit<"g", kind_of<isq::mass>> {} gram;
#if MP_UNITS_COMP_MSVC
inline constexpr struct kilogram : kilo_<gram> {} kilogram;
#else
inline constexpr struct kilogram : decltype(kilo<gram>) {} kilogram;
#endif
inline constexpr struct ampere : named_unit<"A", kind_of<isq::electric_current>> {} ampere;

inline constexpr struct absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
Expand Down Expand Up @@ -100,7 +104,11 @@ inline constexpr struct degree : named_unit<basic_symbol_text{"°", "deg"}, mag_
inline constexpr struct arcminute : named_unit<basic_symbol_text{"", "'"}, mag<ratio{1, 60}> * degree> {} arcminute;
inline constexpr struct arcsecond : named_unit<basic_symbol_text{"", "''"}, mag<ratio{1, 60}> * arcminute> {} arcsecond;
inline constexpr struct are : named_unit<"a", square(si::deca<si::metre>)> {} are;
#if MP_UNITS_COMP_MSVC
inline constexpr struct hectare : si::hecto_<are> {} hectare;
#else
inline constexpr struct hectare : decltype(si::hecto<are>) {} hectare;
#endif
inline constexpr struct litre : named_unit<"l", cubic(si::deci<si::metre>)> {} litre;
inline constexpr struct tonne : named_unit<"t", mag<1000> * si::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> * si::kilogram> {} dalton;
Expand Down

0 comments on commit 09d923d

Please sign in to comment.