diff --git a/src/app/signalhandler.cpp b/src/app/signalhandler.cpp index 1116b5a34..0b0a29ba1 100644 --- a/src/app/signalhandler.cpp +++ b/src/app/signalhandler.cpp @@ -87,7 +87,7 @@ namespace void normalExitHandler(const int signum) { const char *msgs[] = {"Catching signal: ", sysSigName[signum], "\nExiting cleanly\n"}; - std::for_each(std::begin(msgs), std::end(msgs), safePrint); + std::ranges::for_each(msgs, safePrint); signal(signum, SIG_DFL); QMetaObject::invokeMethod(qApp, [] { QCoreApplication::exit(); }, Qt::QueuedConnection); // unsafe, but exit anyway } @@ -103,7 +103,7 @@ namespace const std::string stacktrace = getStacktrace(); const char *msgs[] = {msg, sigName, "\n```\n", stacktrace.c_str(), "```\n\n"}; - std::for_each(std::begin(msgs), std::end(msgs), safePrint); + std::ranges::for_each(msgs, safePrint); #ifndef DISABLE_GUI StacktraceDialog dlg; // unsafe diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index d771b132b..1d65baa67 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2495,7 +2495,7 @@ bool SessionImpl::removeTorrent(const TorrentID &id, const TorrentRemoveOption d m_removingTorrents[torrentID] = {torrentName, torrent->actualStorageLocation(), {}, deleteOption}; const lt::torrent_handle nativeHandle {torrent->nativeHandle()}; - const auto iter = std::find_if(m_moveStorageQueue.cbegin(), m_moveStorageQueue.cend() + const auto iter = std::ranges::find_if(asConst(m_moveStorageQueue) , [&nativeHandle](const MoveStorageJob &job) { return job.torrentHandle == nativeHandle; @@ -2520,7 +2520,7 @@ bool SessionImpl::removeTorrent(const TorrentID &id, const TorrentRemoveOption d { // Delete "move storage job" for the deleted torrent // (note: we shouldn't delete active job) - const auto iter = std::find_if((m_moveStorageQueue.cbegin() + 1), m_moveStorageQueue.cend() + const auto iter = std::ranges::find_if(std::views::drop(asConst(m_moveStorageQueue), 1) , [torrent](const MoveStorageJob &job) { return job.torrentHandle == torrent->nativeHandle(); @@ -2581,7 +2581,7 @@ void SessionImpl::decreaseTorrentsQueuePos(const QList &ids) const QList queuedTorrents = getQueuedTorrentsByID(ids); // Decrease torrents queue position (starting with the one in the lowest queue position) - for (TorrentImpl *torrent : (queuedTorrents | std::views::reverse)) + for (const TorrentImpl *torrent : std::views::reverse(queuedTorrents)) torrentQueuePositionDown(torrent->nativeHandle()); for (const lt::torrent_handle &torrentHandle : asConst(m_downloadedMetadata)) @@ -2595,7 +2595,7 @@ void SessionImpl::topTorrentsQueuePos(const QList &ids) const QList queuedTorrents = getQueuedTorrentsByID(ids); // Top torrents queue position (starting with the one in the lowest queue position) - for (TorrentImpl *torrent : (queuedTorrents | std::views::reverse)) + for (const TorrentImpl *torrent : std::views::reverse(queuedTorrents)) torrentQueuePositionTop(torrent->nativeHandle()); m_torrentsQueueChanged = true; @@ -2857,7 +2857,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr if (isAddTrackersEnabled() && !(hasMetadata && p.ti->priv())) { - const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend()); + const auto maxTierIter = std::ranges::max_element(asConst(p.tracker_tiers)); const int baseTier = (maxTierIter != p.tracker_tiers.cend()) ? (*maxTierIter + 1) : 0; p.trackers.reserve(p.trackers.size() + static_cast(m_additionalTrackerEntries.size())); @@ -2872,7 +2872,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr if (isAddTrackersFromURLEnabled() && !(hasMetadata && p.ti->priv())) { - const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend()); + const auto maxTierIter = std::ranges::max_element(asConst(p.tracker_tiers)); const int baseTier = (maxTierIter != p.tracker_tiers.cend()) ? (*maxTierIter + 1) : 0; p.trackers.reserve(p.trackers.size() + static_cast(m_additionalTrackerEntriesFromURL.size())); @@ -3094,7 +3094,7 @@ bool SessionImpl::downloadMetadata(const TorrentDescriptor &torrentDescr) { // Use "additional trackers" when metadata retrieving (this can help when the DHT nodes are few) - const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend()); + const auto maxTierIter = std::ranges::max_element(asConst(p.tracker_tiers)); const int baseTier = (maxTierIter != p.tracker_tiers.cend()) ? (*maxTierIter + 1) : 0; p.trackers.reserve(p.trackers.size() + static_cast(m_additionalTrackerEntries.size())); @@ -4132,7 +4132,7 @@ void SessionImpl::applyFilenameFilter(const PathList &files, QList 1) { - auto iter = std::find_if((m_moveStorageQueue.cbegin() + 1), m_moveStorageQueue.cend() + const auto iter = std::ranges::find_if(std::views::drop(asConst(m_moveStorageQueue), 1) , [&torrentHandle](const MoveStorageJob &job) { return job.torrentHandle == torrentHandle; }); - if (iter != m_moveStorageQueue.end()) + if (iter != m_moveStorageQueue.cend()) { // remove existing inactive job torrent->handleMoveStorageJobFinished(currentLocation, iter->context, torrentHasActiveJob); @@ -5453,7 +5453,7 @@ void SessionImpl::handleMoveTorrentStorageJobFinished(const Path &newPath) if (!m_moveStorageQueue.isEmpty()) moveTorrentStorage(m_moveStorageQueue.constFirst()); - const auto iter = std::find_if(m_moveStorageQueue.cbegin(), m_moveStorageQueue.cend() + const auto iter = std::ranges::find_if(asConst(m_moveStorageQueue) , [&finishedJob](const MoveStorageJob &job) { return job.torrentHandle == finishedJob.torrentHandle; @@ -5495,7 +5495,7 @@ void SessionImpl::processPendingFinishedTorrents() m_pendingFinishedTorrents.clear(); - const bool hasUnfinishedTorrents = std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent) + const bool hasUnfinishedTorrents = std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent) { return !(torrent->isFinished() || torrent->isStopped() || torrent->isErrored()); }); @@ -5588,7 +5588,7 @@ void SessionImpl::loadCategories() bool SessionImpl::hasPerTorrentRatioLimit() const { - return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent) + return std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent) { return (torrent->ratioLimit() >= 0); }); @@ -5596,7 +5596,7 @@ bool SessionImpl::hasPerTorrentRatioLimit() const bool SessionImpl::hasPerTorrentSeedingTimeLimit() const { - return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent) + return std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent) { return (torrent->seedingTimeLimit() >= 0); }); @@ -5604,7 +5604,7 @@ bool SessionImpl::hasPerTorrentSeedingTimeLimit() const bool SessionImpl::hasPerTorrentInactiveSeedingTimeLimit() const { - return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent) + return std::ranges::any_of(asConst(m_torrents), [](const TorrentImpl *torrent) { return (torrent->inactiveSeedingTimeLimit() >= 0); }); diff --git a/src/base/bittorrent/torrentcreator.cpp b/src/base/bittorrent/torrentcreator.cpp index 23568b2df..442dc06c6 100644 --- a/src/base/bittorrent/torrentcreator.cpp +++ b/src/base/bittorrent/torrentcreator.cpp @@ -139,7 +139,7 @@ void TorrentCreator::run() const QString dirPath = dirInfo.filePath(); dirs.append(dirPath); } - std::sort(dirs.begin(), dirs.end(), naturalLessThan); + std::ranges::sort(dirs, naturalLessThan); QStringList fileNames; QHash fileSizeMap; @@ -173,7 +173,7 @@ void TorrentCreator::run() fileSizeMap[tmpNames.last()] = fileSize; } - std::sort(tmpNames.begin(), tmpNames.end(), naturalLessThan); + std::ranges::sort(tmpNames, naturalLessThan); fileNames += tmpNames; } diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 5a315bd93..d2e5b78c6 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -207,7 +207,7 @@ namespace // remove outdated endpoints trackerEntryStatus.endpoints.removeIf([&nativeEntry](const QHash, TrackerEndpointStatus>::iterator &iter) { - return std::none_of(nativeEntry.endpoints.cbegin(), nativeEntry.endpoints.cend() + return std::ranges::none_of(nativeEntry.endpoints , [&endpointName = std::get<0>(iter.key())](const auto &existingEndpoint) { return (endpointName == toString(existingEndpoint.local_endpoint)); @@ -676,7 +676,7 @@ void TorrentImpl::addTrackers(QList trackers) m_nativeHandle.add_tracker(makeNativeAnnounceEntry(tracker.url, tracker.tier)); m_trackerEntryStatuses.append({tracker.url, tracker.tier}); } - std::sort(m_trackerEntryStatuses.begin(), m_trackerEntryStatuses.end() + std::ranges::sort(m_trackerEntryStatuses , [](const TrackerEntryStatus &left, const TrackerEntryStatus &right) { return left.tier < right.tier; }); deferredRequestResumeData(); @@ -713,7 +713,7 @@ void TorrentImpl::replaceTrackers(QList trackers) // Filter out duplicate trackers const auto uniqueTrackers = QSet(trackers.cbegin(), trackers.cend()); trackers = QList(uniqueTrackers.cbegin(), uniqueTrackers.cend()); - std::sort(trackers.begin(), trackers.end() + std::ranges::sort(trackers , [](const TrackerEntry &left, const TrackerEntry &right) { return left.tier < right.tier; }); std::vector nativeTrackers; @@ -1739,7 +1739,7 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled) TrackerEntryStatus TorrentImpl::updateTrackerEntryStatus(const lt::announce_entry &announceEntry, const QHash> &updateInfo) { - const auto it = std::find_if(m_trackerEntryStatuses.begin(), m_trackerEntryStatuses.end() + const auto it = std::ranges::find_if(m_trackerEntryStatuses , [&announceEntry](const TrackerEntryStatus &trackerEntryStatus) { return (trackerEntryStatus.url == QString::fromStdString(announceEntry.url)); diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index eb7388643..24534563c 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -197,8 +197,8 @@ PathList TorrentInfo::filesForPiece(const int pieceIndex) const PathList res; res.reserve(fileIndices.size()); - std::transform(fileIndices.begin(), fileIndices.end(), std::back_inserter(res) - , [this](int i) { return filePath(i); }); + for (const int i : fileIndices) + res.push_back(filePath(i)); return res; } diff --git a/src/base/http/requestparser.cpp b/src/base/http/requestparser.cpp index bfeac9320..7ff9ec85b 100644 --- a/src/base/http/requestparser.cpp +++ b/src/base/http/requestparser.cpp @@ -316,7 +316,7 @@ bool RequestParser::parsePostMessage(const QByteArrayView data) const QByteArray endDelimiter = QByteArray("--") + delimiter + QByteArray("--") + CRLF; multipart.push_back(viewWithoutEndingWith(multipart.takeLast(), endDelimiter)); - return std::all_of(multipart.cbegin(), multipart.cend(), [this](const QByteArrayView &part) + return std::ranges::all_of(asConst(multipart), [this](const QByteArrayView &part) { return this->parseFormData(part); }); diff --git a/src/base/http/server.cpp b/src/base/http/server.cpp index 7c99d8ecd..98565046e 100644 --- a/src/base/http/server.cpp +++ b/src/base/http/server.cpp @@ -72,7 +72,7 @@ namespace u"ECDHE-ECDSA-AES128-SHA"_s, u"ECDHE-RSA-AES128-SHA"_s, u"DHE-RSA-AES128-SHA"_s}; const QList allCiphers {QSslConfiguration::supportedCiphers()}; QList safeCiphers; - std::copy_if(allCiphers.cbegin(), allCiphers.cend(), std::back_inserter(safeCiphers), + std::ranges::copy_if(allCiphers, std::back_inserter(safeCiphers), [&badCiphers, &badRSAShorthandSuites, &badAESShorthandSuites](const QSslCipher &cipher) { const QString name = cipher.name(); @@ -87,7 +87,7 @@ namespace return false; } - return std::none_of(badCiphers.cbegin(), badCiphers.cend(), [&cipher](const QString &badCipher) + return std::ranges::none_of(badCiphers, [&cipher](const QString &badCipher) { return cipher.name().contains(badCipher, Qt::CaseInsensitive); }); diff --git a/src/base/logger.cpp b/src/base/logger.cpp index 9a91632a9..e7ebbd3c5 100644 --- a/src/base/logger.cpp +++ b/src/base/logger.cpp @@ -29,6 +29,7 @@ #include "logger.h" #include +#include #include #include @@ -40,7 +41,7 @@ namespace { QList ret; ret.reserve(static_cast(src.size()) - offset); - std::copy((src.begin() + offset), src.end(), std::back_inserter(ret)); + std::ranges::copy(std::views::drop(src, offset), std::back_inserter(ret)); return ret; } } diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index 6a46ee0ce..56461bf56 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -254,7 +254,7 @@ bool Net::DownloadManager::deleteCookie(const QNetworkCookie &cookie) bool Net::DownloadManager::hasSupportedScheme(const QString &url) { const QStringList schemes = QNetworkAccessManager().supportedSchemes(); - return std::any_of(schemes.cbegin(), schemes.cend(), [&url](const QString &scheme) + return std::ranges::any_of(schemes, [&url](const QString &scheme) { return url.startsWith((scheme + u':'), Qt::CaseInsensitive); }); diff --git a/src/base/net/smtp.cpp b/src/base/net/smtp.cpp index 851c91100..3c7906fcc 100644 --- a/src/base/net/smtp.cpp +++ b/src/base/net/smtp.cpp @@ -92,7 +92,7 @@ namespace bool canEncodeAsLatin1(const QStringView string) { - return std::none_of(string.cbegin(), string.cend(), [](const QChar &ch) + return std::ranges::none_of(string, [](const QChar &ch) { return ch > QChar(0xff); }); diff --git a/src/base/path.cpp b/src/base/path.cpp index 262caf026..c1357f3cf 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -54,7 +54,7 @@ namespace { QString cleanPath(const QString &path) { - const bool hasSeparator = std::any_of(path.cbegin(), path.cend(), [](const QChar c) + const bool hasSeparator = std::ranges::any_of(path, [](const QChar c) { return (c == u'/') || (c == u'\\'); }); diff --git a/src/base/rss/feed_serializer.cpp b/src/base/rss/feed_serializer.cpp index e55b7dc14..29423c452 100644 --- a/src/base/rss/feed_serializer.cpp +++ b/src/base/rss/feed_serializer.cpp @@ -120,7 +120,7 @@ QList RSS::Private::FeedSerializer::loadArticles(const QByteArray result.push_back(varHash); } - std::sort(result.begin(), result.end(), [](const QVariantHash &left, const QVariantHash &right) + std::ranges::sort(result, [](const QVariantHash &left, const QVariantHash &right) { return (left.value(Article::KeyDate).toDateTime() > right.value(Article::KeyDate).toDateTime()); }); diff --git a/src/base/rss/rss_autodownloader.cpp b/src/base/rss/rss_autodownloader.cpp index c77b1d9bd..4f6586dbb 100644 --- a/src/base/rss/rss_autodownloader.cpp +++ b/src/base/rss/rss_autodownloader.cpp @@ -447,7 +447,7 @@ void AutoDownloader::setRule_impl(const AutoDownloadRule &rule) void AutoDownloader::sortRules() { - std::sort(m_rules.begin(), m_rules.end(), [](const AutoDownloadRule &lhs, const AutoDownloadRule &rhs) + std::ranges::sort(m_rules, [](const AutoDownloadRule &lhs, const AutoDownloadRule &rhs) { return (lhs.priority() < rhs.priority()); }); diff --git a/src/base/rss/rss_autodownloadrule.cpp b/src/base/rss/rss_autodownloadrule.cpp index 77d342f91..db9457e11 100644 --- a/src/base/rss/rss_autodownloadrule.cpp +++ b/src/base/rss/rss_autodownloadrule.cpp @@ -255,7 +255,7 @@ bool AutoDownloadRule::matchesMustContainExpression(const QString &articleTitle) // Each expression is either a regex, or a set of wildcards separated by whitespace. // Accept if any complete expression matches. - return std::any_of(m_dataPtr->mustContain.cbegin(), m_dataPtr->mustContain.cend(), [this, &articleTitle](const QString &expression) + return std::ranges::any_of(asConst(m_dataPtr->mustContain), [this, &articleTitle](const QString &expression) { // A regex of the form "expr|" will always match, so do the same for wildcards return matchesExpression(articleTitle, expression); @@ -269,7 +269,7 @@ bool AutoDownloadRule::matchesMustNotContainExpression(const QString &articleTit // Each expression is either a regex, or a set of wildcards separated by whitespace. // Reject if any complete expression matches. - return std::none_of(m_dataPtr->mustNotContain.cbegin(), m_dataPtr->mustNotContain.cend(), [this, &articleTitle](const QString &expression) + return std::ranges::none_of(asConst(m_dataPtr->mustNotContain), [this, &articleTitle](const QString &expression) { // A regex of the form "expr|" will always match, so do the same for wildcards return matchesExpression(articleTitle, expression); diff --git a/src/base/rss/rss_feed.cpp b/src/base/rss/rss_feed.cpp index 2df5c2417..8e9667acc 100644 --- a/src/base/rss/rss_feed.cpp +++ b/src/base/rss/rss_feed.cpp @@ -32,6 +32,7 @@ #include "rss_feed.h" #include +#include #include #include @@ -426,20 +427,13 @@ int Feed::updateArticles(const QList &loadedArticles) std::vector sortData; const QList
existingArticles = articles(); sortData.reserve(existingArticles.size() + newArticles.size()); - std::transform(existingArticles.begin(), existingArticles.end(), std::back_inserter(sortData) - , [](const Article *article) - { - return std::make_pair(article->date(), nullptr); - }); - std::transform(newArticles.begin(), newArticles.end(), std::back_inserter(sortData) - , [](const QVariantHash &article) - { - return std::make_pair(article[Article::KeyDate].toDateTime(), &article); - }); + for (const Article *article : existingArticles) + sortData.push_back(std::make_pair(article->date(), nullptr)); + for (const QVariantHash &article : asConst(newArticles)) + sortData.push_back(std::make_pair(article[Article::KeyDate].toDateTime(), &article)); // Sort article list in reverse chronological order - std::sort(sortData.begin(), sortData.end() - , [](const ArticleSortAdaptor &a1, const ArticleSortAdaptor &a2) + std::ranges::sort(sortData, [](const ArticleSortAdaptor &a1, const ArticleSortAdaptor &a2) { return (a1.first > a2.first); }); @@ -448,14 +442,14 @@ int Feed::updateArticles(const QList &loadedArticles) sortData.resize(m_session->maxArticlesPerFeed()); int newArticlesCount = 0; - std::for_each(sortData.crbegin(), sortData.crend(), [this, &newArticlesCount](const ArticleSortAdaptor &a) + for (const ArticleSortAdaptor &a : std::views::reverse(sortData)) { if (a.second) { addArticle(*a.second); ++newArticlesCount; } - }); + } return newArticlesCount; } diff --git a/src/base/utils/foreignapps.cpp b/src/base/utils/foreignapps.cpp index 5b834ffbc..b6bd8c504 100644 --- a/src/base/utils/foreignapps.cpp +++ b/src/base/utils/foreignapps.cpp @@ -167,7 +167,7 @@ namespace PathList versions = getRegSubkeys(hkPythonCore); // ordinary sort won't suffice, it needs to sort ["3.9", "3.10"] correctly const Utils::Compare::NaturalCompare comparator; - std::sort(versions.begin(), versions.end(), [&comparator](const Path &left, const Path &right) + std::ranges::sort(versions, [&comparator](const Path &left, const Path &right) { return comparator(left.data(), right.data()); }); diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index 57d6e10c1..946fb2c5b 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -93,8 +93,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const Path &path) while (iter.hasNext()) dirList << iter.next() + u'/'; // sort descending by directory depth - std::sort(dirList.begin(), dirList.end() - , [](const QString &l, const QString &r) { return l.count(u'/') > r.count(u'/'); }); + std::ranges::sort(dirList, [](const QString &l, const QString &r) { return l.count(u'/') > r.count(u'/'); }); for (const QString &p : asConst(dirList)) { @@ -108,7 +107,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const Path &path) // deleteFilesList contains unwanted files, usually created by the OS // temp files on linux usually end with '~', e.g. `filename~` - const bool hasOtherFiles = std::any_of(tmpFileList.cbegin(), tmpFileList.cend(), [&deleteFilesList](const QString &f) + const bool hasOtherFiles = std::ranges::any_of(tmpFileList, [&deleteFilesList](const QString &f) { return (!f.endsWith(u'~') && !deleteFilesList.contains(f, Qt::CaseInsensitive)); }); diff --git a/src/base/utils/net.cpp b/src/base/utils/net.cpp index 40247e38c..dd64ceee0 100644 --- a/src/base/utils/net.cpp +++ b/src/base/utils/net.cpp @@ -71,7 +71,7 @@ namespace Utils protocolEquivalentAddress = QHostAddress(addr.toIPv4Address(&addrConversionOk)); } - return std::any_of(subnets.begin(), subnets.end(), [&](const Subnet &subnet) + return std::ranges::any_of(subnets, [&](const Subnet &subnet) { return addr.isInSubnet(subnet) || (addrConversionOk && protocolEquivalentAddress.isInSubnet(subnet)); @@ -117,7 +117,7 @@ namespace Utils QList loadSSLCertificate(const QByteArray &data) { const QList certs {QSslCertificate::fromData(data)}; - const bool hasInvalidCerts = std::any_of(certs.cbegin(), certs.cend(), [](const QSslCertificate &cert) + const bool hasInvalidCerts = std::ranges::any_of(certs, [](const QSslCertificate &cert) { return cert.isNull(); }); diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 5ab0fd0d0..70757b066 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -460,7 +460,7 @@ void AddNewTorrentDialog::setCurrentContext(const std::shared_ptr conte // Load categories QStringList categories = session->categories(); - std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan()); + std::ranges::sort(categories, Utils::Compare::NaturalLessThan()); const QString defaultCategory = m_storeDefaultCategory; if (!addTorrentParams.category.isEmpty()) diff --git a/src/gui/addtorrentparamswidget.cpp b/src/gui/addtorrentparamswidget.cpp index dd5203dd2..bedf88ffd 100644 --- a/src/gui/addtorrentparamswidget.cpp +++ b/src/gui/addtorrentparamswidget.cpp @@ -167,7 +167,7 @@ void AddTorrentParamsWidget::populate() m_ui->categoryComboBox->disconnect(this); m_ui->categoryComboBox->clear(); QStringList categories = BitTorrent::Session::instance()->categories(); - std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan()); + std::ranges::sort(categories, Utils::Compare::NaturalLessThan()); if (!m_addTorrentParams.category.isEmpty()) m_ui->categoryComboBox->addItem(m_addTorrentParams.category); m_ui->categoryComboBox->addItem(u""_s); diff --git a/src/gui/banlistoptionsdialog.cpp b/src/gui/banlistoptionsdialog.cpp index 23daee3cf..127f0470c 100644 --- a/src/gui/banlistoptionsdialog.cpp +++ b/src/gui/banlistoptionsdialog.cpp @@ -120,7 +120,7 @@ void BanListOptionsDialog::on_buttonBanIP_clicked() void BanListOptionsDialog::on_buttonDeleteIP_clicked() { QModelIndexList selection = m_ui->bannedIPList->selectionModel()->selectedIndexes(); - std::sort(selection.begin(), selection.end(), [](const QModelIndex &left, const QModelIndex &right) + std::ranges::sort(selection, [](const QModelIndex &left, const QModelIndex &right) { return (left.row() > right.row()); }); diff --git a/src/gui/cookiesdialog.cpp b/src/gui/cookiesdialog.cpp index 52d0dc860..dd6617267 100644 --- a/src/gui/cookiesdialog.cpp +++ b/src/gui/cookiesdialog.cpp @@ -100,12 +100,10 @@ void CookiesDialog::onButtonDeleteClicked() QModelIndexList idxs = m_ui->treeView->selectionModel()->selectedRows(); // sort in descending order - std::sort(idxs.begin(), idxs.end(), - [](const QModelIndex &l, const QModelIndex &r) - { - return (l.row() > r.row()); - } - ); + std::ranges::sort(idxs, [](const QModelIndex &l, const QModelIndex &r) + { + return (l.row() > r.row()); + }); for (const QModelIndex &idx : asConst(idxs)) m_cookiesModel->removeRow(idx.row()); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index f29ac971e..a68ff1893 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1184,7 +1184,7 @@ void MainWindow::closeEvent(QCloseEvent *e) #endif // Q_OS_MACOS const QList allTorrents = BitTorrent::Session::instance()->torrents(); - const bool hasActiveTorrents = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [](BitTorrent::Torrent *torrent) + const bool hasActiveTorrents = std::ranges::any_of(allTorrents, [](const BitTorrent::Torrent *torrent) { return torrent->isActive(); }); @@ -1259,7 +1259,7 @@ bool MainWindow::event(QEvent *e) qDebug() << "Has active window:" << (qApp->activeWindow() != nullptr); // Check if there is a modal window const QWidgetList allWidgets = QApplication::allWidgets(); - const bool hasModalWindow = std::any_of(allWidgets.cbegin(), allWidgets.cend() + const bool hasModalWindow = std::ranges::any_of(allWidgets , [](const QWidget *widget) { return widget->isModal(); }); // Iconify if there is no modal window if (!hasModalWindow) @@ -1821,7 +1821,7 @@ void MainWindow::updatePowerManagementState() const const bool preventFromSuspendWhenSeeding = pref->preventFromSuspendWhenSeeding(); const QList allTorrents = BitTorrent::Session::instance()->torrents(); - const bool inhibitSuspend = std::any_of(allTorrents.cbegin(), allTorrents.cend(), [&](const BitTorrent::Torrent *torrent) + const bool inhibitSuspend = std::ranges::any_of(allTorrents, [&](const BitTorrent::Torrent *torrent) { if (preventFromSuspendWhenDownloading && (!torrent->isFinished() && !torrent->isStopped() && !torrent->isErrored() && torrent->hasMetadata())) return true; diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index f5d597232..8fd606dd2 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -1762,7 +1762,7 @@ void OptionsDialog::initializeStyleCombo() m_ui->comboStyle->insertSeparator(1); QStringList styleNames = QStyleFactory::keys(); - std::sort(styleNames.begin(), styleNames.end(), Utils::Compare::NaturalLessThan()); + std::ranges::sort(styleNames, Utils::Compare::NaturalLessThan()); for (const QString &styleName : asConst(styleNames)) m_ui->comboStyle->addItem(styleName, styleName); diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 4c27d4eb4..75f9ccffb 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -293,7 +293,7 @@ void PeerListWidget::showPeerListMenu() , this, [this, torrent]() { const QList peersList = PeersAdditionDialog::askForPeers(this); - const int peerCount = std::count_if(peersList.cbegin(), peersList.cend(), [torrent](const BitTorrent::PeerAddress &peer) + const int peerCount = std::ranges::count_if(peersList, [torrent](const BitTorrent::PeerAddress &peer) { return torrent->connectPeer(peer); }); diff --git a/src/gui/properties/pieceavailabilitybar.cpp b/src/gui/properties/pieceavailabilitybar.cpp index 0e9e2a656..66c39a2b3 100644 --- a/src/gui/properties/pieceavailabilitybar.cpp +++ b/src/gui/properties/pieceavailabilitybar.cpp @@ -48,11 +48,11 @@ QList PieceAvailabilityBar::intToFloatVector(const QList &vecin, int const float ratio = static_cast(vecin.size()) / reqSize; - const int maxElement = *std::max_element(vecin.begin(), vecin.end()); + const int maxElement = *std::ranges::max_element(vecin); // std::max because in normalization we don't want divide by 0 // if maxElement == 0 check will be disabled please enable this line: - // const int maxElement = std::max(*std::max_element(avail.begin(), avail.end()), 1); + // const int maxElement = std::max(*std::ranges::max_element(avail), 1); if (maxElement == 0) return result; diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 775ed7a1f..5e1f222f0 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -564,7 +564,7 @@ void SearchWidget::fillCatCombobox() const auto selectedPlugin = m_ui->selectPlugin->itemData(m_ui->selectPlugin->currentIndex()).toString(); for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin))) tmpList << std::make_pair(SearchPluginManager::categoryFullName(cat), cat); - std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); }); + std::ranges::sort(tmpList, [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); }); for (const QStrPair &p : asConst(tmpList)) { @@ -587,7 +587,7 @@ void SearchWidget::fillPluginComboBox() QList tmpList; for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins())) tmpList << std::make_pair(SearchPluginManager::instance()->pluginFullName(name), name); - std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } ); + std::ranges::sort(tmpList, [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); }); for (const QStrPair &p : asConst(tmpList)) m_ui->selectPlugin->addItem(p.first, p.second); diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index 0238174c3..2a88a5242 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -401,7 +401,7 @@ QVariant TorrentContentModel::data(const QModelIndex &index, const int role) con const auto *folder = static_cast(item); const auto childItems = folder->children(); - const bool hasIgnored = std::any_of(childItems.cbegin(), childItems.cend() + const bool hasIgnored = std::ranges::any_of(childItems , [](const TorrentContentModelItem *childItem) { const auto prio = childItem->priority(); @@ -583,8 +583,7 @@ void TorrentContentModel::populate() QList pathFolders = QStringView(path).split(u'/', Qt::SkipEmptyParts); const QString fileName = pathFolders.takeLast().toString(); - if (!std::equal(lastParentPath.begin(), lastParentPath.end() - , pathFolders.begin(), pathFolders.end())) + if (!std::ranges::equal(asConst(lastParentPath), asConst(pathFolders))) { lastParentPath.clear(); lastParentPath.reserve(pathFolders.size()); diff --git a/src/gui/torrentoptionsdialog.cpp b/src/gui/torrentoptionsdialog.cpp index 85b72ea7c..be35440b3 100644 --- a/src/gui/torrentoptionsdialog.cpp +++ b/src/gui/torrentoptionsdialog.cpp @@ -231,7 +231,7 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QListcomboCategory->addItem(QString()); m_categories = session->categories(); - std::sort(m_categories.begin(), m_categories.end(), Utils::Compare::NaturalLessThan()); + std::ranges::sort(m_categories, Utils::Compare::NaturalLessThan()); for (const QString &category : asConst(m_categories)) { if (m_allSameCategory && (category == firstTorrentCategory)) diff --git a/src/gui/transferlistfilters/categoryfiltermodel.cpp b/src/gui/transferlistfilters/categoryfiltermodel.cpp index 4f27dd640..dfab6672e 100644 --- a/src/gui/transferlistfilters/categoryfiltermodel.cpp +++ b/src/gui/transferlistfilters/categoryfiltermodel.cpp @@ -434,8 +434,8 @@ void CategoryFilterModel::populate() // Uncategorized torrents using Torrent = BitTorrent::Torrent; - const int torrentsCount = std::count_if(torrents.begin(), torrents.end() - , [](Torrent *torrent) { return torrent->category().isEmpty(); }); + const int torrentsCount = std::ranges::count_if(torrents + , [](const Torrent *torrent) { return torrent->category().isEmpty(); }); m_rootItem->addChild(CategoryModelItem::UID_UNCATEGORIZED , new CategoryModelItem(nullptr, tr("Uncategorized"), torrentsCount)); @@ -450,8 +450,8 @@ void CategoryFilterModel::populate() const QString subcatName = shortName(subcat); if (!parent->hasChild(subcatName)) { - const int torrentsCount = std::count_if(torrents.cbegin(), torrents.cend() - , [subcat](Torrent *torrent) { return torrent->category() == subcat; }); + const int torrentsCount = std::ranges::count_if(torrents + , [&subcat](const Torrent *torrent) { return torrent->category() == subcat; }); new CategoryModelItem(parent, subcatName, torrentsCount); } parent = parent->child(subcatName); @@ -462,8 +462,8 @@ void CategoryFilterModel::populate() { for (const QString &categoryName : asConst(session->categories())) { - const int torrentsCount = std::count_if(torrents.begin(), torrents.end() - , [categoryName](Torrent *torrent) { return torrent->belongsToCategory(categoryName); }); + const int torrentsCount = std::ranges::count_if(torrents + , [&categoryName](const Torrent *torrent) { return torrent->belongsToCategory(categoryName); }); new CategoryModelItem(m_rootItem, categoryName, torrentsCount); } } diff --git a/src/gui/transferlistfilters/tagfiltermodel.cpp b/src/gui/transferlistfilters/tagfiltermodel.cpp index 6e741cf86..490c5a46a 100644 --- a/src/gui/transferlistfilters/tagfiltermodel.cpp +++ b/src/gui/transferlistfilters/tagfiltermodel.cpp @@ -294,14 +294,14 @@ void TagFilterModel::populate() // All torrents addToModel(Tag(), torrents.count()); - const int untaggedCount = std::count_if(torrents.cbegin(), torrents.cend() - , [](Torrent *torrent) { return torrent->tags().isEmpty(); }); + const int untaggedCount = std::ranges::count_if(torrents + , [](const Torrent *torrent) { return torrent->tags().isEmpty(); }); addToModel(Tag(), untaggedCount); for (const Tag &tag : asConst(session->tags())) { - const int count = std::count_if(torrents.cbegin(), torrents.cend() - , [tag](Torrent *torrent) { return torrent->hasTag(tag); }); + const int count = std::ranges::count_if(torrents + , [&tag](const Torrent *torrent) { return torrent->hasTag(tag); }); addToModel(tag, count); } } diff --git a/src/gui/transferlistfilters/trackersfilterwidget.cpp b/src/gui/transferlistfilters/trackersfilterwidget.cpp index 894c1b578..fd0c9524f 100644 --- a/src/gui/transferlistfilters/trackersfilterwidget.cpp +++ b/src/gui/transferlistfilters/trackersfilterwidget.cpp @@ -402,7 +402,7 @@ void TrackersFilterWidget::handleTrackerStatusesUpdated(const BitTorrent::Torren if (trackerErrorHashesIt != m_trackerErrors.end()) trackerErrorHashesIt->remove(trackerEntryStatus.url); - const bool hasNoWarningMessages = std::all_of(trackerEntryStatus.endpoints.cbegin(), trackerEntryStatus.endpoints.cend() + const bool hasNoWarningMessages = std::ranges::all_of(trackerEntryStatus.endpoints , [](const BitTorrent::TrackerEndpointStatus &endpointEntry) { return endpointEntry.message.isEmpty() || (endpointEntry.state != BitTorrent::TrackerEndpointState::Working); diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 2444400dc..c0a93e938 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -582,7 +582,7 @@ void TransferListWidget::copySelectedComments() const torrentComments << torrent->comment(); } - qApp->clipboard()->setText(torrentComments.join(u"\n---------\n"_s)); + qApp->clipboard()->setText(torrentComments.join(u"\n---------\n")); } void TransferListWidget::hideQueuePosColumn(bool hide) @@ -793,9 +793,10 @@ void TransferListWidget::editTorrentTrackers() for (const BitTorrent::TrackerEntryStatus &status : asConst(torrent->trackers())) trackerSet.insert({.url = status.url, .tier = status.tier}); - commonTrackers.erase(std::remove_if(commonTrackers.begin(), commonTrackers.end() - , [&trackerSet](const BitTorrent::TrackerEntry &entry) { return !trackerSet.contains(entry); }) - , commonTrackers.end()); + commonTrackers.removeIf([&trackerSet](const BitTorrent::TrackerEntry &entry) + { + return !trackerSet.contains(entry); + }); } } @@ -1170,7 +1171,7 @@ void TransferListWidget::displayListMenu() // Category Menu QStringList categories = BitTorrent::Session::instance()->categories(); - std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan()); + std::ranges::sort(categories, Utils::Compare::NaturalLessThan()); QMenu *categoryMenu = listMenu->addMenu(UIThemeManager::instance()->getIcon(u"view-categories"_s), tr("Categor&y")); diff --git a/src/webui/api/apicontroller.cpp b/src/webui/api/apicontroller.cpp index e1b9d52b5..c3382f705 100644 --- a/src/webui/api/apicontroller.cpp +++ b/src/webui/api/apicontroller.cpp @@ -86,7 +86,7 @@ void APIController::requireParams(const QList &requiredParams) const } if (!missingParams.isEmpty()) - throw APIError(APIErrorType::BadParams, tr("Missing required parameters: %1").arg(missingParams.join(u", "_s))); + throw APIError(APIErrorType::BadParams, tr("Missing required parameters: %1").arg(missingParams.join(u", "))); } void APIController::setResult(const QString &result) diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index e2e465acd..f7aa1b72d 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -980,7 +980,7 @@ void AppController::setPreferencesAction() const QString ifaceValue {it.value().toString()}; const QList ifaces = QNetworkInterface::allInterfaces(); - const auto ifacesIter = std::find_if(ifaces.cbegin(), ifaces.cend(), [&ifaceValue](const QNetworkInterface &iface) + const auto ifacesIter = std::ranges::find_if(ifaces, [&ifaceValue](const QNetworkInterface &iface) { return (!iface.addressEntries().isEmpty()) && (iface.name() == ifaceValue); }); diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 550eb3ec9..99186ac9b 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -628,7 +628,7 @@ void TorrentsController::infoAction() return false; }; - std::sort(torrentList.begin(), torrentList.end() + std::ranges::sort(torrentList , [reverse, &sortedColumn, &lessThan](const QVariant &torrent1, const QVariant &torrent2) { const QVariant value1 {torrent1.toMap().value(sortedColumn)}; @@ -931,8 +931,7 @@ void TorrentsController::filesAction() const int filesCount = torrent->filesCount(); const QStringList indexStrings = idxIt.value().split(u'|'); fileIndexes.reserve(indexStrings.size()); - std::transform(indexStrings.cbegin(), indexStrings.cend(), std::back_inserter(fileIndexes) - , [&filesCount](const QString &indexString) -> int + for (const QString &indexString : indexStrings) { bool ok = false; const int index = indexString.toInt(&ok); @@ -940,8 +939,8 @@ void TorrentsController::filesAction() throw APIError(APIErrorType::Conflict, tr("\"%1\" is not a valid file index.").arg(indexString)); if (index >= filesCount) throw APIError(APIErrorType::Conflict, tr("Index %1 is out of bounds.").arg(indexString)); - return index; - }); + fileIndexes.push_back(index); + } } QJsonArray fileList = getFiles(torrent, fileIndexes); @@ -1348,7 +1347,7 @@ void TorrentsController::addPeersAction() applyToTorrents(hashes, [peers, peerList, &results](BitTorrent::Torrent *const torrent) { - const int peersAdded = std::count_if(peerList.cbegin(), peerList.cend(), [torrent](const BitTorrent::PeerAddress &peer) + const int peersAdded = std::ranges::count_if(peerList, [torrent](const BitTorrent::PeerAddress &peer) { return torrent->connectPeer(peer); }); diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 35cba850e..f3ea9defe 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -446,7 +446,8 @@ void WebApplication::configure() m_sessionCookieName = SESSION_COOKIE_NAME_PREFIX + QString::number(pref->getWebUIPort()); m_domainList = pref->getServerDomains().split(u';', Qt::SkipEmptyParts); - std::for_each(m_domainList.begin(), m_domainList.end(), [](QString &entry) { entry = entry.trimmed(); }); + for (QString &entry : m_domainList) + entry = entry.trimmed(); m_isCSRFProtectionEnabled = pref->isWebUICSRFProtectionEnabled(); m_isSecureCookieEnabled = pref->isWebUISecureCookieEnabled();