replace various find_if calls

C++11 has shorter equivalents.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev
2025-06-16 18:20:51 -07:00
committed by Jari Sundell
parent 47089bce70
commit f0517e2748
7 changed files with 11 additions and 13 deletions
+3 -4
View File
@@ -362,8 +362,7 @@ f_multicall(core::Download* download, const torrent::Object::list_type& args) {
for (torrent::FileList::const_iterator itr = download->file_list()->begin(), last = download->file_list()->end(); itr != last; itr++) {
if (use_regex &&
std::find_if(regex_list.begin(), regex_list.end(),
std::bind(&rak::regex::operator(), std::placeholders::_1, (*itr)->path()->as_string())) == regex_list.end())
std::none_of(regex_list.begin(), regex_list.end(), [itr](const auto& r) { return r((*itr)->path()->as_string()); }))
continue;
torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list();
@@ -557,7 +556,7 @@ d_list_push_back_unique(core::Download* download, const torrent::Object& rawArgs
const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs;
torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list();
if (std::find_if(list.begin(), list.end(), [args](const torrent::Object& obj) { return torrent::object_equal(obj, args); }) == list.end())
if (std::none_of(list.begin(), list.end(), [args](const torrent::Object& obj) { return torrent::object_equal(obj, args); }))
list.push_back(rawArgs);
return torrent::Object();
@@ -568,7 +567,7 @@ d_list_has(core::Download* download, const torrent::Object& rawArgs, const char*
const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs;
torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list();
return (int64_t)(std::find_if(list.begin(), list.end(), [args](const torrent::Object& obj) { return torrent::object_equal(obj, args); }) != list.end());
return (int64_t)(std::any_of(list.begin(), list.end(), [args](const auto& obj) { return torrent::object_equal(obj, args); }));
}
torrent::Object
+1 -2
View File
@@ -180,8 +180,7 @@ apply_cg_insert(const std::string& arg) {
if (rpc::parse_whole_value_nothrow(arg.c_str(), &dummy))
throw torrent::input_error("Cannot use a value string as choke group name.");
if (arg.empty() ||
std::find_if(cg_list_hack.begin(), cg_list_hack.end(), [&arg](torrent::choke_group* cg) { return arg == cg->name(); }) != cg_list_hack.end())
if (arg.empty() || std::any_of(cg_list_hack.begin(), cg_list_hack.end(), [&arg](auto cg) { return arg == cg->name(); }))
throw torrent::input_error("Duplicate name for choke group.");
cg_list_hack.push_back(new torrent::choke_group());
+1 -1
View File
@@ -347,7 +347,7 @@ View::clear_filter_on() {
inline void
View::insert_visible(Download* d) {
iterator itr = std::find_if(begin_visible(), end_visible(), [&d, this](Download* d2) { return view_downloads_compare(m_sortNew)(d, d2); });
auto itr = std::find_if(begin_visible(), end_visible(), [this, d](auto d2) { return view_downloads_compare(m_sortNew)(d, d2); });
m_size++;
m_focus += (m_focus >= position(itr));
+3 -3
View File
@@ -119,9 +119,9 @@ WindowHttpQueue::receive_insert(torrent::net::HttpGet http_get) {
void
WindowHttpQueue::receive_erase(torrent::net::HttpGet http_get) {
Container::iterator itr = std::find_if(m_container.begin(),
m_container.end(),
[http_get](Node& n) { return http_get == n.m_http; });
auto itr = std::find_if(m_container.begin(),
m_container.end(),
[http_get](auto& n) { return http_get == n.m_http; });
if (itr == m_container.end())
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
+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, [&options](char* c) { return std::strcmp(c, options) == 0; }) != argv + argc;
return std::any_of(argv, argv + argc, [&options](char* c) { return std::strcmp(c, options) == 0; });
}
std::string
+1 -1
View File
@@ -241,7 +241,7 @@ object_storage::set_multi_key_obj(const torrent::raw_string& key, const std::str
if (r_itr == m_rlookup.end())
r_itr = m_rlookup.insert(std::make_pair(cmd_key, rlookup_type::mapped_type())).first;
if (std::find_if(r_itr->second.begin(), r_itr->second.end(), [key](value_type* type) { return key == type->first; }) == r_itr->second.end())
if (std::none_of(r_itr->second.begin(), r_itr->second.end(), [key](auto type) { return key == type->first; }))
r_itr->second.push_back(&*itr);
}
+1 -1
View File
@@ -57,7 +57,7 @@ parse_option_flag(const std::string& option, parse_option_flag_type ftor) {
if (first == next)
throw torrent::input_error(option);
if (std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); }) != last)
if (std::any_of(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); }))
throw torrent::input_error(option);
return ftor(std::string(first, next));