Skip to content

Commit d60a37b

Browse files
committed
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.
1 parent b5a6ee3 commit d60a37b

14 files changed

+27
-36
lines changed

rak/regex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
namespace rak {
5252

53-
class regex : public std::unary_function<std::string, bool> {
53+
class regex : public std::function<bool (std::string)> {
5454
public:
5555
regex() {}
5656
regex(const std::string& p) : m_pattern(p) {}

src/command_events.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ apply_close_low_diskspace(int64_t arg) {
222222
bool closed = false;
223223
core::Manager::DListItr itr = downloadList->begin();
224224

225-
while ((itr = std::find_if(itr, downloadList->end(), std::mem_fun(&core::Download::is_downloading)))
225+
while ((itr = std::find_if(itr, downloadList->end(), std::mem_fn(&core::Download::is_downloading)))
226226
!= downloadList->end()) {
227227
if ((*itr)->file_list()->free_diskspace() < (uint64_t)arg) {
228228
downloadList->close(*itr);

src/command_tracker.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ apply_dht_add_node(const std::string& arg) {
9999
torrent::Object
100100
apply_enable_trackers(int64_t arg) {
101101
for (core::Manager::DListItr itr = control->core()->download_list()->begin(), last = control->core()->download_list()->end(); itr != last; ++itr) {
102-
std::for_each((*itr)->tracker_list()->begin(), (*itr)->tracker_list()->end(),
103-
arg ? std::mem_fun(&torrent::Tracker::enable) : std::mem_fun(&torrent::Tracker::disable));
102+
std::for_each((*itr)->tracker_list()->begin(), (*itr)->tracker_list()->end(), std::mem_fn(arg ? &torrent::Tracker::enable : &torrent::Tracker::disable));
104103

105104
if (arg && !rpc::call_command_value("trackers.use_udp"))
106105
(*itr)->enable_udp_trackers(false);

src/core/download_list.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ DownloadList::check_contains(Download* d) {
7979

8080
void
8181
DownloadList::clear() {
82-
std::for_each(begin(), end(), std::bind1st(std::mem_fun(&DownloadList::close), this));
82+
std::for_each(begin(), end(), [&](Download* d) { close(d); });
8383
std::for_each(begin(), end(), [](Download* d) { delete d; });
8484

8585
base_type::clear();
8686
}
8787

8888
void
8989
DownloadList::session_save() {
90-
unsigned int c = std::count_if(begin(), end(), std::bind1st(std::mem_fun(&DownloadStore::save_resume), control->core()->download_store()));
90+
unsigned int c = std::count_if(begin(), end(), [&](Download* d) { return control->core()->download_store()->save_resume(d); });
9191

9292
if (c != size())
9393
lt_log_print(torrent::LOG_ERROR, "Failed to save session torrents.");
@@ -181,13 +181,13 @@ DownloadList::insert(Download* download) {
181181
lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Inserting download.");
182182

183183
try {
184-
(*itr)->data()->slot_initial_hash() = std::bind(&DownloadList::hash_done, this, download);
185-
(*itr)->data()->slot_download_done() = std::bind(&DownloadList::received_finished, this, download);
184+
(*itr)->data()->slot_initial_hash() = [this, download]() { hash_done(download); }
185+
(*itr)->data()->slot_download_done() = [this, download]() { received_finished(download); };
186186

187187
// This needs to be separated into two different calls to ensure
188188
// the download remains in the view.
189-
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fun(&View::insert), download));
190-
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fun(&View::filter_download), download));
189+
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->insert(download); });
190+
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->filter_download(download); });
191191

192192
DL_TRIGGER_EVENT(*itr, "event.download.inserted");
193193

@@ -220,7 +220,7 @@ DownloadList::erase(iterator itr) {
220220
control->core()->download_store()->remove(*itr);
221221

222222
DL_TRIGGER_EVENT(*itr, "event.download.erased");
223-
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), std::bind2nd(std::mem_fun(&View::erase), *itr));
223+
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [itr](View* v) { v->erase(*itr); });
224224

225225
torrent::download_remove(*(*itr)->download());
226226
delete *itr;

src/core/download_store.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ DownloadStore::get_formated_entries() {
175175
if (!d.update(utils::Directory::update_hide_dot))
176176
throw torrent::storage_error("core::DownloadStore::update() could not open directory \"" + m_path + "\"");
177177

178-
d.erase(std::remove_if(d.begin(), d.end(), std::ptr_fun(&not_correct_format)), d.end());
178+
d.erase(std::remove_if(d.begin(), d.end(), [&](const utils::directory_entry& entry) { return not_correct_format(entry); }), d.end());
179179

180180
return d;
181181
}

src/core/http_queue.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace core {
4747

4848
HttpQueue::iterator
4949
HttpQueue::insert(const std::string& url, std::iostream* s) {
50-
std::auto_ptr<CurlGet> h(m_slot_factory());
50+
std::unique_ptr<CurlGet> h(m_slot_factory());
5151

5252
h->set_url(url);
5353
h->set_stream(s);

src/core/manager.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ path_expand(std::vector<std::string>* paths, const std::string& pattern) {
419419
currentCache.swap(nextCache);
420420
}
421421

422-
std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::path));
422+
std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fn(&utils::Directory::path));
423423
}
424424

425425
bool
@@ -453,7 +453,7 @@ Manager::try_create_download_expand(const std::string& uri, int flags, command_l
453453
void
454454
Manager::receive_hashing_changed() {
455455
bool foundHashing = std::find_if(m_hashingView->begin_visible(), m_hashingView->end_visible(),
456-
std::mem_fun(&Download::is_hash_checking)) != m_hashingView->end_visible();
456+
std::mem_fn(&Download::is_hash_checking)) != m_hashingView->end_visible();
457457

458458
// Try quick hashing all those with hashing == initial, set them to
459459
// something else when failed.

src/core/view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace core {
1717

1818
// Also add focus thingie here?
19-
struct view_downloads_compare : std::binary_function<Download*, Download*, bool> {
19+
struct view_downloads_compare : std::function<bool (Download*, Download*)> {
2020
view_downloads_compare(const torrent::Object& cmd) :
2121
m_command(cmd) {}
2222

@@ -50,7 +50,7 @@ struct view_downloads_compare : std::binary_function<Download*, Download*, bool>
5050
const torrent::Object& m_command;
5151
};
5252

53-
struct view_downloads_filter : std::unary_function<Download*, bool> {
53+
struct view_downloads_filter : std::function<bool (Download*)> {
5454
view_downloads_filter(const torrent::Object& cmd, const torrent::Object& cmd2) :
5555
m_command(cmd), m_command2(cmd2) {}
5656

src/display/utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ print_download_status(char* first, char* last, core::Download* d) {
199199
} else if (d->tracker_list()->has_active_not_scrape()) {
200200
torrent::TrackerList::iterator itr =
201201
std::find_if(d->tracker_list()->begin(), d->tracker_list()->end(),
202-
std::mem_fun(&torrent::Tracker::is_busy_not_scrape));
202+
std::mem_fn(&torrent::Tracker::is_busy_not_scrape));
203203
char status[128];
204204

205205
(*itr)->get_status(status, sizeof(status));

src/display/window_download_chunks_seen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ WindowDownloadChunksSeen::redraw() {
110110
if (bitfield->get(chunk - seen)) {
111111
attr = A_NORMAL;
112112
} else if (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) == (*itrTransfer)->index()) {
113-
if (std::find_if((*itrTransfer)->begin(), (*itrTransfer)->end(), std::mem_fun_ref(&torrent::Block::is_transfering)) != (*itrTransfer)->end())
113+
if (std::any_of((*itrTransfer)->begin(), (*itrTransfer)->end(), std::mem_fn(&torrent::Block::is_transfering)))
114114
attr = A_REVERSE;
115115
else
116116
attr = A_BOLD | A_UNDERLINE;

src/input/manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Manager::pressed(int key) {
6464
if (m_textInput != NULL)
6565
m_textInput->pressed(key);
6666
else
67-
std::find_if(rbegin(), rend(), std::bind2nd(std::mem_fun(&Bindings::pressed), key));
67+
std::for_each(rbegin(), rend(), [&key](Bindings* bind) { bind->pressed(key); });
6868
}
6969

7070
}

src/option_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool
8888
OptionParser::has_flag(char flag, int argc, char** argv) {
8989
char options[3] = { '-', flag, '\0' };
9090

91-
return std::find_if(argv, argv + argc, std::not1(std::bind1st(std::ptr_fun(&std::strcmp), options))) != argv + argc;
91+
return std::find_if(argv, argv + argc, [&options](char* c) { return std::strcmp(c, options) == 0; }) != argv + argc;
9292
}
9393

9494
std::string

src/rpc/parse_commands.cc

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,9 @@ CommandMap commands;
5252
XmlRpc xmlrpc;
5353
ExecFile execFile;
5454

55-
struct command_map_is_space : std::unary_function<char, bool> {
56-
bool operator () (char c) const {
57-
return c == ' ' || c == '\t';
58-
}
59-
};
60-
61-
struct command_map_is_newline : std::unary_function<char, bool> {
62-
bool operator () (char c) const {
63-
return c == '\n' || c == '\0' || c == ';';
64-
}
65-
};
55+
bool command_map_is_space(char c) {
56+
return c == ' ' || c == '\t';
57+
}
6658

6759
// Only escape eol on odd number of escape characters. We know that
6860
// there can't be any characters in between, so this should work for
@@ -131,15 +123,15 @@ parse_command_name(const char* first, const char* last, char* dest_first, char*
131123
// the code below for both cases.
132124
parse_command_type
133125
parse_command(target_type target, const char* first, const char* last) {
134-
first = std::find_if(first, last, std::not1(command_map_is_space()));
126+
first = std::find_if(first, last, [&](char c) { return !command_map_is_space(c); });
135127

136128
if (first == last || *first == '#')
137129
return std::make_pair(torrent::Object(), first);
138130

139131
char key[128];
140132

141133
first = parse_command_name(first, last, key, key + 128);
142-
first = std::find_if(first, last, std::not1(command_map_is_space()));
134+
first = std::find_if(first, last, [&](char c) { return !command_map_is_space(c); });
143135

144136
if (first == last || *first != '=')
145137
throw torrent::input_error("Could not find '=' in command '" + std::string(key) + "'.");
@@ -150,7 +142,7 @@ parse_command(target_type target, const char* first, const char* last) {
150142
// Find the last character that is part of this command, skipping
151143
// the whitespace at the end. This ensures us that the caller
152144
// doesn't need to do this nor check for junk at the end.
153-
first = std::find_if(first, last, std::not1(command_map_is_space()));
145+
first = std::find_if(first, last, [&](char c) { return !command_map_is_space(c); });
154146

155147
if (first != last) {
156148
if (*first != '\n' && *first != ';' && *first != '\0')

src/rpc/scgi.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ SCgi::event_read() {
142142
utils::SocketFd fd;
143143

144144
while ((fd = get_fd().accept(&sa)).is_valid()) {
145-
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fun_ref(&SCgiTask::is_available));
145+
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fn(&SCgiTask::is_available));
146146

147147
if (task == m_task + max_tasks) {
148148
// Ergh... just closing for now.

0 commit comments

Comments
 (0)