Skip to content

Commit

Permalink
Restore constexpr support for shorthand funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
chiphogg committed Sep 19, 2024
1 parent 8b6bd79 commit 9389e92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion au/code/au/quantity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class Quantity {
}

template <typename T>
void perform_shorthand_checks() {
constexpr void perform_shorthand_checks() {
static_assert(
IsValidRep<T>::value,
"This overload is only for scalar mult/div-assignment with raw numeric types");
Expand Down
10 changes: 10 additions & 0 deletions au/code/au/quantity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,16 @@ TEST(Quantity, ShorthandMultiplicationAssignmentWorksForComplexRepAndScalar) {
EXPECT_THAT(test, SameTypeAndValue(meters(std::complex<float>{2.5f, 2.5f})));
}

template <typename T>
constexpr T double_by_shorthand(T x) {
return x *= 2.0;
}

TEST(Quantity, ShorthandMultiplicationSupportsConstexpr) {
constexpr auto x = double_by_shorthand(feet(3.0));
EXPECT_THAT(x, SameTypeAndValue(feet(6.0)));
}

TEST(Quantity, ShorthandDivisionAssignmentWorksForComplexRepAndScalar) {
auto test = meters(std::complex<float>{25.0f, 12.5f});
test /= std::complex<float>{3.0f, 4.0f};
Expand Down

0 comments on commit 9389e92

Please sign in to comment.