Browse Source

Merge pull request #19349 from Chocobo1/c++20

Use default operators generated/synthesized by compiler
adaptive-webui-19844
Chocobo1 1 year ago committed by GitHub
parent
commit
9898901236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/app/cmdoptions.cpp
  2. 5
      src/base/bittorrent/infohash.cpp
  3. 1
      src/base/bittorrent/infohash.h
  4. 69
      src/base/bittorrent/sessionimpl.cpp
  5. 7
      src/base/bittorrent/torrentimpl.cpp
  6. 5
      src/base/bittorrent/tracker.cpp
  7. 1
      src/base/bittorrent/tracker.h
  8. 6
      src/base/digest32.h
  9. 5
      src/base/indexrange.h
  10. 9
      src/base/net/downloadmanager.cpp
  11. 5
      src/base/net/proxyconfigurationmanager.cpp
  12. 1
      src/base/net/proxyconfigurationmanager.h
  13. 5
      src/base/path.cpp
  14. 1
      src/base/path.h
  15. 2
      src/base/preferences.cpp
  16. 5
      src/base/rss/rss_autodownloadrule.cpp
  17. 2
      src/base/rss/rss_autodownloadrule.h
  18. 11
      src/base/utils/version.h
  19. 7
      src/gui/properties/peerlistwidget.cpp

20
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 // Option with string value. May not have a shortcut
struct StringOption : protected Option 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 // Option with integer value. May not have a shortcut
class IntOption : protected StringOption 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. // Option that is explicitly set to true or false, and whose value is undefined when unspecified.
// May not have a shortcut. // May not have a shortcut.
class TriStateBoolOption : protected Option class TriStateBoolOption : protected Option
@ -316,11 +301,6 @@ namespace
bool m_defaultValue; 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_HELP_OPTION {"help", 'h'};
constexpr const BoolOption SHOW_VERSION_OPTION {"version", 'v'}; constexpr const BoolOption SHOW_VERSION_OPTION {"version", 'v'};
#if defined(DISABLE_GUI) && !defined(Q_OS_WIN) #if defined(DISABLE_GUI) && !defined(Q_OS_WIN)

5
src/base/bittorrent/infohash.cpp

@ -120,8 +120,3 @@ bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent::
{ {
return (static_cast<InfoHash::WrappedType>(left) == static_cast<InfoHash::WrappedType>(right)); return (static_cast<InfoHash::WrappedType>(left) == static_cast<InfoHash::WrappedType>(right));
} }
bool BitTorrent::operator!=(const BitTorrent::InfoHash &left, const BitTorrent::InfoHash &right)
{
return !(left == right);
}

1
src/base/bittorrent/infohash.h

@ -90,7 +90,6 @@ namespace BitTorrent
std::size_t qHash(const TorrentID &key, std::size_t seed = 0); 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);
bool operator!=(const InfoHash &left, const InfoHash &right);
} }
Q_DECLARE_METATYPE(BitTorrent::TorrentID) Q_DECLARE_METATYPE(BitTorrent::TorrentID)

69
src/base/bittorrent/sessionimpl.cpp

