71 if (u.
value(system) >= 1._f) {
77 stream << u.
value(system) << selectedDesc->label;
89 for (std::string& part : parts) {
95 if (valueAndPower.
size() > 2) {
96 return makeUnexpected<Unit>(
"More than one exponent");
100 if (valueAndPower.
size() == 1) {
105 if (
Optional<int> optPower = fromString<int>(valueAndPower[1])) {
106 power = optPower.value();
108 return makeUnexpected<Unit>(
"Cannot convert power to int");
#define SPH_ASSERT(x,...)
Container storing sorted unique values.
uint32_t Size
Integral type used to index arrays (by default).
#define NAMESPACE_SPH_END
Array< std::string > split(const std::string &s, const char delimiter)
Splits a string into an array of string using given delimiter.
Expected< Unit > parseUnit(const std::string &text)
std::ostream & operator<<(std::ostream &stream, const Unit &u)
NAMESPACE_SPH_BEGIN UnitSystem CODE_UNITS
FlatMap< BasicDimension, FlatSet< UnitDesc > > UNITS
constexpr Size DIMENSION_CNT
INLINE TCounter size() const noexcept
Wrapper of type that either contains a value of given type, or an error message.
Container of key-value pairs.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
Wrapper of type value of which may or may not be present.
INLINE Type & value()
Returns the reference to the stored value.
static UnitDimensions dimensionless()
static Unit dimensionless(const Float value)
static Unit kilogram(const Float value)
Float value(const UnitSystem &system) const
Returns the value in given unit system.
UnitDimensions dimension() const
static Unit meter(const Float value)
constexpr Float au
Astronomical unit (exactly)
constexpr Float M_earth
Earth mass.
bool operator<(const UnitDesc &other) const