mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpimath] Fix units overload resolution (#8267)
This commit is contained in:
@@ -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*/)
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user