Support SFINAE in Constant representability check#669
Merged
Conversation
Right now, we have an unconditional `UnitRatio` invocation, which produces a hard compiler error. We thought this was fine, because nobody should be invoking this check with different-dimension units. However, it somehow does get invoked in Aurora-internal code. I tried reproducing the error in the Au repo only, and couldn't do it. But in any case, we can fix it by just avoiding the hard error. The most straightforward way to fix it was to just make a new trait, `IsUnitRatioRepresentableIn<T, U1, U2>`. This doesn't seem like something I want to expose to end users, so I kept it as a library internal detail.
geoffviola
reviewed
Apr 6, 2026
| } | ||
|
|
||
| TEST(CanStoreValueIn, ReturnsFalseRatherThanHardErrorForDifferentDimensions) { | ||
| constexpr bool result = Constant<Meters>::can_store_value_in<long>(Nano<Seconds>{}); |
Contributor
There was a problem hiding this comment.
Does the size of long matter? It's 8 bytes for GCC and 4 bytes for MSVC: godbolt.
Member
Author
There was a problem hiding this comment.
In this specific case, definitely not. The answer doesn't depend on the ratio, because the ratio is not even well defined. It will return false because the dimensions are different.
| // same dimension. | ||
| namespace detail { | ||
| template <typename T, typename U1, typename U2> | ||
| struct IsUnitRatioRepresentableIn; |
Contributor
There was a problem hiding this comment.
Q: Does it make sense to unit test this?
Member
Author
There was a problem hiding this comment.
I hadn't been planning on it initially, but I agree it makes sense to add them.
geoffviola
approved these changes
Apr 6, 2026
geoffviola
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now, we have an unconditional
UnitRatioinvocation, whichproduces a hard compiler error. We thought this was fine, because
nobody should be invoking this check with different-dimension units.
However, it somehow does get invoked in Aurora-internal code.
I tried reproducing the error in the Au repo only, and couldn't do it.
But in any case, we can fix it by just avoiding the hard error.
The most straightforward way to fix it was to just make a new trait,
IsUnitRatioRepresentableIn<T, U1, U2>. This doesn't seem likesomething I want to expose to end users, so I kept it as a library
internal detail.