You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using 1_m makes the compiler look for operators in the units namespace but since my::Position is not a units type, the first failsafe operator above is selected in the overload set (traits::is_same_scale<UnitTypeLhs, UnitTypeRhs>::value is false) and the static_assert is triggered.
I think the failsafe operator must also include a traits::is_unit_t<UnitTypeLhs>::value and traits::is_unit_t<UnitTypeRhs>::value in his enable_if so that it is only selected when appropriate.
I'm willing to write a PR if you think the approach is correct.
EDIT: I though this problem was for all operators but it looks like it's just operator+.
The text was updated successfully, but these errors were encountered:
BenjaminNavarro
changed the title
Incorrect SFNIAE for operators with static_asserts
Incorrect enable_if condition for operator+
Nov 18, 2022
In fact the problem is triggered only when a custom type inherits its operator+ because in this case the compiler first look for free functions before looking into parent types.
I'm currently using v2.3.1 but after looking at the current version, the problem is still there.
operator+
is defined like:The problem I have is when defining the arithmetic operators on my custom types so that they can be used with this library easily. Something like:
Using
1_m
makes the compiler look for operators in theunits
namespace but sincemy::Position
is not aunits
type, the first failsafe operator above is selected in the overload set (traits::is_same_scale<UnitTypeLhs, UnitTypeRhs>::value
is false) and thestatic_assert
is triggered.I think the failsafe operator must also include a
traits::is_unit_t<UnitTypeLhs>::value and traits::is_unit_t<UnitTypeRhs>::value
in hisenable_if
so that it is only selected when appropriate.I'm willing to write a PR if you think the approach is correct.
EDIT: I though this problem was for all operators but it looks like it's just
operator+
.The text was updated successfully, but these errors were encountered: