replace for_each with range loops

No advantage over the latter, which is simpler.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev
2025-06-18 17:50:05 -07:00
committed by Jari Sundell
parent 8b663dd169
commit 84c0d516ef
10 changed files with 43 additions and 43 deletions
+2 -3
View File
@@ -286,9 +286,8 @@ DownloadFactory::receive_success() {
if (torrent::log_groups[torrent::LOG_TORRENT_DEBUG].valid())
log_created(download, rtorrent);
std::for_each(m_commands.begin(), m_commands.end(), [&download](const std::string& cmd) {
rpc::parse_command_multiple_std(cmd, rpc::make_target(download));
});
for (const auto& command : m_commands)
rpc::parse_command_multiple_std(command, rpc::make_target(download));
if (m_manager->download_list()->find(infohash) == m_manager->download_list()->end())
throw torrent::input_error("The newly created download was removed.");
+6 -3
View File
@@ -167,8 +167,10 @@ 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(), [&download](View* v) { v->insert(download); });
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->filter_download(download); });
for (auto v : *control->view_manager())
v->insert(download);
for (auto v : *control->view_manager())
v->filter_download(download);
DL_TRIGGER_EVENT(*itr, "event.download.inserted");
@@ -201,7 +203,8 @@ 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(), [itr](View* v) { v->erase(*itr); });
for (auto v : *control->view_manager())
v->erase(*itr);
torrent::download_remove(*(*itr)->download());
delete *itr;
+4 -2
View File
@@ -142,9 +142,11 @@ Manager::cleanup() {
void
Manager::shutdown(bool force) {
if (!force)
std::for_each(m_download_list->begin(), m_download_list->end(), [this](Download* d) { m_download_list->pause_default(d); });
for (auto d : *m_download_list)
m_download_list->pause_default(d);
else
std::for_each(m_download_list->begin(), m_download_list->end(), [this](Download* d) { m_download_list->close_quick(d); });
for (auto d : *m_download_list)
m_download_list->close_quick(d);
}
void
+2 -1
View File
@@ -18,7 +18,8 @@ namespace core {
void
ViewManager::clear() {
std::for_each(begin(), end(), [](View* v) { delete v; });
for (auto v : *this)
delete v;
base_type::clear();
}
+2 -1
View File
@@ -45,7 +45,8 @@ namespace display {
void
TextElementList::clear() {
std::for_each(begin(), end(), [](TextElement* t) { delete t; });
for (auto t : *this)
delete t;
base_type::clear();
}
+2 -1
View File
@@ -16,7 +16,8 @@ WindowText::WindowText(rpc::target_type target, extent_type margin) :
void
WindowText::clear() {
std::for_each(begin(), end(), [](TextElement* text) { delete text; });
for (auto t : *this)
delete t;
base_type::clear();
delete m_errorHandler;
+8 -12
View File
@@ -68,17 +68,6 @@ PathInput::pressed(int key) {
return true;
}
struct _transform_filename {
void operator () (utils::directory_entry& entry) {
#ifdef __sun__
if (entry.s_type & S_IFDIR)
#else
if (entry.s_type == DT_DIR)
#endif
entry.s_name += '/';
}
};
void
PathInput::receive_do_complete() {
lt_log_print(torrent::LOG_UI_EVENTS, "path_input: received completion");
@@ -93,7 +82,14 @@ PathInput::receive_do_complete() {
return;
}
std::for_each(dir.begin(), dir.end(), _transform_filename());
for (auto& entry : dir) {
#ifdef __sun__
if (entry.s_type & S_IFDIR)
#else
if (entry.s_type == DT_DIR)
#endif
entry.s_name += '/';
}
range_type r = find_incomplete(dir, str().substr(dirEnd, get_pos()));
+2 -1
View File
@@ -14,7 +14,8 @@
namespace rpc {
CommandScheduler::~CommandScheduler() {
std::for_each(begin(), end(), [](CommandSchedulerItem* item) { delete item; });
for (auto item : *this)
delete item;
}
CommandScheduler::iterator
+2 -1
View File
@@ -63,7 +63,8 @@ ElementPeerList::ElementPeerList(core::Download* d) :
torrent::ConnectionList* connection_list = m_download->download()->connection_list();
std::for_each(connection_list->begin(), connection_list->end(), [&](torrent::Peer* peer) { m_list.push_back(peer); });
for (auto peer : *connection_list)
m_list.push_back(peer);
m_peer_connected = connection_list->signal_connected().insert(connection_list->signal_connected().end(),
std::bind(&ElementPeerList::receive_peer_connected, this, std::placeholders::_1));