decimal_for_cpp
decimal_for_cpp copied to clipboard
Add constexpr constructors
Fixes #40
I wanted to get this code working:
using Quantity = dec::decimal<8>;
[[nodiscard]] constexpr Quantity operator"" _qty(unsigned long long value) noexcept {
return Quantity{int(value)};
}
[[nodiscard]] constexpr Quantity operator"" _qty(long double value) noexcept {
return Quantity{value};
}
void test() {
Quantity q = 12.1_qty;
}
and this change makes this work. It just marks the constructors as constexpr (when using C++11), it doesn't change any other function. This seems to be enough for my use case.