cleanup: Changes for c++17

This cleanup adjusts the rTorrent code to comply with c++17 standard. It also simplifies various parts of the code.
This commit is contained in:
stickz
2025-01-15 13:27:35 -05:00
committed by Jari Sundell
parent 2e0a417367
commit e7fc891f11
14 changed files with 29 additions and 34 deletions
+1 -1
View File
@@ -50,7 +50,7 @@
namespace rak {
class regex : public std::unary_function<std::string, bool> {
class regex : public std::function<bool (std::string)> {
public:
regex() {}
regex(const std::string& p) : m_pattern(p) {}
+1 -1
View File
@@ -222,7 +222,7 @@ apply_close_low_diskspace(int64_t arg) {
bool closed = false;
core::Manager::DListItr itr = downloadList->begin();
while ((itr = std::find_if(itr, downloadList->end(), std::mem_fun(&core::Download::is_downloading)))
while ((itr = std::find_if(itr, downloadList->end(), std::mem_fn(&core::Download::is_downloading)))
!= downloadList->end()) {
if ((*itr)->file_list()->free_diskspace() < (uint64_t)arg) {
downloadList->close(*itr);
+1 -2
View File
@@ -99,8 +99,7 @@ apply_dht_add_node(const std::string& arg) {
torrent::Object
apply_enable_trackers(int64_t arg) {
for (core::Manager::DListItr itr = control->core()->download_list()->begin(), last = control->core()->download_list()->end(); itr != last; ++itr) {
std::for_each((*itr)->tracker_list()->begin(), (*itr)->tracker_list()->end(),
arg ? std::mem_fun(&torrent::Tracker::enable) : std::mem_fun(&torrent::Tracker::disable));
std::for_each((*itr)->tracker_list()->begin(), (*itr)->tracker_list()->end(), std::mem_fn(arg ? &torrent::Tracker::enable : &torrent::Tracker::disable));
if (arg && !rpc::call_command_value("trackers.use_udp"))
(*itr)->enable_udp_trackers(false);
+5 -5
View File
@@ -79,7 +79,7 @@ DownloadList::check_contains(Download* d) {
void
DownloadList::clear() {
std::for_each(begin(), end(), std::bind1st(std::mem_fun(&DownloadList::close), this));
std::for_each(begin(), end(), [&](Download* d) { close(d); });
std::for_each(begin(), end(), [](Download* d) { delete d; });
base_type::clear();
@@ -87,7 +87,7 @@ DownloadList::clear() {
void
DownloadList::session_save() {
unsigned int c = std::count_if(begin(), end(), std::bind1st(std::mem_fun(&DownloadStore::save_resume), control->core()->download_store()));
unsigned int c = std::count_if(begin(), end(), [&](Download* d) { return control->core()->download_store()->save_resume(d); });
if (c != size())
lt_log_print(torrent::LOG_ERROR, "Failed to save session torrents.");
@@ -186,8 +186,8 @@ DownloadList::insert(Download* download) {
// This needs to be separated into two different calls to ensure
// the download remains in the view.
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fun(&View::insert), download));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fun(&View::filter_download), download));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->insert(download); });
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->filter_download(download); });
DL_TRIGGER_EVENT(*itr, "event.download.inserted");
@@ -220,7 +220,7 @@ DownloadList::erase(iterator itr) {
control->core()->download_store()->remove(*itr);
DL_TRIGGER_EVENT(*itr, "event.download.erased");
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fun(&View::erase), *itr));
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [itr](View* v) { v->erase(*itr); });
torrent::download_remove(*(*itr)->download());
delete *itr;
+1 -1
View File
@@ -175,7 +175,7 @@ DownloadStore::get_formated_entries() {
if (!d.update(utils::Directory::update_hide_dot))
throw torrent::storage_error("core::DownloadStore::update() could not open directory \"" + m_path + "\"");
d.erase(std::remove_if(d.begin(), d.end(), std::ptr_fun(&not_correct_format)), d.end());
d.erase(std::remove_if(d.begin(), d.end(), [&](const utils::directory_entry& entry) { return not_correct_format(entry); }), d.end());
return d;
}
+1 -1
View File
@@ -47,7 +47,7 @@ namespace core {
HttpQueue::iterator
HttpQueue::insert(const std::string& url, std::iostream* s) {
std::auto_ptr<CurlGet> h(m_slot_factory());
std::unique_ptr<CurlGet> h(m_slot_factory());
h->set_url(url);
h->set_stream(s);
+2 -2
View File
@@ -419,7 +419,7 @@ path_expand(std::vector<std::string>* paths, const std::string& pattern) {
currentCache.swap(nextCache);
}
std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::path));
std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fn(&utils::Directory::path));
}
bool
@@ -453,7 +453,7 @@ Manager::try_create_download_expand(const std::string& uri, int flags, command_l
void
Manager::receive_hashing_changed() {
bool foundHashing = std::find_if(m_hashingView->begin_visible(), m_hashingView->end_visible(),
std::mem_fun(&Download::is_hash_checking)) != m_hashingView->end_visible();
std::mem_fn(&Download::is_hash_checking)) != m_hashingView->end_visible();
// Try quick hashing all those with hashing == initial, set them to
// something else when failed.
+2 -2
View File
@@ -16,7 +16,7 @@
namespace core {
// Also add focus thingie here?
struct view_downloads_compare : std::binary_function<Download*, Download*, bool> {
struct view_downloads_compare : std::function<bool (Download*, Download*)> {
view_downloads_compare(const torrent::Object& cmd) :
m_command(cmd) {}
@@ -50,7 +50,7 @@ struct view_downloads_compare : std::binary_function<Download*, Download*, bool>
const torrent::Object& m_command;
};
struct view_downloads_filter : std::unary_function<Download*, bool> {
struct view_downloads_filter : std::function<bool (Download*)> {
view_downloads_filter(const torrent::Object& cmd, const torrent::Object& cmd2) :
m_command(cmd), m_command2(cmd2) {}
+1 -1
View File
@@ -199,7 +199,7 @@ print_download_status(char* first, char* last, core::Download* d) {
} else if (d->tracker_list()->has_active_not_scrape()) {
torrent::TrackerList::iterator itr =
std::find_if(d->tracker_list()->begin(), d->tracker_list()->end(),
std::mem_fun(&torrent::Tracker::is_busy_not_scrape));
std::mem_fn(&torrent::Tracker::is_busy_not_scrape));
char status[128];
(*itr)->get_status(status, sizeof(status));
+1 -1
View File
@@ -110,7 +110,7 @@ WindowDownloadChunksSeen::redraw() {
if (bitfield->get(chunk - seen)) {
attr = A_NORMAL;
} else if (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) == (*itrTransfer)->index()) {
if (std::find_if((*itrTransfer)->begin(), (*itrTransfer)->end(), std::mem_fun_ref(&torrent::Block::is_transfering)) != (*itrTransfer)->end())
if (std::any_of((*itrTransfer)->begin(), (*itrTransfer)->end(), std::mem_fn(&torrent::Block::is_transfering)))
attr = A_REVERSE;
else
attr = A_BOLD | A_UNDERLINE;
+1 -1
View File
@@ -64,7 +64,7 @@ Manager::pressed(int key) {
if (m_textInput != NULL)
m_textInput->pressed(key);
else
std::find_if(rbegin(), rend(), std::bind2nd(std::mem_fun(&Bindings::pressed), key));
std::find_if(rbegin(), rend(), [&key](Bindings* bind) { return bind->pressed(key); });
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ bool
OptionParser::has_flag(char flag, int argc, char** argv) {
char options[3] = { '-', flag, '\0' };
return std::find_if(argv, argv + argc, std::not1(std::bind1st(std::ptr_fun(&std::strcmp), options))) != argv + argc;
return std::find_if(argv, argv + argc, [&options](char* c) { return std::strcmp(c, options) == 0; }) != argv + argc;
}
std::string
+10 -14
View File
@@ -52,17 +52,13 @@ CommandMap commands;
XmlRpc xmlrpc;
ExecFile execFile;
struct command_map_is_space : std::unary_function<char, bool> {
bool operator () (char c) const {
return c == ' ' || c == '\t';
}
};
inline bool command_map_is_space(char c) {
return c == ' ' || c == '\t';
}
struct command_map_is_newline : std::unary_function<char, bool> {
bool operator () (char c) const {
return c == '\n' || c == '\0' || c == ';';
}
};
inline bool command_map_is_newline(char c) {
return c == '\n' || c == '\0' || c == ';';
}
// Only escape eol on odd number of escape characters. We know that
// there can't be any characters in between, so this should work for
@@ -131,7 +127,7 @@ parse_command_name(const char* first, const char* last, char* dest_first, char*
// the code below for both cases.
parse_command_type
parse_command(target_type target, const char* first, const char* last) {
first = std::find_if(first, last, std::not1(command_map_is_space()));
first = std::find_if(first, last, [&](char c) { return !command_map_is_space(c); });
if (first == last || *first == '#')
return std::make_pair(torrent::Object(), first);
@@ -139,7 +135,7 @@ parse_command(target_type target, const char* first, const char* last) {
char key[128];
first = parse_command_name(first, last, key, key + 128);
first = std::find_if(first, last, std::not1(command_map_is_space()));
first = std::find_if(first, last, [&](char c) { return !command_map_is_space(c); });
if (first == last || *first != '=')
throw torrent::input_error("Could not find '=' in command '" + std::string(key) + "'.");
@@ -150,10 +146,10 @@ parse_command(target_type target, const char* first, const char* last) {
// Find the last character that is part of this command, skipping
// the whitespace at the end. This ensures us that the caller
// doesn't need to do this nor check for junk at the end.
first = std::find_if(first, last, std::not1(command_map_is_space()));
first = std::find_if(first, last, [&](char c) { return !command_map_is_space(c); });
if (first != last) {
if (*first != '\n' && *first != ';' && *first != '\0')
if (!command_map_is_newline(*first))
throw torrent::input_error("Junk at end of input.");
first++;
+1 -1
View File
@@ -142,7 +142,7 @@ SCgi::event_read() {
utils::SocketFd fd;
while ((fd = get_fd().accept(&sa)).is_valid()) {
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fun_ref(&SCgiTask::is_available));
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fn(&SCgiTask::is_available));
if (task == m_task + max_tasks) {
// Ergh... just closing for now.