Skip to content

Commit

Permalink
refactor: system's units do not inherit from one another anymore
Browse files Browse the repository at this point in the history
Resolves #512
  • Loading branch information
mpusz committed Jun 5, 2024
1 parent 41be9b3 commit fb77585
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/users_guide/framework_basics/text_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ and units of derived quantities.
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;
inline constexpr struct kilogram : decltype(kilo<gram>) {} kilogram;
inline constexpr auto kilogram = kilo<gram>;

inline constexpr struct newton : named_unit<"N", kilogram * metre / square(second)> {} newton;
inline constexpr struct joule : named_unit<"J", newton * metre> {} joule;
Expand Down
10 changes: 3 additions & 7 deletions src/systems/include/mp-units/systems/cgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ MP_UNITS_EXPORT
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 auto centimetre = si::centi<si::metre>;
inline constexpr auto gram = si::gram;
inline constexpr auto second = si::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 erg : named_unit<"erg", dyne * centimetre> {} erg;
Expand Down
2 changes: 1 addition & 1 deletion src/systems/include/mp-units/systems/hep.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ inline constexpr struct proton_mass : named_unit<"m_p", mag_ratio<1'672'621'923'
inline constexpr struct neutron_mass : named_unit<"m_n", mag_ratio<1'674'927'498'049, 1'000'000'000'000> * mag_power<10, -27> * si::kilogram> {} neutron_mass;

// speed
inline constexpr struct speed_of_light : decltype(si::si2019::speed_of_light_in_vacuum) {} speed_of_light;
inline constexpr auto speed_of_light = si::si2019::speed_of_light_in_vacuum;
// clang-format on

