aurora-opensource / au

A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience.
Apache License 2.0
329 stars 21 forks source link

Support `constexpr` in `min` and `max` #251

Closed chiphogg closed 5 months ago

chiphogg commented 5 months ago

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 commented 5 months ago

Well... that would sure explain why it didn't work before! TIL.