diff --git a/docs/users_guide/framework_basics/text_output.md b/docs/users_guide/framework_basics/text_output.md index 9dfee718..da529b85 100644 --- a/docs/users_guide/framework_basics/text_output.md +++ b/docs/users_guide/framework_basics/text_output.md @@ -272,8 +272,8 @@ kg⋅m⋅s⁻² Some [common units](systems_of_units.md#common-units) expressed with a specialization of the `common_unit` class template need special printing rules for their symbols. As they represent -a minimum set of common units resulting from the addition or subtraction of multiple quantities, -we print all of them as a scaled version of the source unit. For example the following: +a minimum set of equivalent common units resulting from the addition or subtraction of multiple +quantities, we print all of them as a scaled version of the source unit. For example the following: ```cpp std::cout << 1 * km + 1 * mi << "\n"; @@ -284,9 +284,9 @@ std::cout << 1 * km / h + 1 * m / s << "\n"; will print: ```text -40771 ([1/25146] mi = [1/15625] km) -108167 ([1/50292] mi = [1/57875] nmi) -23 ([1/5] km/h = [1/18] m/s) +40771 EQUIV{[1/25146] mi, [1/15625] km} +108167 EQUIV{[1/50292] mi, [1/57875] nmi} +23 EQUIV{[1/5] km/h, [1/18] m/s} ``` Thanks to the above, it might be easier for the user to reason about the magnitude of the resulting diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 6194b845..2bbbb67d 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -854,18 +854,19 @@ template Out, typename U, typename.. constexpr Out unit_symbol_impl(Out out, const common_unit&, const unit_symbol_formatting& fmt, bool negative_power) { - constexpr std::string_view separator(" = "); + constexpr std::string_view prefix("EQUIV{"); + constexpr std::string_view separator(", "); auto print_unit = [&](Arg) { constexpr auto u = get_common_unit_in(common_unit{}, Arg{}); unit_symbol_impl(out, u, fmt, negative_power); }; - *out++ = '('; + detail::copy(std::begin(prefix), std::end(prefix), out); print_unit(U{}); for_each(std::tuple{}, [&](Arg) { detail::copy(std::begin(separator), std::end(separator), out); print_unit(Arg{}); }); - *out++ = ')'; + *out++ = '}'; return out; } diff --git a/test/static/unit_symbol_test.cpp b/test/static/unit_symbol_test.cpp index ba3c37dc..38048470 100644 --- a/test/static/unit_symbol_test.cpp +++ b/test/static/unit_symbol_test.cpp @@ -117,12 +117,12 @@ static_assert(unit_symbol(mag<60> * s static_assert(unit_symbol(mag_ratio<1, 18> * metre / second) == "[1/18] m/s"); // common units -static_assert(unit_symbol(get_common_unit(kilo, mile)) == "([1/25146] mi = [1/15625] km)"); -static_assert(unit_symbol(get_common_unit(kilo / hour, metre / second)) == "([1/5] km/h = [1/18] m/s)"); +static_assert(unit_symbol(get_common_unit(kilo, mile)) == "EQUIV{[1/25146] mi, [1/15625] km}"); +static_assert(unit_symbol(get_common_unit(kilo / hour, metre / second)) == "EQUIV{[1/5] km/h, [1/18] m/s}"); static_assert(unit_symbol(get_common_unit(kilo / hour, metre / second) / second) == - "([1/5] km/h = [1/18] m/s)/s"); + "EQUIV{[1/5] km/h, [1/18] m/s}/s"); static_assert(unit_symbol(get_common_unit(kilo / hour, metre / second) * second) == - "([1/5] km/h = [1/18] m/s) s"); + "EQUIV{[1/5] km/h, [1/18] m/s} s"); // derived units static_assert(unit_symbol(one) == ""); // NOLINT(readability-container-size-empty)