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

min and max functions are not constexpr #244

Closed
hoffbrinkle opened this issue Jun 11, 2024 · 0 comments · Fixed by #251
Closed

min and max functions are not constexpr #244

hoffbrinkle opened this issue Jun 11, 2024 · 0 comments · Fixed by #251
Labels
⬇️ affects: code (interfaces) Affects the way end users will interact with the library 📁 kind: enhancement New feature or request 💪 effort: small

Comments

@hoffbrinkle
Copy link
Contributor

C++'s std::max and std::min have been constexpr since C++14. It would be fantastic to have the Au implementations of max and min similarly constexpr so they could be used similar to those in the standard library.

@chiphogg chiphogg added 📁 kind: enhancement New feature or request 💪 effort: small ⬇️ affects: code (interfaces) Affects the way end users will interact with the library labels Jun 11, 2024
chiphogg added a commit that referenced this issue Jun 23, 2024
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.
chiphogg added a commit that referenced this issue Jun 24, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬇️ affects: code (interfaces) Affects the way end users will interact with the library 📁 kind: enhancement New feature or request 💪 effort: small
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants