[wpimath] Fix units overload resolution (#8267)

This commit is contained in:
Joseph Eng
2025-10-02 17:36:30 -07:00
committed by GitHub
parent ca7718cb08
commit 871769c815
2 changed files with 16 additions and 0 deletions

View File

@@ -1992,6 +1992,7 @@ namespace units
* @param[in] rhs unit to copy.
*/
template<class UnitsRhs, typename Ty, template<typename> class NlsRhs>
requires traits::is_unit_v<UnitsRhs> && traits::is_unit_v<Units> && traits::is_convertible_unit_v<UnitsRhs, Units>
constexpr unit_t(const unit_t<UnitsRhs, Ty, NlsRhs>& rhs) noexcept :
nls(units::convert<UnitsRhs, Units, T>(rhs.m_value), std::true_type() /*store linear value*/)
{

View File

@@ -3513,3 +3513,18 @@ TEST_F(CaseStudies, pythagoreanTheorum) {
pow<2>(RightTriangle::b::value()) ==
pow<2>(RightTriangle::c::value()));
}
TEST(Units, overloadResolution) {
// Slight hack to get nested functions
struct Scope {
static bool f(units::meter_t) {
return true;
};
static bool f(units::second_t) {
return false;
};
};
// Make sure this properly selects the meter overload
EXPECT_TRUE(Scope::f(1_mm));
}