From d9697afd6799e4edc80877fbaefe77b5985059bf Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 19 Jun 2023 14:02:31 +0200 Subject: [PATCH] feat: non-SI units got their own namespace `non_si` --- .../mp-units/systems/si/unit_symbols.h | 38 ++++++++++----- .../si/include/mp-units/systems/si/units.h | 47 ++++++++++++------- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/systems/si/include/mp-units/systems/si/unit_symbols.h b/src/systems/si/include/mp-units/systems/si/unit_symbols.h index 43ea5cd1..8ce9de27 100644 --- a/src/systems/si/include/mp-units/systems/si/unit_symbols.h +++ b/src/systems/si/include/mp-units/systems/si/unit_symbols.h @@ -25,7 +25,9 @@ #include #include -namespace mp_units::si::unit_symbols { +namespace mp_units { + +namespace si::unit_symbols { inline constexpr auto qm = quecto; inline constexpr auto rm = ronto; @@ -730,7 +732,21 @@ inline constexpr auto Ykat = yotta; inline constexpr auto Rkat = ronna; inline constexpr auto Qkat = quetta; -// TODO Should the following non-SI units have prefixes symbols predefiend as well? +// no prefixes should be provided for the below units +inline constexpr auto deg_C = degree_Celsius; + +// commonly used squared and cubic units +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); + +} // namespace si::unit_symbols + +namespace non_si::unit_symbols { + +// TODO Should the following non-SI units have prefixed symbols predefiend as well? inline constexpr auto au = astronomical_unit; inline constexpr auto deg = degree; inline constexpr auto arcmin = arcminute; @@ -742,17 +758,17 @@ inline constexpr auto t = tonne; inline constexpr auto Da = dalton; inline constexpr auto eV = electronvolt; -// No prefixes should be provided for the below units -inline constexpr auto deg_C = degree_Celsius; +// no prefixes should be provided for the below units inline constexpr auto min = minute; 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 m4 = pow<4>(metre); -inline constexpr auto s2 = square(second); -inline constexpr auto s3 = cubic(second); +} // namespace non_si::unit_symbols -} // namespace mp_units::si::unit_symbols +namespace si::unit_symbols { + +using namespace non_si::unit_symbols; + +} // namespace si::unit_symbols + +} // namespace mp_units diff --git a/src/systems/si/include/mp-units/systems/si/units.h b/src/systems/si/include/mp-units/systems/si/units.h index 41543f5b..314c6f19 100644 --- a/src/systems/si/include/mp-units/systems/si/units.h +++ b/src/systems/si/include/mp-units/systems/si/units.h @@ -27,7 +27,9 @@ #include #include -namespace mp_units::si { +namespace mp_units { + +namespace si { // clang-format off // base units @@ -70,45 +72,56 @@ inline constexpr struct henry : named_unit<"H", weber / ampere> {} henry; inline constexpr struct degree_Celsius : named_unit {} 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 becquerel : named_unit<"Bq", 1 / second, kind_of> {} becquerel; +// TODO add when isq::activity will be supported +// inline constexpr struct becquerel : named_unit<"Bq", 1 / second, kind_of> {} becquerel; inline constexpr struct becquerel : named_unit<"Bq", 1 / second> {} becquerel; inline constexpr struct gray : named_unit<"Gy", joule / kilogram> {} gray; inline constexpr struct sievert : named_unit<"Sv", joule / kilogram> {} sievert; inline constexpr struct katal : named_unit<"kat", mole / second> {} katal; +// clang-format on +} // namespace si + +namespace non_si { + +// clang-format off // non-SI units accepted for use with the SI -inline constexpr struct minute : named_unit<"min", mag<60> * second> {} minute; +inline constexpr struct minute : named_unit<"min", mag<60> * si::second> {} minute; inline constexpr struct hour : named_unit<"h", mag<60> * minute> {} hour; inline constexpr struct day : named_unit<"d", mag<24> * hour> {} day; -inline constexpr struct astronomical_unit : named_unit<"au", mag<149'597'870'700> * metre> {} astronomical_unit; -inline constexpr struct degree : named_unit * radian> {} degree; +inline constexpr struct astronomical_unit : named_unit<"au", mag<149'597'870'700> * si::metre> {} astronomical_unit; +inline constexpr struct degree : named_unit * si::radian> {} degree; inline constexpr struct arcminute : named_unit * degree> {} arcminute; inline constexpr struct arcsecond : named_unit * arcminute> {} arcsecond; -inline constexpr struct are : named_unit<"a", square(deca)> {} are; -inline constexpr struct hectare : decltype(hecto) {} hectare; -inline constexpr struct litre : named_unit<"l", cubic(deci)> {} litre; -inline constexpr struct tonne : named_unit<"t", mag<1000> * kilogram> {} tonne; -inline constexpr struct dalton : named_unit<"Da", mag * mag_power<10, -27> * kilogram> {} dalton; +inline constexpr struct are : named_unit<"a", square(si::deca)> {} are; +inline constexpr struct hectare : decltype(si::hecto) {} hectare; +inline constexpr struct litre : named_unit<"l", cubic(si::deci)> {} litre; +inline constexpr struct tonne : named_unit<"t", mag<1000> * si::kilogram> {} tonne; +inline constexpr struct dalton : named_unit<"Da", mag * mag_power<10, -27> * si::kilogram> {} dalton; // TODO A different value is provided in the SI Brochure and different in the ISO 80000 -inline constexpr struct electronvolt : named_unit<"eV", mag * mag_power<10, -19> * joule> {} electronvolt; +inline constexpr struct electronvolt : named_unit<"eV", mag * mag_power<10, -19> * si::joule> {} electronvolt; // TODO the below are logarithmic units - how to support those? // neper // bel // decibel - // clang-format on -} // namespace mp_units::si +} // namespace non_si -namespace mp_units { +namespace si { + +// Non-SI units are accepted for use with SI +using namespace non_si; + +} // namespace si template<> inline constexpr bool unit_can_be_prefixed = false; template<> -inline constexpr bool unit_can_be_prefixed = false; +inline constexpr bool unit_can_be_prefixed = false; template<> -inline constexpr bool unit_can_be_prefixed = false; +inline constexpr bool unit_can_be_prefixed = false; template<> -inline constexpr bool unit_can_be_prefixed = false; +inline constexpr bool unit_can_be_prefixed = false; } // namespace mp_units