forked from mpusz/mp-units
ostream width, align and fill added
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <units/bits/external/text_tools.h>
|
||||
#include <units/prefix.h>
|
||||
#include <units/derived_dimension.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace units::detail {
|
||||
|
||||
@@ -161,4 +162,16 @@ constexpr auto unit_text()
|
||||
}
|
||||
}
|
||||
|
||||
template<typename CharT, class Traits, Quantity Q>
|
||||
std::basic_string<CharT> to_string(const Q& q)
|
||||
{
|
||||
std::basic_ostringstream<CharT, Traits> s;
|
||||
s << q.count();
|
||||
constexpr auto symbol = unit_text<typename Q::dimension, typename Q::unit>();
|
||||
if constexpr (symbol.size()) {
|
||||
s << " " << symbol;
|
||||
}
|
||||
return s.str();
|
||||
}
|
||||
|
||||
} // namespace units::detail
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <units/bits/common_quantity.h>
|
||||
#include <units/bits/dimension_op.h>
|
||||
#include <units/bits/unit_text.h>
|
||||
#include <units/bits/to_string.h>
|
||||
#include <units/quantity_cast.h>
|
||||
|
||||
#if __GNUC__ >= 10
|
||||
@@ -62,7 +62,7 @@ concept safe_divisible = // exposition only
|
||||
*/
|
||||
template<Dimension D, UnitOf<D> U, Scalar Rep = double>
|
||||
class quantity {
|
||||
Rep value_;
|
||||
Rep value_{};
|
||||
|
||||
public:
|
||||
using dimension = D;
|
||||
@@ -308,12 +308,7 @@ public:
|
||||
template<class CharT, class Traits>
|
||||
friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const quantity& q)
|
||||
{
|
||||
constexpr auto symbol = detail::unit_text<quantity::dimension, quantity::unit>();
|
||||
os << q.count();
|
||||
if (symbol.size()) {
|
||||
os << " " << symbol;
|
||||
}
|
||||
return os;
|
||||
return os << detail::to_string<CharT, Traits>(q);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user