Use defaulted comparison operators in C++ (#4723)

Comparison operators which compared against every class member variable
now use C++20's default comparison operators.

Also remove operator!= that in C++20 is now auto-generated from operator==.
This commit is contained in:
Tyler Veness
2022-11-27 21:01:01 -08:00
committed by GitHub
parent 135c13958f
commit 42b6d4e3f7
39 changed files with 25 additions and 367 deletions

View File

@@ -763,6 +763,8 @@ class Color {
constexpr Color(int r, int g, int b)
: Color(r / 255.0, g / 255.0, b / 255.0) {}
constexpr bool operator==(const Color&) const = default;
/**
* Creates a Color from HSV values.
*
@@ -830,14 +832,6 @@ class Color {
}
};
inline bool operator==(const Color& c1, const Color& c2) {
return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
}
inline bool operator!=(const Color& c1, const Color& c2) {
return !(c1 == c2);
}
/*
* FIRST Colors
*/

View File

@@ -44,6 +44,8 @@ class Color8Bit {
return Color(red / 255.0, green / 255.0, blue / 255.0);
}
constexpr bool operator==(const Color8Bit&) const = default;
/**
* Return this color represented as a hex string.
*
@@ -56,8 +58,4 @@ class Color8Bit {
int blue = 0;
};
inline bool operator==(const Color8Bit& c1, const Color8Bit& c2) {
return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
}
} // namespace frc