forked from mpusz/mp-units
fix: regression in quantity::op<<() for the case of std::setw() fixed
This commit is contained in:
@@ -178,4 +178,14 @@ constexpr auto unit_text()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename CharT, class Traits, typename D, typename U, typename Rep>
|
||||||
|
void to_stream(std::basic_ostream<CharT, Traits>& os, const quantity<D, U, Rep>& q)
|
||||||
|
{
|
||||||
|
os << q.count();
|
||||||
|
constexpr auto symbol = detail::unit_text<D, U>();
|
||||||
|
if constexpr (symbol.standard().size()) {
|
||||||
|
os << " " << symbol.standard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace units::detail
|
} // namespace units::detail
|
||||||
|
@@ -334,11 +334,14 @@ public:
|
|||||||
template<class CharT, class Traits>
|
template<class CharT, class Traits>
|
||||||
friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const quantity& q)
|
friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const quantity& q)
|
||||||
{
|
{
|
||||||
os << q.count();
|
if(os.width()) {
|
||||||
constexpr auto symbol = detail::unit_text<D, U>();
|
// std::setw() applies to the whole quantity output so it has to be first put into std::string
|
||||||
if constexpr (symbol.standard().size()) {
|
std::basic_ostringstream<CharT, Traits> s;
|
||||||
os << " " << symbol.standard();
|
detail::to_stream(s, q);
|
||||||
|
return os << s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detail::to_stream(os, q);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user