-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support constexpr
in min
and max
#251
Conversation
These have been `constexpr` compatible since C++14. Mechanically, the way I did this was: 1. Find an overload that was not `constexpr`. 2. Make a test that requires it to be `constexpr` to pass (either tweaking an existing test, or making a new one). 3. Make sure the test fails. 4. Change the function until the test passes. The biggest challenge was that our default compiler wouldn't accept our lambda in a `constexpr` context. That feels like a bug, but in any case, we were able to work around it by making a manual function object with an explicitly `constexpr` call operator. Fixes #244.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes make sense. It looks like lambdas in a constexpr
context have been added in C++17: https://stackoverflow.com/a/32697323
Well... that would sure explain why it didn't work before! TIL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, thanks!
@@ -318,31 +318,41 @@ constexpr bool isnan(QuantityPoint<U, R> p) { | |||
return std::isnan(p.in(U{})); | |||
} | |||
|
|||
namespace detail { | |||
// Some compilers do not support lambdas in constexpr contexts, so we make a manual function object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the comment about this being a C++17 thing, or is it the case that even with C++17, some compilers still don't support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Addressed in #252.
These have been
constexpr
compatible since C++14. Mechanically, theway I did this was:
constexpr
.constexpr
to pass (eithertweaking an existing test, or making a new one).
The biggest challenge was that our default compiler wouldn't accept our
lambda in a
constexpr
context. That feels like a bug, but in anycase, we were able to work around it by making a manual function object
with an explicitly
constexpr
call operator.Fixes #244.