Avoid heavy weight function object

Also, by switching to template we can avoid the cost of converting to some specific type and
perfectly forward the parameter to the final function.

PR #21572.
This commit is contained in:
Chocobo1 2024-10-12 15:15:39 +08:00 committed by GitHub
commit 21b0367629
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 11 deletions

View file

@ -28,6 +28,7 @@
#include "torrentscontroller.h"
#include <concepts>
#include <functional>
#include <QBitArray>
@ -135,7 +136,9 @@ namespace
const QSet<QString> SUPPORTED_WEB_SEED_SCHEMES {u"http"_s, u"https"_s, u"ftp"_s};
void applyToTorrents(const QStringList &idList, const std::function<void (BitTorrent::Torrent *torrent)> &func)
template <typename Func>
void applyToTorrents(const QStringList &idList, Func func)
requires std::invocable<Func, BitTorrent::Torrent *>
{
if ((idList.size() == 1) && (idList[0] == u"all"))
{