namespace unit_symbols {
Expand Down
2 changes: 1 addition & 1 deletion src/systems/include/mp-units/systems/iau.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ inline constexpr struct Jupiter_mass : named_unit<"M_JUP", mag_ratio<1'898, 1'00
inline constexpr struct Earth_mass : named_unit<"M_EARTH", mag_ratio<59'742, 10'000> * mag_power<10, 24> * si::kilogram> {} Earth_mass;

// length
inline constexpr struct astronomical_unit : decltype(si::astronomical_unit) {} astronomical_unit;
inline constexpr auto astronomical_unit = si::astronomical_unit;

// https://en.wikipedia.org/wiki/Lunar_distance_(astronomy)
inline constexpr struct lunar_distance : named_unit<"LD", mag<384'399> * si::kilo<si::metre>> {} lunar_distance;
Expand Down
6 changes: 3 additions & 3 deletions src/systems/include/mp-units/systems/imperial.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ inline constexpr struct link : named_unit<"li", mag_ratio<1, 100> * chain> {} li
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 rood : decltype(mag<40> * perch) {} rood;
inline constexpr struct acre : decltype(mag<4> * rood) {} acre;
inline constexpr struct perch : named_unit<"perch", square(rod)> {} perch;
inline constexpr struct rood : named_unit<"rood", mag<40> * perch> {} rood;
inline constexpr struct acre : named_unit<"acre", mag<4> * rood> {} acre;

// https://en.wikipedia.org/wiki/Imperial_units#Volume
inline constexpr struct gallon : named_unit<"gal", mag_ratio<454'609, 100'000> * si::litre> {} gallon;
Expand Down
6 changes: 1 addition & 5 deletions src/systems/include/mp-units/systems/international.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ 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
inline constexpr auto kip = si::kilo<pound_force>;

// pressure
inline constexpr struct psi : named_unit<"psi", pound_force / square(inch)> {} psi;
Expand Down
6 changes: 1 addition & 5 deletions src/systems/include/mp-units/systems/natural.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ 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
inline constexpr auto gigaelectronvolt = si::giga<electronvolt>;

// system references
inline constexpr struct time : system_reference<isq::time, inverse(gigaelectronvolt)> {} time;
Expand Down
12 changes: 2 additions & 10 deletions src/systems/include/mp-units/systems/si/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ 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 auto kilogram = kilo<gram>;
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 @@ -107,11 +103,7 @@ inline constexpr struct degree : named_unit<symbol_text{u8"°", "deg"}, mag_pi /
inline constexpr struct arcminute : named_unit<symbol_text{u8"", "'"}, mag_ratio<1, 60> * degree> {} arcminute;
inline constexpr struct arcsecond : named_unit<symbol_text{u8"", "''"}, 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 auto hectare = si::hecto<are>;
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
2 changes: 1 addition & 1 deletion src/systems/include/mp-units/systems/usc.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ inline constexpr struct minim : named_unit<"min", mag_ratio<1, 80> * teaspoon> {
inline constexpr struct fluid_dram : named_unit<"fl dr", mag<60> * minim> {} fluid_dram;
inline constexpr struct barrel : named_unit<"bbl", mag_ratio<315, 10> * gallon> {} barrel;
inline constexpr struct oil_barrel : named_unit<"bbl", mag_ratio<4, 3> * barrel> {} oil_barrel;
inline constexpr struct hogshead : decltype(mag<63> * gallon) {} hogshead;
inline constexpr struct hogshead : named_unit<"hogshead", 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;
Expand Down
10 changes: 5 additions & 5 deletions test/static/concepts_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static_assert(!detail::QuantityKindSpec<int>);
struct metre_per_second : decltype(si::metre / si::second) {};

static_assert(Unit<struct si::metre>);
static_assert(Unit<struct si::kilogram>);
static_assert(Unit<decltype(si::kilogram)>);
static_assert(Unit<decltype(si::kilo<si::gram>)>);
static_assert(Unit<struct natural::electronvolt>);
static_assert(Unit<decltype(si::metre / si::second)>);
Expand All @@ -168,7 +168,7 @@ static_assert(!Unit<std::chrono::seconds>);
// NamedUnit
static_assert(detail::NamedUnit<struct si::metre>);
static_assert(detail::NamedUnit<struct natural::electronvolt>);
static_assert(!detail::NamedUnit<struct si::kilogram>);
static_assert(!detail::NamedUnit<decltype(si::kilogram)>);
static_assert(!detail::NamedUnit<decltype(si::kilo<si::gram>)>);
static_assert(!detail::NamedUnit<decltype(si::metre / si::second)>);
static_assert(!detail::NamedUnit<decltype(inverse(si::second))>);
Expand All @@ -194,7 +194,7 @@ static_assert(!detail::NamedUnit<std::chrono::seconds>);
// PrefixableUnit
static_assert(PrefixableUnit<struct si::metre>);
static_assert(PrefixableUnit<struct natural::electronvolt>);
static_assert(!PrefixableUnit<struct si::kilogram>);
static_assert(!PrefixableUnit<decltype(si::kilogram)>);
static_assert(!PrefixableUnit<decltype(si::kilo<si::gram>)>);
static_assert(!PrefixableUnit<decltype(si::metre / si::second)>);
static_assert(!PrefixableUnit<decltype(inverse(si::second))>);
Expand All @@ -220,7 +220,7 @@ static_assert(!PrefixableUnit<std::chrono::seconds>);
// AssociatedUnit
static_assert(AssociatedUnit<struct si::metre>);
static_assert(!AssociatedUnit<struct natural::electronvolt>);
static_assert(AssociatedUnit<struct si::kilogram>);
static_assert(AssociatedUnit<decltype(si::kilogram)>);
static_assert(AssociatedUnit<decltype(si::kilo<si::gram>)>);
static_assert(AssociatedUnit<decltype(si::metre / si::second)>);
static_assert(AssociatedUnit<decltype(inverse(si::second))>);
Expand All @@ -246,7 +246,7 @@ static_assert(!AssociatedUnit<std::chrono::seconds>);
// UnitOf
static_assert(UnitOf<struct si::metre, isq::length>);
static_assert(UnitOf<struct si::metre, isq::radius>);
static_assert(UnitOf<struct si::kilogram, isq::mass>);
static_assert(UnitOf<decltype(si::kilogram), isq::mass>);
static_assert(UnitOf<struct si::hertz, isq::frequency>);
static_assert(UnitOf<struct si::hertz, inverse(isq::time)>);
static_assert(UnitOf<struct one, dimensionless>);
Expand Down

0 comments on commit fb77585

Please sign in to comment.