Skip to content

Commit 6361daa

Browse files
committed
feat: EQUIV{...} replaced with [...] in the text output of common units
1 parent 088fb3c commit 6361daa

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

docs/users_guide/framework_basics/text_output.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ std::cout << 1 * rad + 1 * deg << "\n";
304304
prints:
305305

306306
```text
307-
40771 EQUIV{[1/25146 mi], [1/15625 km]}
308-
108167 EQUIV{[1/50292 mi], [1/57875 nmi]}
309-
23 EQUIV{[1/5 km/h], [1/18 m/s]}
310-
183.142 EQUIV{[1/π°], [1/180 rad]}
307+
40771 [(1/25146 mi), (1/15625 km)]
308+
108167 [(1/50292 mi), (1/57875 nmi)]
309+
23 [(1/5 km/h), (1/18 m/s)]
310+
183.142 [(1/π°), (1/180 rad)]
311311
```
312312

313313
Thanks to the above, it might be easier for the user to reason about the magnitude of the resulting

src/core/include/mp-units/framework/unit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ template<typename CharT, std::output_iterator<CharT> Out, typename U, typename..
802802
constexpr Out unit_symbol_impl(Out out, const common_unit<U, Rest...>&, const unit_symbol_formatting& fmt,
803803
bool negative_power)
804804
{
805-
constexpr std::string_view prefix("EQUIV{");
805+
constexpr std::string_view prefix("[");
806806
constexpr std::string_view separator(", ");
807807
auto print_unit = [&]<Unit Arg>(Arg) {
808808
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
814814
detail::copy(std::begin(separator), std::end(separator), out);
815815
print_unit(Arg{});
816816
});
817-
*out++ = '}';
817+
*out++ = ']';
818818
return out;
819819
}
820820

test/static/unit_symbol_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ static_assert(unit_symbol(mag<2> / (mag<π> * mag<e>)*one) == "(2 e⁻¹ π⁻¹
204204
static_assert(unit_symbol<usf{.solidus = always}>(mag<2> / (mag<π> * mag<e>)*one) == "(2/(e π))");
205205

206206
// common units
207-
static_assert(unit_symbol(get_common_unit(kilo<metre>, mile)) == "EQUIV{(1/25146 mi), (1/15625 km)}");
208-
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second)) == "EQUIV{(1/5 km/h), (1/18 m/s)}");
207+
static_assert(unit_symbol(get_common_unit(kilo<metre>, mile)) == "[(1/25146 mi), (1/15625 km)]");
208+
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second)) == "[(1/5 km/h), (1/18 m/s)]");
209209
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) / second) ==
210-
"EQUIV{(1/5 km/h), (1/18 m/s)}/s");
210+
"[(1/5 km/h), (1/18 m/s)]/s");
211211
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) * second) ==
212-
"EQUIV{(1/5 km/h), (1/18 m/s)} s");
213-
static_assert(unit_symbol(get_common_unit(radian, degree)) == "EQUIV{(1/π°), (1/180 rad)}");
212+
"[(1/5 km/h), (1/18 m/s)] s");
213+
static_assert(unit_symbol(get_common_unit(radian, degree)) == "[(1/π°), (1/180 rad)]");
214214

215215
// derived units
216216
static_assert(unit_symbol(one) == ""); // NOLINT(readability-container-size-empty)

0 commit comments

Comments
 (0)