mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
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:
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "SequenceNumber.h"
|
||||
|
||||
namespace nt::net3 {
|
||||
|
||||
bool operator<(const SequenceNumber& lhs, const SequenceNumber& rhs) {
|
||||
if (lhs.m_value < rhs.m_value) {
|
||||
return (rhs.m_value - lhs.m_value) < (1u << 15);
|
||||
} else if (lhs.m_value > rhs.m_value) {
|
||||
return (lhs.m_value - rhs.m_value) > (1u << 15);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator>(const SequenceNumber& lhs, const SequenceNumber& rhs) {
|
||||
if (lhs.m_value < rhs.m_value) {
|
||||
return (rhs.m_value - lhs.m_value) > (1u << 15);
|
||||
} else if (lhs.m_value > rhs.m_value) {
|
||||
return (lhs.m_value - rhs.m_value) < (1u << 15);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nt::net3
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
|
||||
namespace nt::net3 {
|
||||
|
||||
/* A sequence number per RFC 1982 */
|
||||
@@ -26,34 +28,11 @@ class SequenceNumber {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
friend bool operator<(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
friend bool operator>(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
friend bool operator<=(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
friend bool operator>=(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
friend bool operator==(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
friend bool operator!=(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
friend auto operator<=>(const SequenceNumber& lhs,
|
||||
const SequenceNumber& rhs) = default;
|
||||
|
||||
private:
|
||||
unsigned int m_value{0};
|
||||
};
|
||||
|
||||
bool operator<(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
bool operator>(const SequenceNumber& lhs, const SequenceNumber& rhs);
|
||||
|
||||
inline bool operator<=(const SequenceNumber& lhs, const SequenceNumber& rhs) {
|
||||
return lhs == rhs || lhs < rhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const SequenceNumber& lhs, const SequenceNumber& rhs) {
|
||||
return lhs == rhs || lhs > rhs;
|
||||
}
|
||||
|
||||
inline bool operator==(const SequenceNumber& lhs, const SequenceNumber& rhs) {
|
||||
return lhs.m_value == rhs.m_value;
|
||||
}
|
||||
|
||||
inline bool operator!=(const SequenceNumber& lhs, const SequenceNumber& rhs) {
|
||||
return lhs.m_value != rhs.m_value;
|
||||
}
|
||||
|
||||
} // namespace nt::net3
|
||||
|
||||
@@ -520,14 +520,7 @@ class NetworkTableEntry final {
|
||||
* Equality operator. Returns true if both instances refer to the same
|
||||
* native handle.
|
||||
*/
|
||||
bool operator==(const NetworkTableEntry& oth) const {
|
||||
return m_handle == oth.m_handle;
|
||||
}
|
||||
|
||||
/** Inequality operator. */
|
||||
bool operator!=(const NetworkTableEntry& oth) const {
|
||||
return !(*this == oth);
|
||||
}
|
||||
bool operator==(const NetworkTableEntry&) const = default;
|
||||
|
||||
protected:
|
||||
/* Native handle */
|
||||
|
||||
@@ -688,14 +688,7 @@ class NetworkTableInstance final {
|
||||
* Equality operator. Returns true if both instances refer to the same
|
||||
* native handle.
|
||||
*/
|
||||
bool operator==(const NetworkTableInstance& other) const {
|
||||
return m_handle == other.m_handle;
|
||||
}
|
||||
|
||||
/** Inequality operator. */
|
||||
bool operator!=(const NetworkTableInstance& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
bool operator==(const NetworkTableInstance&) const = default;
|
||||
|
||||
private:
|
||||
/* Native handle */
|
||||
|
||||
@@ -636,9 +636,6 @@ class Value final {
|
||||
};
|
||||
|
||||
bool operator==(const Value& lhs, const Value& rhs);
|
||||
inline bool operator!=(const Value& lhs, const Value& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* NetworkTable Value alias for similarity with Java.
|
||||
|
||||
@@ -278,10 +278,7 @@ class Topic {
|
||||
* Equality operator. Returns true if both instances refer to the same
|
||||
* native handle.
|
||||
*/
|
||||
bool operator==(const Topic& oth) const { return m_handle == oth.m_handle; }
|
||||
|
||||
/** Inequality operator. */
|
||||
bool operator!=(const Topic& oth) const { return !(*this == oth); }
|
||||
bool operator==(const Topic&) const = default;
|
||||
|
||||
protected:
|
||||
NT_Topic m_handle{0};
|
||||
|
||||
Reference in New Issue
Block a user