feat: EQUIV{...} replaced with [...] in the text output of common units

This commit is contained in:
Mateusz Pusz
2025-06-18 08:53:46 +02:00
parent 088fb3ca9f
commit 6361daa76f
3 changed files with 11 additions and 11 deletions

View File

@ -304,10 +304,10 @@ std::cout << 1 * rad + 1 * deg << "\n";
prints: prints:
```text ```text
40771 EQUIV{[1/25146 mi], [1/15625 km]} 40771 [(1/25146 mi), (1/15625 km)]
108167 EQUIV{[1/50292 mi], [1/57875 nmi]} 108167 [(1/50292 mi), (1/57875 nmi)]
23 EQUIV{[1/5 km/h], [1/18 m/s]} 23 [(1/5 km/h), (1/18 m/s)]
183.142 EQUIV{[1/π°], [1/180 rad]} 183.142 [(1/π°), (1/180 rad)]
``` ```
Thanks to the above, it might be easier for the user to reason about the magnitude of the resulting Thanks to the above, it might be easier for the user to reason about the magnitude of the resulting

View File

@ -802,7 +802,7 @@ template<typename CharT, std::output_iterator<CharT> Out, typename U, typename..
constexpr Out unit_symbol_impl(Out out, const common_unit<U, Rest...>&, const unit_symbol_formatting& fmt, constexpr Out unit_symbol_impl(Out out, const common_unit<U, Rest...>&, const unit_symbol_formatting& fmt,
bool negative_power) bool negative_power)
{ {
constexpr std::string_view prefix("EQUIV{"); constexpr std::string_view prefix("[");
constexpr std::string_view separator(", "); constexpr std::string_view separator(", ");
auto print_unit = [&]<Unit Arg>(Arg) { auto print_unit = [&]<Unit Arg>(Arg) {
constexpr auto u = get_common_unit_in(common_unit<U, Rest...>{}, Arg{}); constexpr auto u = get_common_unit_in(common_unit<U, Rest...>{}, Arg{});
@ -814,7 +814,7 @@ constexpr Out unit_symbol_impl(Out out, const common_unit<U, Rest...>&, const un
detail::copy(std::begin(separator), std::end(separator), out); detail::copy(std::begin(separator), std::end(separator), out);
print_unit(Arg{}); print_unit(Arg{});
}); });
*out++ = '}'; *out++ = ']';
return out; return out;
} }

View File

@ -204,13 +204,13 @@ static_assert(unit_symbol(mag<2> / (mag<π> * mag<e>)*one) == "(2 e⁻¹ π⁻¹
static_assert(unit_symbol<usf{.solidus = always}>(mag<2> / (mag<π> * mag<e>)*one) == "(2/(e π))"); static_assert(unit_symbol<usf{.solidus = always}>(mag<2> / (mag<π> * mag<e>)*one) == "(2/(e π))");
// common units // common units
static_assert(unit_symbol(get_common_unit(kilo<metre>, mile)) == "EQUIV{(1/25146 mi), (1/15625 km)}"); static_assert(unit_symbol(get_common_unit(kilo<metre>, mile)) == "[(1/25146 mi), (1/15625 km)]");
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second)) == "EQUIV{(1/5 km/h), (1/18 m/s)}"); static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second)) == "[(1/5 km/h), (1/18 m/s)]");
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) / second) == static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) / second) ==
"EQUIV{(1/5 km/h), (1/18 m/s)}/s"); "[(1/5 km/h), (1/18 m/s)]/s");
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) * second) == static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) * second) ==
"EQUIV{(1/5 km/h), (1/18 m/s)} s"); "[(1/5 km/h), (1/18 m/s)] s");
static_assert(unit_symbol(get_common_unit(radian, degree)) == "EQUIV{(1/π°), (1/180 rad)}"); static_assert(unit_symbol(get_common_unit(radian, degree)) == "[(1/π°), (1/180 rad)]");
// derived units // derived units
static_assert(unit_symbol(one) == ""); // NOLINT(readability-container-size-empty) static_assert(unit_symbol(one) == ""); // NOLINT(readability-container-size-empty)