Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constexpr constructors #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielytics
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest using constexpr
1 participant