3 ms·
Something like this: auto operator"" _rpmPerVolt (long double x) { return decltype (1_rpm / 1_V)(x); } I have a macro for that: #defi
by majorexception 3y ago
Something like this:
auto
operator"" _rpmPerVolt (long double x) {
return decltype (1_rpm / 1_V)(x);
}
I have a macro for that:
#define SI_DEFINE_LITERAL(xUnit, xliteral) \
[[nodiscard]] \
constexpr Quantity<units::xUnit> \
operator"" xliteral (long double value) \
{ \
return Quantity<units::xUnit> (value); \
} \
\
[[nodiscard]] \
constexpr Quantity<units::xUnit> \
operator"" xliteral (unsigned long long value) \
{ \
return Quantity<units::xUnit> (value); \
}
// Base SI units:
SI_DEFINE_LITERAL (Meter, _m)
SI_DEFINE_LITERAL (Kilogram, _kg)
SI_DEFINE_LITERAL (Second, _s)
SI_DEFINE_LITERAL (Ampere, _A)
SI_DEFINE_LITERAL (Kelvin, _K)
SI_DEFINE_LITERAL (Mole, _mol)
SI_DEFINE_LITERAL (Candela, _cd)
SI_DEFINE_LITERAL (Radian, _rad)
...and a loong list of other common units here.
The additional types are defined like this, in another file:
using Foot = ScaledUnit<Meter, std::ratio<1'200, 3'937>>;
using Mile = ScaledUnit<Meter, std::ratio<1'609'344, 1'000>>;
using NauticalMile = ScaledUnit<Meter, std::ratio<1'852, 1>>;
using Inch = ScaledUnit<Meter, std::ratio<254, 10'000>>;
And then I use SI_DEFINE_LITERAL (NauticalMile, _nm); etc.