@ -1571,37 +1571,48 @@ void SessionImpl::initMetrics()
return index; return index;
}; };
// TODO: switch to "designated initializers" in C++20 m_metricIndices =
m_metricIndices.net.hasIncomingConnections = findMetricIndex("net.has_incoming_connections"); {
m_metricIndices.net.sentPayloadBytes = findMetricIndex("net.sent_payload_bytes"); .net =
m_metricIndices.net.recvPayloadBytes = findMetricIndex("net.recv_payload_bytes"); {
m_metricIndices.net.sentBytes = findMetricIndex("net.sent_bytes"); .hasIncomingConnections = findMetricIndex("net.has_incoming_connections"),
m_metricIndices.net.recvBytes = findMetricIndex("net.recv_bytes"); .sentPayloadBytes = findMetricIndex("net.sent_payload_bytes"),
m_metricIndices.net.sentIPOverheadBytes = findMetricIndex("net.sent_ip_overhead_bytes"); .recvPayloadBytes = findMetricIndex("net.recv_payload_bytes"),
m_metricIndices.net.recvIPOverheadBytes = findMetricIndex("net.recv_ip_overhead_bytes"); .sentBytes = findMetricIndex("net.sent_bytes"),
m_metricIndices.net.sentTrackerBytes = findMetricIndex("net.sent_tracker_bytes"); .recvBytes = findMetricIndex("net.recv_bytes"),
m_metricIndices.net.recvTrackerBytes = findMetricIndex("net.recv_tracker_bytes"); .sentIPOverheadBytes = findMetricIndex("net.sent_ip_overhead_bytes"),
m_metricIndices.net.recvRedundantBytes = findMetricIndex("net.recv_redundant_bytes"); .recvIPOverheadBytes = findMetricIndex("net.recv_ip_overhead_bytes"),
m_metricIndices.net.recvFailedBytes = findMetricIndex("net.recv_failed_bytes"); .sentTrackerBytes = findMetricIndex("net.sent_tracker_bytes"),
.recvTrackerBytes = findMetricIndex("net.recv_tracker_bytes"),
m_metricIndices.peer.numPeersConnected = findMetricIndex("peer.num_peers_connected"); .recvRedundantBytes = findMetricIndex("net.recv_redundant_bytes"),
m_metricIndices.peer.numPeersDownDisk = findMetricIndex("peer.num_peers_down_disk"); .recvFailedBytes = findMetricIndex("net.recv_failed_bytes")
m_metricIndices.peer.numPeersUpDisk = findMetricIndex("peer.num_peers_up_disk"); },
.peer =
m_metricIndices.dht.dhtBytesIn = findMetricIndex("dht.dht_bytes_in"); {
m_metricIndices.dht.dhtBytesOut = findMetricIndex("dht.dht_bytes_out"); .numPeersConnected = findMetricIndex("peer.num_peers_connected"),
m_metricIndices.dht.dhtNodes = findMetricIndex("dht.dht_nodes"); .numPeersUpDisk = findMetricIndex("peer.num_peers_up_disk"),
.numPeersDownDisk = findMetricIndex("peer.num_peers_down_disk")
m_metricIndices.disk.diskBlocksInUse = findMetricIndex("disk.disk_blocks_in_use"); },
m_metricIndices.disk.numBlocksRead = findMetricIndex("disk.num_blocks_read"); .dht =
{
.dhtBytesIn = findMetricIndex("dht.dht_bytes_in"),
.dhtBytesOut = findMetricIndex("dht.dht_bytes_out"),
.dhtNodes = findMetricIndex("dht.dht_nodes")
},
.disk =
{
.diskBlocksInUse = findMetricIndex("disk.disk_blocks_in_use"),
.numBlocksRead = findMetricIndex("disk.num_blocks_read"),
#ifndef QBT_USES_LIBTORRENT2 #ifndef QBT_USES_LIBTORRENT2
m_metricIndices.disk.numBlocksCacheHits = findMetricIndex("disk.num_blocks_cache_hits"); .numBlocksCacheHits = findMetricIndex("disk.num_blocks_cache_hits"),
#endif #endif
m_metricIndices.disk.writeJobs = findMetricIndex("disk.num_write_ops"); .writeJobs = findMetricIndex("disk.num_write_ops"),
m_metricIndices.disk.readJobs = findMetricIndex("disk.num_read_ops"); .readJobs = findMetricIndex("disk.num_read_ops"),
m_metricIndices.disk.hashJobs = findMetricIndex("disk.num_blocks_hashed"); .hashJobs = findMetricIndex("disk.num_blocks_hashed"),
m_metricIndices.disk.queuedDiskJobs = findMetricIndex("disk.queued_disk_jobs"); .queuedDiskJobs = findMetricIndex("disk.queued_disk_jobs"),
m_metricIndices.disk.diskJobTime = findMetricIndex("disk.disk_job_time"); .diskJobTime = findMetricIndex("disk.disk_job_time")
}
};
} }
lt::settings_pack SessionImpl::loadLTSettings() const lt::settings_pack SessionImpl::loadLTSettings() const

7
src/base/bittorrent/torrentimpl.cpp

