diff --git a/rtorrent/rak/priority_queue.h b/rtorrent/rak/priority_queue.h index 74be58fc..545b887c 100644 --- a/rtorrent/rak/priority_queue.h +++ b/rtorrent/rak/priority_queue.h @@ -85,7 +85,7 @@ class priority_queue : public std::vector { template iterator find(const Key& key) { - return std::find_if(begin(), end(), std::bind2nd(m_equal, key)); + return std::find_if(begin(), end(), [&](auto& value) { return m_equal(value, key); }); } template @@ -114,36 +114,6 @@ class priority_queue : public std::vector { Equal m_equal; }; -// Iterate while the top node has higher priority, as 'Compare' -// returns false. -template -class queue_pop_iterator - : public std::iterator { -public: - typedef Queue container_type; - - queue_pop_iterator() : m_queue(NULL) {} - queue_pop_iterator(Queue* q, Compare c) : m_queue(q), m_compare(c) {} - - queue_pop_iterator& operator ++ () { m_queue->pop(); return *this; } - queue_pop_iterator& operator ++ (int) { m_queue->pop(); return *this; } - - typename container_type::const_reference operator * () { return m_queue->top(); } - - bool operator != (const queue_pop_iterator& itr) { return !m_queue->empty() && !m_compare(m_queue->top()); } - bool operator == (const queue_pop_iterator& itr) { return m_queue->empty() || m_compare(m_queue->top()); } - -private: - Queue* m_queue; - Compare m_compare; -}; - -template -inline queue_pop_iterator -queue_popper(Queue& queue, Compare comp) { - return queue_pop_iterator(&queue, comp); -} - } #endif diff --git a/rtorrent/rak/regex.h b/rtorrent/rak/regex.h index 2d074161..8d89b14c 100644 --- a/rtorrent/rak/regex.h +++ b/rtorrent/rak/regex.h @@ -50,7 +50,7 @@ namespace rak { -class regex : public std::unary_function { +class regex : public std::function { public: regex() {} regex(const std::string& p) : m_pattern(p) {} diff --git a/rtorrent/src/command_events.cc b/rtorrent/src/command_events.cc index a60f1e63..cd12c6dd 100644 --- a/rtorrent/src/command_events.cc +++ b/rtorrent/src/command_events.cc @@ -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); diff --git a/rtorrent/src/command_local.cc b/rtorrent/src/command_local.cc index 553368af..935c8372 100644 --- a/rtorrent/src/command_local.cc +++ b/rtorrent/src/command_local.cc @@ -195,7 +195,7 @@ file_print_list(torrent::Object::list_const_iterator first, torrent::Object::lis fprintf(output, (const char*)" %s" + !(flags & file_print_use_space), first->as_string().c_str()); break; case torrent::Object::TYPE_VALUE: - fprintf(output, (const char*)" %lli" + !(flags & file_print_use_space), first->as_value()); + fprintf(output, (const char*)" %li" + !(flags & file_print_use_space), first->as_value()); break; case torrent::Object::TYPE_LIST: file_print_list(first->as_list().begin(), first->as_list().end(), output, 0); diff --git a/rtorrent/src/command_tracker.cc b/rtorrent/src/command_tracker.cc index e0694761..ac5b3f48 100644 --- a/rtorrent/src/command_tracker.cc +++ b/rtorrent/src/command_tracker.cc @@ -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); diff --git a/rtorrent/src/core/curl_stack.cc b/rtorrent/src/core/curl_stack.cc index 7ada91dc..7a8eb0cf 100644 --- a/rtorrent/src/core/curl_stack.cc +++ b/rtorrent/src/core/curl_stack.cc @@ -241,7 +241,7 @@ CurlStack::remove_get(CurlGet* get) { throw torrent::internal_error("Error calling curl_multi_remove_handle."); if (m_active == m_maxActive && - (itr = std::find_if(begin(), end(), std::not1(std::mem_fun(&CurlGet::is_active)))) != end()) { + (itr = std::find_if(begin(), end(), [](CurlGet* get) { return !get->is_active(); })) != end()) { (*itr)->set_active(true); if (curl_multi_add_handle((CURLM*)m_handle, (*itr)->handle()) > 0) diff --git a/rtorrent/src/core/download_list.cc b/rtorrent/src/core/download_list.cc index 1b545375..a10c7782 100644 --- a/rtorrent/src/core/download_list.cc +++ b/rtorrent/src/core/download_list.cc @@ -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."); @@ -181,13 +181,13 @@ DownloadList::insert(Download* download) { lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Inserting download."); try { - (*itr)->data()->slot_initial_hash() = std::bind(&DownloadList::hash_done, this, download); - (*itr)->data()->slot_download_done() = std::bind(&DownloadList::received_finished, this, download); + (*itr)->data()->slot_initial_hash() = [this, download]() { hash_done(download); }; + (*itr)->data()->slot_download_done() = [this, download]() { received_finished(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; diff --git a/rtorrent/src/core/download_store.cc b/rtorrent/src/core/download_store.cc index b3251416..2428374e 100644 --- a/rtorrent/src/core/download_store.cc +++ b/rtorrent/src/core/download_store.cc @@ -207,7 +207,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(¬_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; } diff --git a/rtorrent/src/core/http_queue.cc b/rtorrent/src/core/http_queue.cc index d83cddb5..eee1deca 100644 --- a/rtorrent/src/core/http_queue.cc +++ b/rtorrent/src/core/http_queue.cc @@ -47,7 +47,7 @@ namespace core { HttpQueue::iterator HttpQueue::insert(const std::string& url, std::iostream* s) { - std::auto_ptr h(m_slot_factory()); + std::unique_ptr h(m_slot_factory()); h->set_url(url); h->set_stream(s); diff --git a/rtorrent/src/core/manager.cc b/rtorrent/src/core/manager.cc index 534ad007..2fd0e875 100644 --- a/rtorrent/src/core/manager.cc +++ b/rtorrent/src/core/manager.cc @@ -177,9 +177,9 @@ Manager::cleanup() { void Manager::shutdown(bool force) { if (!force) - std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::pause_default), m_downloadList)); + std::for_each(m_downloadList->begin(), m_downloadList->end(), [this](Download* d) { m_downloadList->pause_default(d); }); else - std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::close_quick), m_downloadList)); + std::for_each(m_downloadList->begin(), m_downloadList->end(), [this](Download* d) { m_downloadList->close_quick(d); }); } void @@ -431,7 +431,7 @@ path_expand(std::vector* 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 @@ -465,7 +465,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. diff --git a/rtorrent/src/core/view.cc b/rtorrent/src/core/view.cc index 09937e30..fe42af61 100644 --- a/rtorrent/src/core/view.cc +++ b/rtorrent/src/core/view.cc @@ -52,7 +52,7 @@ namespace core { // Also add focus thingie here? -struct view_downloads_compare : std::binary_function { +struct view_downloads_compare : std::function { view_downloads_compare(const torrent::Object& cmd) : m_command(cmd) {} bool operator () (Download* d1, Download* d2) const { @@ -86,7 +86,7 @@ struct view_downloads_compare : std::binary_function const torrent::Object& m_command; }; -struct view_downloads_filter : std::unary_function { +struct view_downloads_filter : std::function { view_downloads_filter(const torrent::Object& cmd, const torrent::Object& cmd2) : m_command(cmd), m_command2(cmd2) {} bool operator () (Download* d1) const { diff --git a/rtorrent/src/display/utils.cc b/rtorrent/src/display/utils.cc index 93011e82..cd3f0853 100644 --- a/rtorrent/src/display/utils.cc +++ b/rtorrent/src/display/utils.cc @@ -198,7 +198,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)); diff --git a/rtorrent/src/display/window_download_chunks_seen.cc b/rtorrent/src/display/window_download_chunks_seen.cc index e445320a..92d6ea6e 100644 --- a/rtorrent/src/display/window_download_chunks_seen.cc +++ b/rtorrent/src/display/window_download_chunks_seen.cc @@ -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; diff --git a/rtorrent/src/input/manager.cc b/rtorrent/src/input/manager.cc index 73637d1f..d94d4d89 100644 --- a/rtorrent/src/input/manager.cc +++ b/rtorrent/src/input/manager.cc @@ -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); }); } } diff --git a/rtorrent/src/option_parser.cc b/rtorrent/src/option_parser.cc index f07777f2..8164ca63 100644 --- a/rtorrent/src/option_parser.cc +++ b/rtorrent/src/option_parser.cc @@ -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 diff --git a/rtorrent/src/rpc/command_map.h b/rtorrent/src/rpc/command_map.h index 4742bddd..4b9b484e 100644 --- a/rtorrent/src/rpc/command_map.h +++ b/rtorrent/src/rpc/command_map.h @@ -37,6 +37,7 @@ #ifndef RTORRENT_RPC_COMMAND_MAP_H #define RTORRENT_RPC_COMMAND_MAP_H +#include #include #include #include @@ -46,7 +47,7 @@ namespace rpc { -struct command_map_comp : public std::binary_function { +struct command_map_comp : public std::function { bool operator () (const char* arg1, const char* arg2) const { return std::strcmp(arg1, arg2) < 0; } }; diff --git a/rtorrent/src/rpc/parse_commands.cc b/rtorrent/src/rpc/parse_commands.cc index 7ba53c87..baaa6b8b 100644 --- a/rtorrent/src/rpc/parse_commands.cc +++ b/rtorrent/src/rpc/parse_commands.cc @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -52,17 +51,13 @@ CommandMap commands; XmlRpc xmlrpc; ExecFile execFile; -struct command_map_is_space : std::unary_function { - 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 { - 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 +126,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 +134,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 +145,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++; diff --git a/rtorrent/src/rpc/scgi.cc b/rtorrent/src/rpc/scgi.cc index 0579d5f5..4a476dcd 100644 --- a/rtorrent/src/rpc/scgi.cc +++ b/rtorrent/src/rpc/scgi.cc @@ -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.