diff --git a/src/include/units/format.h b/src/include/units/format.h index 92389236..78b4f694 100644 --- a/src/include/units/format.h +++ b/src/include/units/format.h @@ -116,12 +116,6 @@ namespace units { return format_to(out, treat_as_floating_point ? "{:" + sign_text + "g}" : "{:" + sign_text + "}", val); } - template - inline static OutputIt format_units_quantity_unit(OutputIt out) - { - return format_to(out, "{}", unit_text().c_str()); - } - template struct units_formatter { OutputIt out; @@ -147,7 +141,7 @@ namespace units { void on_quantity_unit() { - out = format_units_quantity_unit(out); + format_to(out, "{}", unit_text().c_str()); } }; @@ -306,10 +300,13 @@ public: // deal with quantity content if(begin == end || *begin == '}') { - // default format should print value followed by the unit separeted with 1 space + // default format should print value followed by the unit separated with 1 space out = units::detail::format_units_quantity_value(out, q.count(), specs.sign, precision); - *out++ = CharT(' '); - units::detail::format_units_quantity_unit(out); + constexpr auto symbol = units::detail::unit_text(); + if(symbol.size()) { + *out++ = CharT(' '); + format_to(out, "{}", symbol.c_str()); + } } else { // user provided format diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index ba26180f..3a3dab58 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -308,7 +308,12 @@ public: template friend std::basic_ostream& operator<<(std::basic_ostream& os, const quantity& q) { - return os << q.count() << " " << detail::unit_text(); + constexpr auto symbol = detail::unit_text(); + os << q.count(); + if (symbol.size()) { + os << " " << symbol; + } + return os; } };