forked from mpusz/mp-units
Compile-time performance of printing a prefix improved
This commit is contained in:
@@ -47,18 +47,19 @@ namespace units {
|
|||||||
void print_prefix_or_ratio(std::basic_ostream<CharT, Traits>& os)
|
void print_prefix_or_ratio(std::basic_ostream<CharT, Traits>& os)
|
||||||
{
|
{
|
||||||
if constexpr(Ratio::num != 1 || Ratio::den != 1) {
|
if constexpr(Ratio::num != 1 || Ratio::den != 1) {
|
||||||
|
if(!std::same_as<PrefixType, no_prefix>) {
|
||||||
using prefix = downcast_target<detail::prefix_base<PrefixType, Ratio>>;
|
using prefix = downcast_target<detail::prefix_base<PrefixType, Ratio>>;
|
||||||
|
|
||||||
if constexpr(!std::same_as<prefix, prefix_base<PrefixType, Ratio>>) {
|
if constexpr(!std::same_as<prefix, prefix_base<PrefixType, Ratio>>) {
|
||||||
// print as a prefixed unit
|
// print as a prefixed unit
|
||||||
os << prefix::symbol;
|
os << prefix::symbol;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// print as a ratio of the coherent unit
|
// print as a ratio of the coherent unit
|
||||||
print_ratio<Ratio>(os);
|
print_ratio<Ratio>(os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template<typename CharT, typename Traits, typename... Es>
|
template<typename CharT, typename Traits, typename... Es>
|
||||||
void print_dimensions(std::basic_ostream<CharT, Traits>& os, dimension<Es...>)
|
void print_dimensions(std::basic_ostream<CharT, Traits>& os, dimension<Es...>)
|
||||||
|
Reference in New Issue
Block a user