@ -31,7 +31,6 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <type_traits>
#include <libtorrent/address.hpp> #include <libtorrent/address.hpp>
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
@ -551,8 +550,7 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
void TorrentImpl::addTrackers(QVector<TrackerEntry> trackers) void TorrentImpl::addTrackers(QVector<TrackerEntry> trackers)
{ {
// TODO: use std::erase_if() in C++20 trackers.removeIf([](const TrackerEntry &entry) { return entry.url.isEmpty(); });
trackers.erase(std::remove_if(trackers.begin(), trackers.end(), [](const TrackerEntry &entry) { return entry.url.isEmpty(); }), trackers.end());
const auto newTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend()) const auto newTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend())
- QSet<TrackerEntry>(m_trackerEntries.cbegin(), m_trackerEntries.cend()); - QSet<TrackerEntry>(m_trackerEntries.cbegin(), m_trackerEntries.cend());
@ -596,8 +594,7 @@ void TorrentImpl::removeTrackers(const QStringList &trackers)
void TorrentImpl::replaceTrackers(QVector<TrackerEntry> trackers) void TorrentImpl::replaceTrackers(QVector<TrackerEntry> trackers)
{ {
// TODO: use std::erase_if() in C++20 trackers.removeIf([](const TrackerEntry &entry) { return entry.url.isEmpty(); });
trackers.erase(std::remove_if(trackers.begin(), trackers.end(), [](const TrackerEntry &entry) { return entry.url.isEmpty(); }), trackers.end());
std::sort(trackers.begin(), trackers.end() std::sort(trackers.begin(), trackers.end()
, [](const TrackerEntry &lhs, const TrackerEntry &rhs) { return lhs.tier < rhs.tier; }); , [](const TrackerEntry &lhs, const TrackerEntry &rhs) { return lhs.tier < rhs.tier; });

5
src/base/bittorrent/tracker.cpp

@ -135,11 +135,6 @@ namespace BitTorrent
return (left.uniqueID() == right.uniqueID()); 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) std::size_t qHash(const Peer &key, const std::size_t seed)
{ {
return qHash(key.uniqueID(), seed); return qHash(key.uniqueID(), seed);

1
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);
bool operator!=(const Peer &left, const Peer &right);
std::size_t qHash(const Peer &key, std::size_t seed = 0); std::size_t qHash(const Peer &key, std::size_t seed = 0);
// *Basic* Bittorrent tracker implementation // *Basic* Bittorrent tracker implementation

6
src/base/digest32.h

@ -144,12 +144,6 @@ bool operator==(const Digest32<N> &left, const Digest32<N> &right)
== static_cast<typename Digest32<N>::UnderlyingType>(right)); == static_cast<typename Digest32<N>::UnderlyingType>(right));
} }
template <int N>
bool operator!=(const Digest32<N> &left, const Digest32<N> &right)
{
return !(left == right);
}
template <int N> template <int N>
bool operator<(const Digest32<N> &left, const Digest32<N> &right) bool operator<(const Digest32<N> &left, const Digest32<N> &right)
{ {

5
src/base/indexrange.h

@ -107,11 +107,6 @@ public:
return (*left == *right); return (*left == *right);
} }
friend constexpr bool operator!=(const Iterator &left, const Iterator &right)
{
return !(left == right);
}
private: private:
IndexType m_index; IndexType m_index;
}; };

9
src/base/net/downloadmanager.cpp

@ -42,7 +42,6 @@
#include <QSslError> #include <QSslError>
#include <QUrl> #include <QUrl>
#include "base/algorithm.h"
#include "base/global.h" #include "base/global.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
@ -63,7 +62,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies(); QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies();
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return cookie.isSessionCookie() || (cookie.expirationDate() <= now); return cookie.isSessionCookie() || (cookie.expirationDate() <= now);
}); });
@ -75,7 +74,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = allCookies(); QList<QNetworkCookie> cookies = allCookies();
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return cookie.isSessionCookie() || (cookie.expirationDate() <= now); return cookie.isSessionCookie() || (cookie.expirationDate() <= now);
}); });
@ -90,7 +89,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url); QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url);
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return !cookie.isSessionCookie() && (cookie.expirationDate() <= now); return !cookie.isSessionCookie() && (cookie.expirationDate() <= now);
}); });
@ -102,7 +101,7 @@ public:
{ {
const QDateTime now = QDateTime::currentDateTime(); const QDateTime now = QDateTime::currentDateTime();
QList<QNetworkCookie> cookies = cookieList; QList<QNetworkCookie> cookies = cookieList;
Algorithm::removeIf(cookies, [&now](const QNetworkCookie &cookie) cookies.removeIf([&now](const QNetworkCookie &cookie)
{ {
return !cookie.isSessionCookie() && (cookie.expirationDate() <= now); return !cookie.isSessionCookie() && (cookie.expirationDate() <= now);
}); });

5
src/base/net/proxyconfigurationmanager.cpp

@ -41,11 +41,6 @@ bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &r
&& (left.hostnameLookupEnabled == right.hostnameLookupEnabled); && (left.hostnameLookupEnabled == right.hostnameLookupEnabled);
} }
bool Net::operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right)
{
return !(left == right);
}
using namespace Net; using namespace Net;
ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr; ProxyConfigurationManager *ProxyConfigurationManager::m_instance = nullptr;

