decimal_for_cpp icon indicating copy to clipboard operation
decimal_for_cpp copied to clipboard

Add constexpr constructors

Open danielytics opened this issue 4 years ago • 0 comments

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.

danielytics avatar Sep 02 '21 20:09 danielytics