From 96dcea751dec0700307f523ef13ac75b7d33e618 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 5 Feb 2024 19:11:14 +0100 Subject: [PATCH 1/3] feat: improve types readability by eliminating extraneous `()` for a value of a type for prefixes --- .../systems/iec80000/binary_prefixes.h | 32 +++---- .../include/mp-units/systems/si/prefixes.h | 96 +++++++++---------- test/static/unit_test.cpp | 10 +- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/systems/include/mp-units/systems/iec80000/binary_prefixes.h b/src/systems/include/mp-units/systems/iec80000/binary_prefixes.h index ca3db21e5..112e71a8f 100644 --- a/src/systems/include/mp-units/systems/iec80000/binary_prefixes.h +++ b/src/systems/include/mp-units/systems/iec80000/binary_prefixes.h @@ -27,23 +27,23 @@ namespace mp_units::iec80000 { // clang-format off -template struct kibi_ : prefixed_unit<"Ki", mag_power<2, 10>, U> {}; -template struct mebi_ : prefixed_unit<"Mi", mag_power<2, 20>, U> {}; -template struct gibi_ : prefixed_unit<"Gi", mag_power<2, 30>, U> {}; -template struct tebi_ : prefixed_unit<"Ti", mag_power<2, 40>, U> {}; -template struct pebi_ : prefixed_unit<"Pi", mag_power<2, 50>, U> {}; -template struct exbi_ : prefixed_unit<"Ei", mag_power<2, 60>, U> {}; -template struct zebi_ : prefixed_unit<"Zi", mag_power<2, 70>, U> {}; -template struct yobi_ : prefixed_unit<"Yi", mag_power<2, 80>, U> {}; +template struct kibi_ : prefixed_unit<"Ki", mag_power<2, 10>, U{}> {}; +template struct mebi_ : prefixed_unit<"Mi", mag_power<2, 20>, U{}> {}; +template struct gibi_ : prefixed_unit<"Gi", mag_power<2, 30>, U{}> {}; +template struct tebi_ : prefixed_unit<"Ti", mag_power<2, 40>, U{}> {}; +template struct pebi_ : prefixed_unit<"Pi", mag_power<2, 50>, U{}> {}; +template struct exbi_ : prefixed_unit<"Ei", mag_power<2, 60>, U{}> {}; +template struct zebi_ : prefixed_unit<"Zi", mag_power<2, 70>, U{}> {}; +template struct yobi_ : prefixed_unit<"Yi", mag_power<2, 80>, U{}> {}; -template inline constexpr kibi_ kibi; -template inline constexpr mebi_ mebi; -template inline constexpr gibi_ gibi; -template inline constexpr tebi_ tebi; -template inline constexpr pebi_ pebi; -template inline constexpr exbi_ exbi; -template inline constexpr zebi_ zebi; -template inline constexpr yobi_ yobi; +template inline constexpr kibi_> kibi; +template inline constexpr mebi_> mebi; +template inline constexpr gibi_> gibi; +template inline constexpr tebi_> tebi; +template inline constexpr pebi_> pebi; +template inline constexpr exbi_> exbi; +template inline constexpr zebi_> zebi; +template inline constexpr yobi_> yobi; // clang-format on } // namespace mp_units::iec80000 diff --git a/src/systems/include/mp-units/systems/si/prefixes.h b/src/systems/include/mp-units/systems/si/prefixes.h index f8c9431ca..09582df0d 100644 --- a/src/systems/include/mp-units/systems/si/prefixes.h +++ b/src/systems/include/mp-units/systems/si/prefixes.h @@ -27,55 +27,55 @@ namespace mp_units::si { // clang-format off -template struct quecto_ : prefixed_unit<"q", mag_power<10, -30>, U> {}; -template struct ronto_ : prefixed_unit<"r", mag_power<10, -27>, U> {}; -template struct yocto_ : prefixed_unit<"y", mag_power<10, -24>, U> {}; -template struct zepto_ : prefixed_unit<"z", mag_power<10, -21>, U> {}; -template struct atto_ : prefixed_unit<"a", mag_power<10, -18>, U> {}; -template struct femto_ : prefixed_unit<"f", mag_power<10, -15>, U> {}; -template struct pico_ : prefixed_unit<"p", mag_power<10, -12>, U> {}; -template struct nano_ : prefixed_unit<"n", mag_power<10, -9>, U> {}; -template struct micro_ : prefixed_unit, U> {}; -template struct milli_ : prefixed_unit<"m", mag_power<10, -3>, U> {}; -template struct centi_ : prefixed_unit<"c", mag_power<10, -2>, U> {}; -template struct deci_ : prefixed_unit<"d", mag_power<10, -1>, U> {}; -template struct deca_ : prefixed_unit<"da", mag_power<10, 1>, U> {}; -template struct hecto_ : prefixed_unit<"h", mag_power<10, 2>, U> {}; -template struct kilo_ : prefixed_unit<"k", mag_power<10, 3>, U> {}; -template struct mega_ : prefixed_unit<"M", mag_power<10, 6>, U> {}; -template struct giga_ : prefixed_unit<"G", mag_power<10, 9>, U> {}; -template struct tera_ : prefixed_unit<"T", mag_power<10, 12>, U> {}; -template struct peta_ : prefixed_unit<"P", mag_power<10, 15>, U> {}; -template struct exa_ : prefixed_unit<"E", mag_power<10, 18>, U> {}; -template struct zetta_ : prefixed_unit<"Z", mag_power<10, 21>, U> {}; -template struct yotta_ : prefixed_unit<"Y", mag_power<10, 24>, U> {}; -template struct ronna_ : prefixed_unit<"R", mag_power<10, 27>, U> {}; -template struct quetta_ : prefixed_unit<"Q", mag_power<10, 30>, U> {}; +template struct quecto_ : prefixed_unit<"q", mag_power<10, -30>, U{}> {}; +template struct ronto_ : prefixed_unit<"r", mag_power<10, -27>, U{}> {}; +template struct yocto_ : prefixed_unit<"y", mag_power<10, -24>, U{}> {}; +template struct zepto_ : prefixed_unit<"z", mag_power<10, -21>, U{}> {}; +template struct atto_ : prefixed_unit<"a", mag_power<10, -18>, U{}> {}; +template struct femto_ : prefixed_unit<"f", mag_power<10, -15>, U{}> {}; +template struct pico_ : prefixed_unit<"p", mag_power<10, -12>, U{}> {}; +template struct nano_ : prefixed_unit<"n", mag_power<10, -9>, U{}> {}; +template struct micro_ : prefixed_unit, U{}> {}; +template struct milli_ : prefixed_unit<"m", mag_power<10, -3>, U{}> {}; +template struct centi_ : prefixed_unit<"c", mag_power<10, -2>, U{}> {}; +template struct deci_ : prefixed_unit<"d", mag_power<10, -1>, U{}> {}; +template struct deca_ : prefixed_unit<"da", mag_power<10, 1>, U{}> {}; +template struct hecto_ : prefixed_unit<"h", mag_power<10, 2>, U{}> {}; +template struct kilo_ : prefixed_unit<"k", mag_power<10, 3>, U{}> {}; +template struct mega_ : prefixed_unit<"M", mag_power<10, 6>, U{}> {}; +template struct giga_ : prefixed_unit<"G", mag_power<10, 9>, U{}> {}; +template struct tera_ : prefixed_unit<"T", mag_power<10, 12>, U{}> {}; +template struct peta_ : prefixed_unit<"P", mag_power<10, 15>, U{}> {}; +template struct exa_ : prefixed_unit<"E", mag_power<10, 18>, U{}> {}; +template struct zetta_ : prefixed_unit<"Z", mag_power<10, 21>, U{}> {}; +template struct yotta_ : prefixed_unit<"Y", mag_power<10, 24>, U{}> {}; +template struct ronna_ : prefixed_unit<"R", mag_power<10, 27>, U{}> {}; +template struct quetta_ : prefixed_unit<"Q", mag_power<10, 30>, U{}> {}; -template inline constexpr quecto_ quecto; -template inline constexpr ronto_ ronto; -template inline constexpr yocto_ yocto; -template inline constexpr zepto_ zepto; -template inline constexpr atto_ atto; -template inline constexpr femto_ femto; -template inline constexpr pico_ pico; -template inline constexpr nano_ nano; -template inline constexpr micro_ micro; -template inline constexpr milli_ milli; -template inline constexpr centi_ centi; -template inline constexpr deci_ deci; -template inline constexpr deca_ deca; -template inline constexpr hecto_ hecto; -template inline constexpr kilo_ kilo; -template inline constexpr mega_ mega; -template inline constexpr giga_ giga; -template inline constexpr tera_ tera; -template inline constexpr peta_ peta; -template inline constexpr exa_ exa; -template inline constexpr zetta_ zetta; -template inline constexpr yotta_ yotta; -template inline constexpr ronna_ ronna; -template inline constexpr quetta_ quetta; +template inline constexpr quecto_> quecto; +template inline constexpr ronto_> ronto; +template inline constexpr yocto_> yocto; +template inline constexpr zepto_> zepto; +template inline constexpr atto_> atto; +template inline constexpr femto_> femto; +template inline constexpr pico_> pico; +template inline constexpr nano_> nano; +template inline constexpr micro_> micro; +template inline constexpr milli_> milli; +template inline constexpr centi_> centi; +template inline constexpr deci_> deci; +template inline constexpr deca_> deca; +template inline constexpr hecto_> hecto; +template inline constexpr kilo_> kilo; +template inline constexpr mega_> mega; +template inline constexpr giga_> giga; +template inline constexpr tera_> tera; +template inline constexpr peta_> peta; +template inline constexpr exa_> exa; +template inline constexpr zetta_> zetta; +template inline constexpr yotta_> yotta; +template inline constexpr ronna_> ronna; +template inline constexpr quetta_> quetta; // clang-format on } // namespace mp_units::si diff --git a/test/static/unit_test.cpp b/test/static/unit_test.cpp index d187467a0..6b3ab4d1c 100644 --- a/test/static/unit_test.cpp +++ b/test/static/unit_test.cpp @@ -212,8 +212,8 @@ static_assert(convertible(kilojoule, joule)); static_assert(kilojoule != joule); static_assert(kilojoule.symbol == "kJ"); -static_assert(is_of_type, si::kilo_>); -static_assert(is_of_type, si::kilo_>); +static_assert(is_of_type, si::kilo_>); +static_assert(is_of_type, si::kilo_>); // TODO Should the below be a scaled version of metre^2? static_assert(is_of_type>); // !!! @@ -264,7 +264,7 @@ static_assert(is_of_type); static_assert(get_canonical_unit(km_2).mag == mag<2000>); constexpr auto kJ_42 = mag<42> * si::kilo; -static_assert(is_of_type, si::kilo_>>); +static_assert(is_of_type, si::kilo_>>); static_assert( is_of_type, per>>>); static_assert(get_canonical_unit(kJ_42).mag == mag<42'000'000>); @@ -467,7 +467,7 @@ static_assert(!convertible(metre, metre* metre)); // one static_assert(is_of_type); -static_assert(is_of_type / metre, derived_unit, per>>); +static_assert(is_of_type / metre, derived_unit, per>>); static_assert(metre / metre == one); static_assert(hertz * second == one); static_assert(one * one == one); @@ -509,7 +509,7 @@ static_assert(is_of_type(metre / (second * second)), derived_unit>>); static_assert(is_of_type(kilometre), derived_unit>>); -static_assert(is_of_type(si::kilo), derived_unit, 2>>>); +static_assert(is_of_type(si::kilo), derived_unit, 2>>>); static_assert(is_of_type(hour), derived_unit>>); static_assert( is_of_type(mag<3600>* second), scaled_unit * mag<3600>, derived_unit>>>); From 25a4c7c1287698f868e8e8ec46fb31b8482c73a7 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 5 Feb 2024 19:32:38 +0100 Subject: [PATCH 2/3] fix: quantity_test compilation fixed --- test/static/quantity_test.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 7992f4932..69386243f 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -520,7 +520,8 @@ static_assert(is_of_type<1 * percent * (1 * m), quantity>{}, int>>); static_assert(is_of_type<1 * m / (1 * m), quantity>); -static_assert(is_of_type<1 * km / (1 * m), quantity, per>{}, int>>); +static_assert( + is_of_type<1 * km / (1 * m), quantity, per>{}, int>>); static_assert(is_of_type<1 * m / 1, quantity>); static_assert(is_of_type<1 * m / (1 * one), quantity>); @@ -568,7 +569,7 @@ static_assert(is_of_type<1 * percent * (1. * m), quantity>{}, double>>); static_assert(is_of_type<1. * m / (1 * m), quantity>); static_assert( - is_of_type<1. * km / (1 * m), quantity, per>{}, double>>); + is_of_type<1. * km / (1 * m), quantity, per>{}, double>>); static_assert(is_of_type<1. * m / 1, quantity>); static_assert(is_of_type<1 * m / (1. * one), quantity>); @@ -612,11 +613,12 @@ static_assert(is_of_type<1 * m * (1 * min), quantity{}, int>>); static_assert(is_of_type<1 / (1 * min), quantity>{}, int>>); static_assert(is_of_type<1 / (1 * Hz), quantity>{}, int>>); -static_assert(is_of_type<1 / (1 * km), quantity>>{}, int>>); +static_assert(is_of_type<1 / (1 * km), quantity>>{}, int>>); static_assert(is_of_type<1 / min, quantity>{}, int>>); static_assert(is_of_type<1 / Hz, quantity>{}, int>>); -static_assert(is_of_type<1 / km, quantity>>{}, int>>); -static_assert(is_of_type<1 * km / (1 * m), quantity, per>{}, int>>); +static_assert(is_of_type<1 / km, quantity>>{}, int>>); +static_assert( + is_of_type<1 * km / (1 * m), quantity, per>{}, int>>); static_assert(is_of_type<1 * m / (1 * s), quantity>{}, int>>); static_assert(is_of_type<1 * m / (1 * min), quantity>{}, int>>); static_assert(is_of_type<1 * min / (1 * m), quantity>{}, int>>); From 8b5d2ead52dc6483794d88f374d014a3dc77cea2 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 5 Feb 2024 19:45:08 +0100 Subject: [PATCH 3/3] fix: si_test compilation fixed --- test/static/si_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/static/si_test.cpp b/test/static/si_test.cpp index 8ce659358..0599469bd 100644 --- a/test/static/si_test.cpp +++ b/test/static/si_test.cpp @@ -61,8 +61,9 @@ static_assert(1 * Rm == 1'000'000'000'000'000'000 * Gm); static_assert(1 * Qm == 1'000'000'000'000'000'000 * Tm); // check for invalid prefixes -template typename prefix, auto V1> -concept can_not_be_prefixed = Unit> && !requires { typename prefix; }; +template typename prefix, auto V1> +concept can_not_be_prefixed = + Unit> && !requires { typename prefix>; }; static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed);