From cb858f1e512117c975be7545f3aca5c9ac28ec06 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 16 Feb 2024 22:13:13 +0100 Subject: [PATCH] feat: ABI concerns resolved with introduction of u8 strings for symbols --- .../dimensionless_quantities.md | 4 +- .../faster_than_lightspeed_constants.md | 2 +- .../framework_basics/systems_of_units.md | 2 +- .../framework_basics/the_affine_space.md | 5 +- .../mp-units/bits/external/fixed_string.h | 3 + src/core/include/mp-units/bits/magnitude.h | 2 +- src/core/include/mp-units/bits/symbol_text.h | 67 ++++++++++++------- src/core/include/mp-units/bits/text_tools.h | 26 +++---- src/core/include/mp-units/unit.h | 18 ++--- .../include/mp-units/systems/angular/units.h | 4 +- .../include/mp-units/systems/iau/iau.h | 8 +-- .../mp-units/systems/isq/base_quantities.h | 2 +- .../include/mp-units/systems/si/constants.h | 6 +- .../include/mp-units/systems/si/prefixes.h | 2 +- .../include/mp-units/systems/si/units.h | 10 +-- .../include/mp-units/systems/usc/usc.h | 2 +- test/static/symbol_text_test.cpp | 30 ++++----- test/static/unit_test.cpp | 12 ++-- 18 files changed, 112 insertions(+), 93 deletions(-) diff --git a/docs/users_guide/framework_basics/dimensionless_quantities.md b/docs/users_guide/framework_basics/dimensionless_quantities.md index 7215eb4e..065e4ae8 100644 --- a/docs/users_guide/framework_basics/dimensionless_quantities.md +++ b/docs/users_guide/framework_basics/dimensionless_quantities.md @@ -114,7 +114,7 @@ units of _length_: ```cpp inline constexpr struct hubble_constant : - named_unit * si::kilo / si::second / si::mega> {} hubble_constant; + named_unit<{u8"H₀", "H_0"}, mag * si::kilo / si::second / si::mega> {} hubble_constant; ``` @@ -159,7 +159,7 @@ with dimensionless quantities: ```cpp inline constexpr struct percent : named_unit<"%", mag * one> {} percent; -inline constexpr struct per_mille : named_unit * one> {} per_mille; +inline constexpr struct per_mille : named_unit<{u8"‰", "%o"}, mag * one> {} per_mille; inline constexpr struct parts_per_million : named_unit<"ppm", mag * one> {} parts_per_million; inline constexpr auto ppm = parts_per_million; ``` diff --git a/docs/users_guide/framework_basics/faster_than_lightspeed_constants.md b/docs/users_guide/framework_basics/faster_than_lightspeed_constants.md index b49450de..13ce4e34 100644 --- a/docs/users_guide/framework_basics/faster_than_lightspeed_constants.md +++ b/docs/users_guide/framework_basics/faster_than_lightspeed_constants.md @@ -45,7 +45,7 @@ inline constexpr struct speed_of_light_in_vacuum : } // namespace si2019 inline constexpr struct magnetic_constant : - named_unit * mag_pi * mag_power<10, -7> * henry / metre> {} magnetic_constant; + named_unit<{u8"μ₀", "u_0"}, mag<4> * mag_pi * mag_power<10, -7> * henry / metre> {} magnetic_constant; } // namespace mp_units::si ``` diff --git a/docs/users_guide/framework_basics/systems_of_units.md b/docs/users_guide/framework_basics/systems_of_units.md index 882c8acb..ef005a37 100644 --- a/docs/users_guide/framework_basics/systems_of_units.md +++ b/docs/users_guide/framework_basics/systems_of_units.md @@ -188,5 +188,5 @@ inline constexpr struct mag_pi : magnitude> {} m ``` ```cpp -inline constexpr struct degree : named_unit * si::radian> {} degree; +inline constexpr struct degree : named_unit<{u8"°", "deg"}, mag_pi / mag<180> * si::radian> {} degree; ``` diff --git a/docs/users_guide/framework_basics/the_affine_space.md b/docs/users_guide/framework_basics/the_affine_space.md index bf7b5fe1..56b60dd7 100644 --- a/docs/users_guide/framework_basics/the_affine_space.md +++ b/docs/users_guide/framework_basics/the_affine_space.md @@ -472,15 +472,14 @@ namespace si { inline constexpr struct kelvin : named_unit<"K", kind_of, zeroth_kelvin> {} kelvin; inline constexpr struct degree_Celsius : - named_unit {} degree_Celsius; + named_unit<{u8"°C", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius; } namespace usc { inline constexpr struct degree_Fahrenheit : - named_unit * si::degree_Celsius, - zeroth_degree_Fahrenheit> {} degree_Fahrenheit; + named_unit<{u8"°F", "`F"}, mag * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit; } ``` diff --git a/src/core/include/mp-units/bits/external/fixed_string.h b/src/core/include/mp-units/bits/external/fixed_string.h index 1ad0a5b4..d7fb80f4 100644 --- a/src/core/include/mp-units/bits/external/fixed_string.h +++ b/src/core/include/mp-units/bits/external/fixed_string.h @@ -143,6 +143,9 @@ basic_fixed_string(const CharT* ptr, std::integral_constant) -> template using fixed_string = basic_fixed_string; +template +using fixed_u8string = basic_fixed_string; + } // namespace mp_units template diff --git a/src/core/include/mp-units/bits/magnitude.h b/src/core/include/mp-units/bits/magnitude.h index f75cc4c6..4b4e7646 100644 --- a/src/core/include/mp-units/bits/magnitude.h +++ b/src/core/include/mp-units/bits/magnitude.h @@ -850,7 +850,7 @@ template return integer_part((detail::abs(power_of_2) < detail::abs(power_of_5)) ? power_of_2 : power_of_5); } -inline constexpr basic_symbol_text base_multiplier("× 10", "x 10"); +inline constexpr basic_symbol_text base_multiplier(u8"× 10", "x 10"); template [[nodiscard]] consteval auto magnitude_text() diff --git a/src/core/include/mp-units/bits/symbol_text.h b/src/core/include/mp-units/bits/symbol_text.h index 05315ec9..d96b38b3 100644 --- a/src/core/include/mp-units/bits/symbol_text.h +++ b/src/core/include/mp-units/bits/symbol_text.h @@ -32,11 +32,21 @@ #include +#if __cpp_lib_text_encoding +#include +static_assert(std::text_encoding::literal().mib() == std::text_encoding::id::UTF8); +#endif + namespace mp_units { namespace detail { -constexpr void validate_ascii_char([[maybe_unused]] char c) noexcept { gsl_Expects((c & 0x80) == 0); } +constexpr void validate_ascii_char([[maybe_unused]] char c) noexcept +{ + // check if character belongs to basic character literal set + // https://en.cppreference.com/w/cpp/language/charset + gsl_Expects(c == 0x00 || (0x07 <= c && c <= 0x0D) || (0x20 <= c && c <= 0x7E)); +} template constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[N + 1]) noexcept @@ -47,6 +57,12 @@ constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[N + 1]) no #endif } +template +constexpr fixed_u8string to_u8string(fixed_string txt) +{ + return std::bit_cast>(txt); +} + } // namespace detail @@ -57,37 +73,37 @@ constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[N + 1]) no * representation. In the libary it is used to define symbols of units and prefixes. * Each symbol can have two versions: Unicode and ASCI-only. * - * @tparam UnicodeCharT Character type to be used for a Unicode representation * @tparam N The size of a Unicode symbol * @tparam M The size of the ASCII-only symbol */ -template +template struct basic_symbol_text { - basic_fixed_string unicode_; - basic_fixed_string ascii_; + fixed_u8string unicode_; + fixed_string ascii_; - constexpr explicit(false) basic_symbol_text(char txt) : unicode_(txt), ascii_(txt) + constexpr explicit(false) basic_symbol_text(char txt) : unicode_(static_cast(txt)), ascii_(txt) { detail::validate_ascii_char(txt); } - constexpr explicit(false) basic_symbol_text(const char (&txt)[N + 1]) : unicode_(txt), ascii_(txt) + constexpr explicit(false) basic_symbol_text(const char (&txt)[N + 1]) : + unicode_(detail::to_u8string(basic_fixed_string{txt})), ascii_(txt) { detail::validate_ascii_string(txt); } - constexpr explicit(false) basic_symbol_text(const basic_fixed_string& txt) : unicode_(txt), ascii_(txt) + constexpr explicit(false) basic_symbol_text(const fixed_string& txt) : + unicode_(detail::to_u8string(txt)), ascii_(txt) { detail::validate_ascii_string(txt.data_); } - constexpr basic_symbol_text(const UnicodeCharT (&u)[N + 1], const char (&a)[M + 1]) : unicode_(u), ascii_(a) + constexpr basic_symbol_text(const char8_t (&u)[N + 1], const char (&a)[M + 1]) : unicode_(u), ascii_(a) { detail::validate_ascii_string(a); } - constexpr basic_symbol_text(const basic_fixed_string& u, const basic_fixed_string& a) : - unicode_(u), ascii_(a) + constexpr basic_symbol_text(const fixed_u8string& u, const fixed_string& a) : unicode_(u), ascii_(a) { detail::validate_ascii_string(a.data_); } @@ -98,15 +114,15 @@ struct basic_symbol_text { [[nodiscard]] constexpr bool empty() const { return unicode().empty() && ascii().empty(); } template - [[nodiscard]] constexpr friend basic_symbol_text operator+( - const basic_symbol_text& lhs, const basic_symbol_text& rhs) + [[nodiscard]] constexpr friend basic_symbol_text operator+(const basic_symbol_text& lhs, + const basic_symbol_text& rhs) { - return basic_symbol_text(lhs.unicode() + rhs.unicode(), lhs.ascii() + rhs.ascii()); + return basic_symbol_text(lhs.unicode() + rhs.unicode(), lhs.ascii() + rhs.ascii()); } - template + template [[nodiscard]] friend constexpr auto operator<=>(const basic_symbol_text& lhs, - const basic_symbol_text& rhs) noexcept + const basic_symbol_text& rhs) noexcept { MP_UNITS_DIAGNOSTIC_PUSH MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT @@ -115,27 +131,26 @@ struct basic_symbol_text { return lhs.ascii() <=> rhs.ascii(); } - template + template [[nodiscard]] friend constexpr bool operator==(const basic_symbol_text& lhs, - const basic_symbol_text& rhs) noexcept + const basic_symbol_text& rhs) noexcept { return lhs.unicode() == rhs.unicode() && lhs.ascii() == rhs.ascii(); } }; -basic_symbol_text(char) -> basic_symbol_text; +basic_symbol_text(char) -> basic_symbol_text<1, 1>; template -basic_symbol_text(const char (&)[N]) -> basic_symbol_text; +basic_symbol_text(const char (&)[N]) -> basic_symbol_text; template -basic_symbol_text(const basic_fixed_string&) -> basic_symbol_text; +basic_symbol_text(const fixed_string&) -> basic_symbol_text; -template -basic_symbol_text(const UnicodeCharT (&)[N], const char (&)[M]) -> basic_symbol_text; +template +basic_symbol_text(const char8_t (&)[N], const char (&)[M]) -> basic_symbol_text; -template -basic_symbol_text(const basic_fixed_string&, const basic_fixed_string&) - -> basic_symbol_text; +template +basic_symbol_text(const fixed_u8string&, const fixed_string&) -> basic_symbol_text; } // namespace mp_units diff --git a/src/core/include/mp-units/bits/text_tools.h b/src/core/include/mp-units/bits/text_tools.h index 9a17f3a3..40fe0d62 100644 --- a/src/core/include/mp-units/bits/text_tools.h +++ b/src/core/include/mp-units/bits/text_tools.h @@ -29,32 +29,32 @@ namespace mp_units::detail { template requires(0 <= Value) && (Value < 10) -inline constexpr basic_fixed_string superscript_number = ""; +inline constexpr basic_fixed_string superscript_number = u8""; template<> -inline constexpr basic_fixed_string superscript_number<0> = "\u2070"; +inline constexpr basic_fixed_string superscript_number<0> = u8"\u2070"; template<> -inline constexpr basic_fixed_string superscript_number<1> = "\u00b9"; +inline constexpr basic_fixed_string superscript_number<1> = u8"\u00b9"; template<> -inline constexpr basic_fixed_string superscript_number<2> = "\u00b2"; +inline constexpr basic_fixed_string superscript_number<2> = u8"\u00b2"; template<> -inline constexpr basic_fixed_string superscript_number<3> = "\u00b3"; +inline constexpr basic_fixed_string superscript_number<3> = u8"\u00b3"; template<> -inline constexpr basic_fixed_string superscript_number<4> = "\u2074"; +inline constexpr basic_fixed_string superscript_number<4> = u8"\u2074"; template<> -inline constexpr basic_fixed_string superscript_number<5> = "\u2075"; +inline constexpr basic_fixed_string superscript_number<5> = u8"\u2075"; template<> -inline constexpr basic_fixed_string superscript_number<6> = "\u2076"; +inline constexpr basic_fixed_string superscript_number<6> = u8"\u2076"; template<> -inline constexpr basic_fixed_string superscript_number<7> = "\u2077"; +inline constexpr basic_fixed_string superscript_number<7> = u8"\u2077"; template<> -inline constexpr basic_fixed_string superscript_number<8> = "\u2078"; +inline constexpr basic_fixed_string superscript_number<8> = u8"\u2078"; template<> -inline constexpr basic_fixed_string superscript_number<9> = "\u2079"; +inline constexpr basic_fixed_string superscript_number<9> = u8"\u2079"; -inline constexpr basic_symbol_text superscript_minus("\u207b", "-"); +inline constexpr basic_symbol_text superscript_minus(u8"\u207b", "-"); -inline constexpr basic_symbol_text superscript_prefix("", "^"); +inline constexpr basic_symbol_text superscript_prefix(u8"", "^"); template [[nodiscard]] consteval auto superscript_helper() diff --git a/src/core/include/mp-units/unit.h b/src/core/include/mp-units/unit.h index e586ec87..8e332d2b 100644 --- a/src/core/include/mp-units/unit.h +++ b/src/core/include/mp-units/unit.h @@ -92,7 +92,7 @@ inline constexpr bool is_specialization_of_scaled_unit> = true * inline constexpr struct metre : named_unit<"m", length> {} metre; * inline constexpr struct hertz : named_unit<"Hz", inverse(second)> {} hertz; * inline constexpr struct newton : named_unit<"N", kilogram * metre / square(second)> {} newton; - * inline constexpr struct degree_Celsius : named_unit {} degree_Celsius; + * inline constexpr struct degree_Celsius : named_unit<{u8"°C", "`C"}, kelvin> {} degree_Celsius; * inline constexpr struct minute : named_unit<"min", mag<60> * second> {} minute; * @endcode * @@ -604,7 +604,7 @@ template // common dimensionless units // clang-format off inline constexpr struct percent : named_unit<"%", mag * one> {} percent; -inline constexpr struct per_mille : named_unit * one> {} per_mille; +inline constexpr struct per_mille : named_unit * one> {} per_mille; inline constexpr struct parts_per_million : named_unit<"ppm", mag * one> {} parts_per_million; inline constexpr auto ppm = parts_per_million; // clang-format on @@ -699,17 +699,19 @@ struct unit_symbol_formatting { namespace detail { -// TODO Should `basic_symbol_text` be fixed to use `char` type for both encodings? -template Out> -constexpr Out copy(const basic_symbol_text& txt, text_encoding encoding, Out out) +template Out> +constexpr Out copy(const basic_symbol_text& txt, text_encoding encoding, Out out) { if (encoding == text_encoding::unicode) { - if (is_same_v) + if constexpr (is_same_v) return copy(txt.unicode(), out).out; - else + else if constexpr (is_same_v) { + for (char8_t ch : txt.unicode()) *out++ = static_cast(ch); + return out; + } else throw std::invalid_argument("Unicode text can't be copied to CharT output"); } else { - if (is_same_v) + if constexpr (is_same_v) return copy(txt.ascii(), out).out; else throw std::invalid_argument("ASCII text can't be copied to CharT output"); diff --git a/src/systems/include/mp-units/systems/angular/units.h b/src/systems/include/mp-units/systems/angular/units.h index cfe1e192..1f129781 100644 --- a/src/systems/include/mp-units/systems/angular/units.h +++ b/src/systems/include/mp-units/systems/angular/units.h @@ -35,8 +35,8 @@ QUANTITY_SPEC(solid_angle, pow<2>(angle)); inline constexpr struct radian : named_unit<"rad", kind_of> {} radian; inline constexpr struct revolution : named_unit<"rev", mag<2> * mag_pi * radian> {} revolution; -inline constexpr struct degree : named_unit * revolution> {} degree; -inline constexpr struct gradian : named_unit * revolution> {} gradian; +inline constexpr struct degree : named_unit * revolution> {} degree; +inline constexpr struct gradian : named_unit * revolution> {} gradian; inline constexpr struct steradian : named_unit<"sr", square(radian)> {} steradian; // clang-format on diff --git a/src/systems/include/mp-units/systems/iau/iau.h b/src/systems/include/mp-units/systems/iau/iau.h index cb30008b..17898f44 100644 --- a/src/systems/include/mp-units/systems/iau/iau.h +++ b/src/systems/include/mp-units/systems/iau/iau.h @@ -38,7 +38,7 @@ inline constexpr struct Julian_year : named_unit<"a", mag * // mass // https://en.wikipedia.org/wiki/Solar_mass // TODO What is the official mass of sun (every source in the Internet provides a different value) -inline constexpr struct solar_mass : named_unit * mag_power<10, 30> * si::kilogram> {} solar_mass; +inline constexpr struct solar_mass : named_unit * mag_power<10, 30> * si::kilogram> {} solar_mass; inline constexpr struct Jupiter_mass : named_unit<"M_JUP", mag * mag_power<10, 27> * si::kilogram> {} Jupiter_mass; inline constexpr struct Earth_mass : named_unit<"M_EARTH", mag * mag_power<10, 24> * si::kilogram> {} Earth_mass; @@ -55,7 +55,7 @@ inline constexpr struct light_year : named_unit<"ly", mag<9'460'730'472'580'800> inline constexpr struct parsec : named_unit<"pc", astronomical_unit / (mag * si::degree)> {} parsec; // https://en.wikipedia.org/wiki/Angstrom -inline constexpr struct angstrom : named_unit * si::metre> {} angstrom; +inline constexpr struct angstrom : named_unit * si::metre> {} angstrom; // selected constants // https://en.wikipedia.org/wiki/Astronomical_constant @@ -63,13 +63,13 @@ inline constexpr struct gaussian_gravitational_constant : named_unit<"k", mag * pow<3, 2>(astronomical_unit) / pow<1,2>(solar_mass) / day> {} gaussian_gravitational_constant; inline constexpr struct speed_of_light : - named_unit {} speed_of_light; + named_unit {} speed_of_light; inline constexpr struct constant_of_gravitation : named_unit<"G", mag * mag_power<10, -11> * cubic(si::metre) / si::kilogram / square(si::second)> {} constant_of_gravitation; inline constexpr struct hubble_constant : - named_unit * si::kilo / si::second / si::mega> {} hubble_constant; + named_unit * si::kilo / si::second / si::mega> {} hubble_constant; // clang-format on namespace unit_symbols { diff --git a/src/systems/include/mp-units/systems/isq/base_quantities.h b/src/systems/include/mp-units/systems/isq/base_quantities.h index f10c7fc3..e57d8ec6 100644 --- a/src/systems/include/mp-units/systems/isq/base_quantities.h +++ b/src/systems/include/mp-units/systems/isq/base_quantities.h @@ -34,7 +34,7 @@ inline constexpr struct dim_length : base_dimension<"L"> {} dim_length; inline constexpr struct dim_mass : base_dimension<"M"> {} dim_mass; inline constexpr struct dim_time : base_dimension<"T"> {} dim_time; inline constexpr struct dim_electric_current : base_dimension<"I"> {} dim_electric_current; -inline constexpr struct dim_thermodynamic_temperature : base_dimension {} dim_thermodynamic_temperature; +inline constexpr struct dim_thermodynamic_temperature : base_dimension {} dim_thermodynamic_temperature; inline constexpr struct dim_amount_of_substance : base_dimension<"N"> {} dim_amount_of_substance; inline constexpr struct dim_luminous_intensity : base_dimension<"J"> {} dim_luminous_intensity; // clang-format on diff --git a/src/systems/include/mp-units/systems/si/constants.h b/src/systems/include/mp-units/systems/si/constants.h index b342ba5d..53d499e4 100644 --- a/src/systems/include/mp-units/systems/si/constants.h +++ b/src/systems/include/mp-units/systems/si/constants.h @@ -31,7 +31,7 @@ namespace si2019 { // clang-format off inline constexpr struct hyperfine_structure_transition_frequency_of_cs : - named_unit * hertz> {} hyperfine_structure_transition_frequency_of_cs; + named_unit * hertz> {} hyperfine_structure_transition_frequency_of_cs; inline constexpr struct speed_of_light_in_vacuum : named_unit<"c", mag<299'792'458> * metre / second> {} speed_of_light_in_vacuum; inline constexpr struct planck_constant : @@ -50,9 +50,9 @@ inline constexpr struct luminous_efficacy : // clang-format off inline constexpr struct standard_gravity : - named_unit * metre / square(second)> {} standard_gravity; + named_unit * metre / square(second)> {} standard_gravity; inline constexpr struct magnetic_constant : - named_unit * mag_pi * mag_power<10, -7> * henry / metre> {} magnetic_constant; + named_unit * mag_pi * mag_power<10, -7> * henry / metre> {} magnetic_constant; // clang-format on } // namespace mp_units::si diff --git a/src/systems/include/mp-units/systems/si/prefixes.h b/src/systems/include/mp-units/systems/si/prefixes.h index 09582df0..0984f74f 100644 --- a/src/systems/include/mp-units/systems/si/prefixes.h +++ b/src/systems/include/mp-units/systems/si/prefixes.h @@ -35,7 +35,7 @@ template struct atto_ : prefixed_unit<"a", mag_power<10, -18> 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 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{}> {}; diff --git a/src/systems/include/mp-units/systems/si/units.h b/src/systems/include/mp-units/systems/si/units.h index b8cd3fce..9c622072 100644 --- a/src/systems/include/mp-units/systems/si/units.h +++ b/src/systems/include/mp-units/systems/si/units.h @@ -70,7 +70,7 @@ inline constexpr struct watt : named_unit<"W", joule / second> {} watt; inline constexpr struct coulomb : named_unit<"C", ampere * second> {} coulomb; inline constexpr struct volt : named_unit<"V", watt / ampere> {} volt; inline constexpr struct farad : named_unit<"F", coulomb / volt> {} farad; -inline constexpr struct ohm : named_unit {} ohm; +inline constexpr struct ohm : named_unit {} ohm; inline constexpr struct siemens : named_unit<"S", one / ohm> {} siemens; inline constexpr struct weber : named_unit<"Wb", volt * second> {} weber; inline constexpr struct tesla : named_unit<"T", weber / square(metre)> {} tesla; @@ -78,7 +78,7 @@ inline constexpr struct henry : named_unit<"H", weber / ampere> {} henry; inline constexpr struct ice_point : relative_point_origin}> {} ice_point; inline constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius; -inline constexpr struct degree_Celsius : named_unit {} degree_Celsius; +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; @@ -98,9 +98,9 @@ inline constexpr struct minute : named_unit<"min", mag<60> * si::second> {} minu 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> * 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 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(si::deca)> {} are; #if MP_UNITS_COMP_MSVC inline constexpr struct hectare : si::hecto_ {} hectare; diff --git a/src/systems/include/mp-units/systems/usc/usc.h b/src/systems/include/mp-units/systems/usc/usc.h index b126c983..909a8eb2 100644 --- a/src/systems/include/mp-units/systems/usc/usc.h +++ b/src/systems/include/mp-units/systems/usc/usc.h @@ -111,7 +111,7 @@ inline constexpr struct inch_of_mercury : named_unit<"inHg", mag * si::degree_Celsius)> {} zeroth_degree_Fahrenheit; -inline constexpr struct degree_Fahrenheit : named_unit * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit; +inline constexpr struct degree_Fahrenheit : named_unit * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit; // clang-format on diff --git a/test/static/symbol_text_test.cpp b/test/static/symbol_text_test.cpp index 950c39e6..17b4c5dd 100644 --- a/test/static/symbol_text_test.cpp +++ b/test/static/symbol_text_test.cpp @@ -40,30 +40,30 @@ static_assert(sym1 <= 'b'); static_assert(sym1 <= 'c'); static_assert(sym1 >= 'b'); static_assert(sym1 >= 'a'); -static_assert(sym1.unicode() == "b"); +static_assert(sym1.unicode() == u8"b"); static_assert(sym1.ascii() == "b"); constexpr basic_symbol_text sym3("ab"); -static_assert(sym3.unicode() == "ab"); +static_assert(sym3.unicode() == u8"ab"); static_assert(sym3.ascii() == "ab"); constexpr basic_fixed_string txt1("bc"); constexpr basic_symbol_text sym4(txt1); -static_assert(sym4.unicode() == "bc"); +static_assert(sym4.unicode() == u8"bc"); static_assert(sym4.ascii() == "bc"); -constexpr basic_symbol_text sym5("bc", "de"); -static_assert(sym5.unicode() == "bc"); +constexpr basic_symbol_text sym5(u8"bc", "de"); +static_assert(sym5.unicode() == u8"bc"); static_assert(sym5.ascii() == "de"); constexpr basic_fixed_string txt2("de"); constexpr basic_symbol_text sym6(sym4.unicode(), txt2); -static_assert(sym6.unicode() == "bc"); +static_assert(sym6.unicode() == u8"bc"); static_assert(sym6.ascii() == "de"); -static_assert(sym6 == basic_symbol_text("bc", "de")); -static_assert(sym6 != basic_symbol_text("fg", "hi")); -static_assert(sym6 != basic_symbol_text("bcd", "ef")); +static_assert(sym6 == basic_symbol_text(u8"bc", "de")); +static_assert(sym6 != basic_symbol_text(u8"fg", "hi")); +static_assert(sym6 != basic_symbol_text(u8"bcd", "ef")); static_assert(sym6 < basic_symbol_text("c")); static_assert(sym6 > basic_symbol_text("a")); @@ -75,13 +75,13 @@ static_assert(sym6 >= basic_symbol_text("bc")); static_assert(basic_symbol_text("a") + sym4 == basic_symbol_text("abc")); static_assert(sym4 + basic_symbol_text("f") == basic_symbol_text("bcf")); -static_assert(basic_symbol_text("a", "f") + sym6 == basic_symbol_text("abc", "fde")); -static_assert(sym6 + basic_symbol_text("a", "f") == basic_symbol_text("bca", "def")); +static_assert(basic_symbol_text(u8"a", "f") + sym6 == basic_symbol_text(u8"abc", "fde")); +static_assert(sym6 + basic_symbol_text(u8"a", "f") == basic_symbol_text(u8"bca", "def")); -static_assert(basic_symbol_text('a') + sym6 == basic_symbol_text("abc", "ade")); -static_assert(sym6 + basic_symbol_text('f') == basic_symbol_text("bcf", "def")); +static_assert(basic_symbol_text('a') + sym6 == basic_symbol_text(u8"abc", "ade")); +static_assert(sym6 + basic_symbol_text('f') == basic_symbol_text(u8"bcf", "def")); -static_assert(basic_symbol_text("a") + sym6 == basic_symbol_text("abc", "ade")); -static_assert(sym6 + basic_symbol_text("f") == basic_symbol_text("bcf", "def")); +static_assert(basic_symbol_text("a") + sym6 == basic_symbol_text(u8"abc", "ade")); +static_assert(sym6 + basic_symbol_text("f") == basic_symbol_text(u8"bcf", "def")); } // namespace diff --git a/test/static/unit_test.cpp b/test/static/unit_test.cpp index 6b3ab4d1..be2ce8bf 100644 --- a/test/static/unit_test.cpp +++ b/test/static/unit_test.cpp @@ -44,7 +44,7 @@ using percent_ = struct percent; inline constexpr struct dim_length_ : base_dimension<"L"> {} dim_length; inline constexpr struct dim_mass_ : base_dimension<"M"> {} dim_mass; inline constexpr struct dim_time_ : base_dimension<"T"> {} dim_time; -inline constexpr struct dim_thermodynamic_temperature_ : base_dimension {} dim_thermodynamic_temperature; +inline constexpr struct dim_thermodynamic_temperature_ : base_dimension {} dim_thermodynamic_temperature; // quantities specification QUANTITY_SPEC_(length, dim_length); @@ -71,11 +71,11 @@ inline constexpr struct newton_ : named_unit<"N", kilogram * metre / square(seco inline constexpr struct pascal_ : named_unit<"Pa", newton / square(metre)> {} pascal; inline constexpr struct joule_ : named_unit<"J", newton * metre> {} joule; inline constexpr struct watt_ : named_unit<"W", joule / second> {} watt; -inline constexpr struct degree_Celsius_ : named_unit {} degree_Celsius; +inline constexpr struct degree_Celsius_ : named_unit {} degree_Celsius; inline constexpr struct minute_ : named_unit<"min", mag<60> * second> {} minute; inline constexpr struct hour_ : named_unit<"h", mag<60> * minute> {} hour; -inline constexpr struct degree_ : named_unit * radian> {} degree; +inline constexpr struct degree_ : named_unit * radian> {} degree; inline constexpr struct yard_ : named_unit<"yd", mag * metre> {} yard; inline constexpr struct mile_ : named_unit<"mi", mag<1760> * yard> {} mile; @@ -84,7 +84,7 @@ inline constexpr struct kilometre_ : decltype(si::kilo) {} kilometre; inline constexpr struct kilojoule_ : decltype(si::kilo) {} kilojoule; // physical constant units -inline constexpr struct standard_gravity_ : named_unit * metre / square(second)> {} standard_gravity; +inline constexpr struct standard_gravity_ : named_unit * metre / square(second)> {} standard_gravity; inline constexpr struct speed_of_light_in_vacuum_ : named_unit<"c", mag<299'792'458> * metre / second> {} speed_of_light_in_vacuum; // clang-format on @@ -194,7 +194,7 @@ static_assert(convertible(standard_gravity, standard_gravity)); static_assert(convertible(standard_gravity, metre / square(second))); static_assert(standard_gravity == standard_gravity); static_assert(standard_gravity != metre / square(second)); // magnitude is different -static_assert(standard_gravity.symbol == basic_symbol_text{"g₀", "g_0"}); +static_assert(standard_gravity.symbol == basic_symbol_text{u8"g₀", "g_0"}); // prefixed_unit static_assert(is_of_type); @@ -229,7 +229,7 @@ static_assert(si::atto.symbol == "am"); static_assert(si::femto.symbol == "fm"); static_assert(si::pico.symbol == "pm"); static_assert(si::nano.symbol == "nm"); -static_assert(si::micro.symbol == basic_symbol_text{"µm", "um"}); +static_assert(si::micro.symbol == basic_symbol_text{u8"µm", "um"}); static_assert(si::milli.symbol == "mm"); static_assert(si::centi.symbol == "cm"); static_assert(si::deci.symbol == "dm");