1
src/base/net/proxyconfigurationmanager.h

@ -57,7 +57,6 @@ namespace Net
bool hostnameLookupEnabled = true; bool hostnameLookupEnabled = true;
}; };
bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right); bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right);
bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right);
class ProxyConfigurationManager final : public QObject class ProxyConfigurationManager final : public QObject
{ {

5
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); 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) Path operator/(const Path &lhs, const Path &rhs)
{ {
if (rhs.isEmpty()) if (rhs.isEmpty())

1
src/base/path.h

@ -95,7 +95,6 @@ private:
Q_DECLARE_METATYPE(Path) Q_DECLARE_METATYPE(Path)
bool operator==(const Path &lhs, const Path &rhs); bool operator==(const Path &lhs, const Path &rhs);
bool operator!=(const Path &lhs, const Path &rhs);
Path operator+(const Path &lhs, QStringView rhs); Path operator+(const Path &lhs, QStringView rhs);
QDataStream &operator<<(QDataStream &out, const Path &path); QDataStream &operator<<(QDataStream &out, const Path &path);

2
src/base/preferences.cpp

@ -702,7 +702,7 @@ QVector<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets) void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets)
{ {
Algorithm::removeIf(subnets, [](const QString &subnet) subnets.removeIf([](const QString &subnet)
{ {
return !Utils::Net::parseSubnet(subnet.trimmed()).has_value(); return !Utils::Net::parseSubnet(subnet.trimmed()).has_value();
}); });

5
src/base/rss/rss_autodownloadrule.cpp

@ -167,11 +167,6 @@ namespace RSS
return (left.m_dataPtr == right.m_dataPtr) // optimization return (left.m_dataPtr == right.m_dataPtr) // optimization
|| (*(left.m_dataPtr) == *(right.m_dataPtr)); || (*(left.m_dataPtr) == *(right.m_dataPtr));
} }
bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right)
{
return !(left == right);
}
} }
using namespace RSS; using namespace RSS;

2
src/base/rss/rss_autodownloadrule.h

@ -108,6 +108,4 @@ namespace RSS
QSharedDataPointer<AutoDownloadRuleData> m_dataPtr; QSharedDataPointer<AutoDownloadRuleData> m_dataPtr;
}; };
bool operator!=(const AutoDownloadRule &left, const AutoDownloadRule &right);
} }

11
src/base/utils/version.h

@ -124,13 +124,12 @@ namespace Utils
return res; return res;
} }
// TODO: remove manually defined operators and use compiler generated `operator<=>()` in C++20 friend constexpr bool operator==(const ThisType &left, const ThisType &right)
friend bool operator==(const ThisType &left, const ThisType &right)
{ {
return (left.m_components == right.m_components); 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); return (left.m_components < right.m_components);
} }
@ -159,12 +158,6 @@ namespace Utils
std::array<int, N> m_components {{}}; std::array<int, N> m_components {{}};
}; };
template <int N, int Mandatory>
constexpr bool operator!=(const Version<N, Mandatory> &left, const Version<N, Mandatory> &right)
{
return !(left == right);
}
template <int N, int Mandatory> template <int N, int Mandatory>
constexpr bool operator>(const Version<N, Mandatory> &left, const Version<N, Mandatory> &right) constexpr bool operator>(const Version<N, Mandatory> &left, const Version<N, Mandatory> &right)
{ {

7
src/gui/properties/peerlistwidget.cpp

@ -67,12 +67,9 @@ struct PeerEndpoint
{ {
BitTorrent::PeerAddress address; BitTorrent::PeerAddress address;
QString connectionType; // matches return type of `PeerInfo::connectionType()` QString connectionType; // matches return type of `PeerInfo::connectionType()`
};
bool operator==(const PeerEndpoint &left, const PeerEndpoint &right) friend bool operator==(const PeerEndpoint &left, const PeerEndpoint &right) = default;
{ };
return (left.address == right.address) && (left.connectionType == right.connectionType);
}
std::size_t qHash(const PeerEndpoint &peerEndpoint, const std::size_t seed = 0) std::size_t qHash(const PeerEndpoint &peerEndpoint, const std::size_t seed = 0)
{ {

Loading…
Cancel
Save