diff --git a/src/core/include/mp-units/ostream.h b/src/core/include/mp-units/ostream.h index c648a810..248b05af 100644 --- a/src/core/include/mp-units/ostream.h +++ b/src/core/include/mp-units/ostream.h @@ -39,10 +39,8 @@ void to_stream(std::basic_ostream& os, const quantity& q) os << +q.numerical_value_ref_in(q.unit); else os << q.numerical_value_ref_in(q.unit); - if constexpr (has_unit_symbol(get_unit(R))) { - if constexpr (space_before_unit_symbol) os << " "; - unit_symbol_to(std::ostream_iterator(os), get_unit(R)); - } + if constexpr (space_before_unit_symbol) os << " "; + unit_symbol_to(std::ostream_iterator(os), get_unit(R)); } } // namespace detail diff --git a/src/core/include/mp-units/unit.h b/src/core/include/mp-units/unit.h index 7c210cd2..e586ec87 100644 --- a/src/core/include/mp-units/unit.h +++ b/src/core/include/mp-units/unit.h @@ -653,6 +653,23 @@ template } +/** + * @brief Puts a space ' ' sign before a unit symbol + * + * Quantities of some units (e.g. degree, arcminute, arcsecond) should not be printed with the + * space between a number and a unit. For those a partial specialization with the value `false` should + * be provided. + */ +template +inline constexpr bool space_before_unit_symbol = true; + +template<> +inline constexpr bool space_before_unit_symbol = false; +template<> +inline constexpr bool space_before_unit_symbol = false; +template<> +inline constexpr bool space_before_unit_symbol = false; + // get_unit_symbol enum class text_encoding : std::int8_t { @@ -713,12 +730,6 @@ constexpr Out print_separator(Out out, unit_symbol_formatting fmt) return out; } -template -[[nodiscard]] consteval bool has_unit_symbol(U) -{ - return requires { U::symbol; } || !std::derived_from>; -} - template Out, Unit U> requires requires { U::symbol; } constexpr Out unit_symbol_impl(Out out, U, unit_symbol_formatting fmt, bool negative_power) @@ -741,12 +752,8 @@ constexpr Out unit_symbol_impl(Out out, const scaled_unit& u, unit_symbol_ constexpr auto mag_txt = magnitude_text(); out = copy(mag_txt, fmt.encoding, out); - if constexpr (has_unit_symbol(scaled_unit::reference_unit)) { - *out++ = ' '; - return unit_symbol_impl(out, u.reference_unit, fmt, negative_power); - } else { - return out; - } + if constexpr (space_before_unit_symbol::reference_unit>) *out++ = ' '; + return unit_symbol_impl(out, u.reference_unit, fmt, negative_power); } } @@ -828,21 +835,6 @@ constexpr Out unit_symbol_impl(Out out, const derived_unit&, unit_symbo } // namespace detail -/** - * @brief Puts a space ' ' sign before a unit symbol - * - * Quantities of some units (e.g. degree, arcminute, arcsecond) should not be printed with the - * space between a number and a unit. For those a partial specialization with the value `false` should - * be provided. - */ -template -inline constexpr bool space_before_unit_symbol = true; - -template<> -inline constexpr bool space_before_unit_symbol = false; -template<> -inline constexpr bool space_before_unit_symbol = false; - template Out, Unit U> constexpr Out unit_symbol_to(Out out, U u, unit_symbol_formatting fmt = unit_symbol_formatting{}) {