From 7612d5d0efce5804e39c6f8d2ef0c1e78641747b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 2 Apr 2022 13:34:52 +0800 Subject: [PATCH] Use default operators generated/synthesized by compiler --- src/app/cmdoptions.cpp | 20 -------------------- src/base/bittorrent/infohash.cpp | 5 ----- src/base/bittorrent/infohash.h | 1 - src/base/bittorrent/tracker.cpp | 5 ----- src/base/bittorrent/tracker.h | 1 - src/base/digest32.h | 6 ------ src/base/indexrange.h | 5 ----- src/base/net/proxyconfigurationmanager.cpp | 5 ----- src/base/net/proxyconfigurationmanager.h | 1 - src/base/path.cpp | 5 ----- src/base/path.h | 1 - src/base/rss/rss_autodownloadrule.cpp | 5 ----- src/base/rss/rss_autodownloadrule.h | 2 -- src/base/utils/version.h | 11 ++--------- src/gui/properties/peerlistwidget.cpp | 7 ++----- 15 files changed, 4 insertions(+), 76 deletions(-) diff --git a/src/app/cmdoptions.cpp b/src/app/cmdoptions.cpp index 0b993c3a6..45f9cee6f 100644 --- a/src/app/cmdoptions.cpp +++ b/src/app/cmdoptions.cpp @@ -134,11 +134,6 @@ namespace } }; - bool operator==(const QString &arg, const BoolOption &option) - { - return (option == arg); - } - // Option with string value. May not have a shortcut struct StringOption : protected Option { @@ -181,11 +176,6 @@ namespace } }; - bool operator==(const QString &arg, const StringOption &option) - { - return (option == arg); - } - // Option with integer value. May not have a shortcut class IntOption : protected StringOption { @@ -233,11 +223,6 @@ namespace } }; - bool operator==(const QString &arg, const IntOption &option) - { - return (option == arg); - } - // Option that is explicitly set to true or false, and whose value is undefined when unspecified. // May not have a shortcut. class TriStateBoolOption : protected Option @@ -316,11 +301,6 @@ namespace bool m_defaultValue; }; - bool operator==(const QString &arg, const TriStateBoolOption &option) - { - return (option == arg); - } - constexpr const BoolOption SHOW_HELP_OPTION {"help", 'h'}; constexpr const BoolOption SHOW_VERSION_OPTION {"version", 'v'}; #if defined(DISABLE_GUI) && !defined(Q_OS_WIN) diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index 1a6035353..9558c4209 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -120,8 +120,3 @@ bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent:: { return (static_cast(left) == static_cast(right)); } - -bool BitTorrent::operator!=(const BitTorrent::InfoHash &left, const BitTorrent::InfoHash &right) -{ - return !(left == right); -} diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index fa033d0ae..fbf6b8f95 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -90,7 +90,6 @@ namespace BitTorrent std::size_t qHash(const TorrentID &key, std::size_t seed = 0); bool operator==(const InfoHash &left, const InfoHash &right); - bool operator!=(const InfoHash &left, const InfoHash &right); } Q_DECLARE_METATYPE(BitTorrent::TorrentID) diff --git a/src/base/bittorrent/tracker.cpp b/src/base/bittorrent/tracker.cpp index eb6f5606b..6da1321cd 100644 --- a/src/base/bittorrent/tracker.cpp +++ b/src/base/bittorrent/tracker.cpp @@ -135,11 +135,6 @@ namespace BitTorrent return (left.uniqueID() == right.uniqueID()); } - bool operator!=(const Peer &left, const Peer &right) - { - return !(left == right); - } - std::size_t qHash(const Peer &key, const std::size_t seed) { return qHash(key.uniqueID(), seed); diff --git a/src/base/bittorrent/tracker.h b/src/base/bittorrent/tracker.h index 6a54ca3a9..892c5f3e2 100644 --- a/src/base/bittorrent/tracker.h +++ b/src/base/bittorrent/tracker.h @@ -64,7 +64,6 @@ namespace BitTorrent }; bool operator==(const Peer &left, const Peer &right); - bool operator!=(const Peer &left, const Peer &right); std::size_t qHash(const Peer &key, std::size_t seed = 0); // *Basic* Bittorrent tracker implementation diff --git a/src/base/digest32.h b/src/base/digest32.h index 11c0c314b..5fdace840 100644 --- a/src/base/digest32.h +++ b/src/base/digest32.h @@ -144,12 +144,6 @@ bool operator==(const Digest32 &left, const Digest32 &right) == static_cast::UnderlyingType>(right)); } -template -bool operator!=(const Digest32 &left, const Digest32 &right) -{ - return !(left == right); -} - template bool operator<(const Digest32 &left, const Digest32 &right) { diff --git a/src/base/indexrange.h b/src/base/indexrange.h index 65129f5ea..37931f791 100644 --- a/src/base/indexrange.h +++ b/src/base/indexrange.h @@ -107,11 +107,6 @@ public: return (*left == *right); } - friend constexpr bool operator!=(const Iterator &left, const Iterator &right) - { - return !(left == right); - } - private: IndexType m_index; }; diff --git a/src/base/net/proxyconfigurationmanager.cpp b/src/base/net/proxyconfigurationmanager.cpp index 00bc7cedd..4494280d4 100644 --- a/src/base/net/proxyconfigurationmanager.cpp +++ b/src/base/net/proxyconfigurationmanager.cpp @@ -41,11 +41,6 @@ bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &r && (left.hostnameLookupEnabled == right.hostnameLookupEnabled); } -bool Net::operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right) -{ - return !(left == right); -} - using namespace Net; ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr; diff --git a/src/base/net/proxyconfigurationmanager.h b/src/base/net/proxyconfigurationmanager.h index 5444fb193..41521823d 100644 --- a/src/base/net/proxyconfigurationmanager.h +++ b/src/base/net/proxyconfigurationmanager.h @@ -57,7 +57,6 @@ namespace Net bool hostnameLookupEnabled = true; }; bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right); - bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right); class ProxyConfigurationManager final : public QObject { diff --git a/src/base/path.cpp b/src/base/path.cpp index 75bf074ed..2ed951773 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -342,11 +342,6 @@ bool operator==(const Path &lhs, const Path &rhs) return (lhs.data().compare(rhs.data(), CASE_SENSITIVITY) == 0); } -bool operator!=(const Path &lhs, const Path &rhs) -{ - return !(lhs == rhs); -} - Path operator/(const Path &lhs, const Path &rhs) { if (rhs.isEmpty()) diff --git a/src/base/path.h b/src/base/path.h index 16bf51f71..4501e2668 100644 --- a/src/base/path.h +++ b/src/base/path.h @@ -95,7 +95,6 @@ private: Q_DECLARE_METATYPE(Path) bool operator==(const Path &lhs, const Path &rhs); -bool operator!=(const Path &lhs, const Path &rhs); Path operator+(const Path &lhs, QStringView rhs); QDataStream &operator<<(QDataStream &out, const Path &path); diff --git a/src/base/rss/rss_autodownloadrule.cpp b/src/base/rss/rss_autodownloadrule.cpp index 8caff1037..b4637cf43 100644 --- a/src/base/rss/rss_autodownloadrule.cpp +++ b/src/base/rss/rss_autodownloadrule.cpp @@ -167,11 +167,6 @@ namespace RSS return (left.m_dataPtr == right.m_dataPtr) // optimization || (*(left.m_dataPtr) == *(right.m_dataPtr)); } - - bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right) - { - return !(left == right); - } } using namespace RSS; diff --git a/src/base/rss/rss_autodownloadrule.h b/src/base/rss/rss_autodownloadrule.h index 9e5449bc6..ff54b5faf 100644 --- a/src/base/rss/rss_autodownloadrule.h +++ b/src/base/rss/rss_autodownloadrule.h @@ -108,6 +108,4 @@ namespace RSS QSharedDataPointer m_dataPtr; }; - - bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right); } diff --git a/src/base/utils/version.h b/src/base/utils/version.h index 98bff202f..ba2618a7b 100644 --- a/src/base/utils/version.h +++ b/src/base/utils/version.h @@ -124,13 +124,12 @@ namespace Utils return res; } - // TODO: remove manually defined operators and use compiler generated `operator<=>()` in C++20 - friend bool operator==(const ThisType &left, const ThisType &right) + friend constexpr bool operator==(const ThisType &left, const ThisType &right) { return (left.m_components == right.m_components); } - friend bool operator<(const ThisType &left, const ThisType &right) + friend constexpr bool operator<(const ThisType &left, const ThisType &right) { return (left.m_components < right.m_components); } @@ -159,12 +158,6 @@ namespace Utils std::array m_components {{}}; }; - template - constexpr bool operator!=(const Version &left, const Version &right) - { - return !(left == right); - } - template constexpr bool operator>(const Version &left, const Version &right) { diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index afae06d64..9f6b37b08 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -67,12 +67,9 @@ struct PeerEndpoint { BitTorrent::PeerAddress address; QString connectionType; // matches return type of `PeerInfo::connectionType()` -}; -bool operator==(const PeerEndpoint &left, const PeerEndpoint &right) -{ - return (left.address == right.address) && (left.connectionType == right.connectionType); -} + friend bool operator==(const PeerEndpoint &left, const PeerEndpoint &right) = default; +}; std::size_t qHash(const PeerEndpoint &peerEndpoint, const std::size_t seed = 0) {