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 @@ -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 @@ -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 @@ -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 @@ -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)

5
src/base/bittorrent/infohash.cpp

@ -120,8 +120,3 @@ bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent:: @@ -120,8 +120,3 @@ bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent::
{
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 @@ -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)

69
src/base/bittorrent/sessionimpl.cpp

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

7
src/base/bittorrent/torrentimpl.cpp

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

5
src/base/bittorrent/tracker.cpp

@ -135,11 +135,6 @@ namespace BitTorrent @@ -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);

1
src/base/bittorrent/tracker.h

@ -64,7 +64,6 @@ namespace BitTorrent @@ -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

6
src/base/digest32.h

@ -144,12 +144,6 @@ bool operator==(const Digest32<N> &left, const Digest32<N> &right) @@ -144,12 +144,6 @@ bool operator==(const Digest32<N> &left, const Digest32<N> &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>
bool operator<(const Digest32<N> &left, const Digest32<N> &right)
{

5
src/base/indexrange.h

@ -107,11 +107,6 @@ public: @@ -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;
};

9
src/base/net/downloadmanager.cpp

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

1
src/base/net/proxyconfigurationmanager.h

@ -57,7 +57,6 @@ namespace Net @@ -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
{

5
src/base/path.cpp

@ -342,11 +342,6 @@ bool operator==(const Path &lhs, const Path &rhs) @@ -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())

1
src/base/path.h

@ -95,7 +95,6 @@ private: @@ -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);

2
src/base/preferences.cpp

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

5
src/base/rss/rss_autodownloadrule.cpp

@ -167,11 +167,6 @@ namespace RSS @@ -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;

2
src/base/rss/rss_autodownloadrule.h

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

11
src/base/utils/version.h

@ -124,13 +124,12 @@ namespace Utils @@ -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 @@ -159,12 +158,6 @@ namespace Utils
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>
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 @@ -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)
{

Loading…
Cancel
Save