Merge pull request #36348 from rschu1ze/erase_if3

Replace remove-erase idiom by C++20 erase()/erase_if()
This commit is contained in:
alesapin 2022-04-25 23:34:18 +02:00 committed by GitHub
commit 92296484e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 33 additions and 53 deletions

View File

@ -296,11 +296,7 @@ PoolWithFailoverBase<TNestedPool>::getMany(
"All connection tries failed. Log: \n\n" + fail_messages + "\n", "All connection tries failed. Log: \n\n" + fail_messages + "\n",
DB::ErrorCodes::ALL_CONNECTION_TRIES_FAILED); DB::ErrorCodes::ALL_CONNECTION_TRIES_FAILED);
try_results.erase( std::erase_if(try_results, [](const TryResult & r) { return r.entry.isNull() || !r.is_usable; });
std::remove_if(
try_results.begin(), try_results.end(),
[](const TryResult & r) { return r.entry.isNull() || !r.is_usable; }),
try_results.end());
/// Sort so that preferred items are near the beginning. /// Sort so that preferred items are near the beginning.
std::stable_sort( std::stable_sort(

View File

@ -59,23 +59,20 @@ namespace Format
{ {
size_t i = 0; size_t i = 0;
bool should_delete = true; bool should_delete = true;
str.erase( std::erase_if(
std::remove_if( str,
str.begin(), [&i, &should_delete, &str](char)
str.end(), {
[&i, &should_delete, &str](char) bool is_double_brace = (str[i] == '{' && str[i + 1] == '{') || (str[i] == '}' && str[i + 1] == '}');
++i;
if (is_double_brace && should_delete)
{ {
bool is_double_brace = (str[i] == '{' && str[i + 1] == '{') || (str[i] == '}' && str[i + 1] == '}'); should_delete = false;
++i; return true;
if (is_double_brace && should_delete) }
{ should_delete = true;
should_delete = false; return false;
return true; });
}
should_delete = true;
return false;
}),
str.end());
}; };
index_positions.emplace_back(); index_positions.emplace_back();

View File

@ -152,10 +152,7 @@ ASTPtr DatabaseMySQL::getCreateTableQueryImpl(const String & table_name, Context
storage_engine_arguments->children.insert(storage_engine_arguments->children.begin() + 2, mysql_table_name); storage_engine_arguments->children.insert(storage_engine_arguments->children.begin() + 2, mysql_table_name);
/// Unset settings /// Unset settings
storage_children.erase( std::erase_if(storage_children, [&](const ASTPtr & element) { return element.get() == ast_storage->settings; });
std::remove_if(storage_children.begin(), storage_children.end(),
[&](const ASTPtr & element) { return element.get() == ast_storage->settings; }),
storage_children.end());
ast_storage->settings = nullptr; ast_storage->settings = nullptr;
} }
auto create_table_query = DB::getCreateQueryFromStorage(storage, table_storage_define, true, auto create_table_query = DB::getCreateQueryFromStorage(storage, table_storage_define, true,

View File

@ -219,10 +219,10 @@ private:
auto current_box = Box(Point(current_min_x, current_min_y), Point(current_max_x, current_max_y)); auto current_box = Box(Point(current_min_x, current_min_y), Point(current_max_x, current_max_y));
Polygon tmp_poly; Polygon tmp_poly;
bg::convert(current_box, tmp_poly); bg::convert(current_box, tmp_poly);
possible_ids.erase(std::remove_if(possible_ids.begin(), possible_ids.end(), [&](const auto id) std::erase_if(possible_ids, [&](const auto id)
{ {
return !bg::intersects(current_box, polygons[id]); return !bg::intersects(current_box, polygons[id]);
}), possible_ids.end()); });
int covered = 0; int covered = 0;
#ifndef __clang_analyzer__ /// Triggers a warning in boost geometry. #ifndef __clang_analyzer__ /// Triggers a warning in boost geometry.
auto it = std::find_if(possible_ids.begin(), possible_ids.end(), [&](const auto id) auto it = std::find_if(possible_ids.begin(), possible_ids.end(), [&](const auto id)

View File

@ -435,8 +435,7 @@ void ActionsDAG::removeUnusedActions(bool allow_remove_inputs, bool allow_consta
} }
nodes.remove_if([&](const Node & node) { return !visited_nodes.contains(&node); }); nodes.remove_if([&](const Node & node) { return !visited_nodes.contains(&node); });
auto it = std::remove_if(inputs.begin(), inputs.end(), [&](const Node * node) { return !visited_nodes.contains(node); }); std::erase_if(inputs, [&](const Node * node) { return !visited_nodes.contains(node); });
inputs.erase(it, inputs.end());
} }
static ColumnWithTypeAndName executeActionForHeader(const ActionsDAG::Node * node, ColumnsWithTypeAndName arguments) static ColumnWithTypeAndName executeActionForHeader(const ActionsDAG::Node * node, ColumnsWithTypeAndName arguments)

View File

@ -221,7 +221,7 @@ DDLTaskPtr DDLWorker::initAndCheckTask(const String & entry_name, String & out_r
static void filterAndSortQueueNodes(Strings & all_nodes) static void filterAndSortQueueNodes(Strings & all_nodes)
{ {
all_nodes.erase(std::remove_if(all_nodes.begin(), all_nodes.end(), [] (const String & s) { return !startsWith(s, "query-"); }), all_nodes.end()); std::erase_if(all_nodes, [] (const String & s) { return !startsWith(s, "query-"); });
::sort(all_nodes.begin(), all_nodes.end()); ::sort(all_nodes.begin(), all_nodes.end());
} }

View File

@ -274,9 +274,9 @@ std::string buildTaggedRegex(std::string regexp_str)
std::vector<std::string> tags; std::vector<std::string> tags;
splitInto<';'>(tags, regexp_str); splitInto<';'>(tags, regexp_str);
/* remove empthy elements */ /* remove empty elements */
using namespace std::string_literals; using namespace std::string_literals;
tags.erase(std::remove(tags.begin(), tags.end(), ""s), tags.end()); std::erase(tags, ""s);
if (tags[0].find('=') == tags[0].npos) if (tags[0].find('=') == tags[0].npos)
{ {
if (tags.size() == 1) /* only name */ if (tags.size() == 1) /* only name */

View File

@ -3676,10 +3676,10 @@ void MergeTreeData::movePartitionToDisk(const ASTPtr & partition, const String &
parts = getVisibleDataPartsVectorInPartition(local_context, partition_id); parts = getVisibleDataPartsVectorInPartition(local_context, partition_id);
auto disk = getStoragePolicy()->getDiskByName(name); auto disk = getStoragePolicy()->getDiskByName(name);
parts.erase(std::remove_if(parts.begin(), parts.end(), [&](auto part_ptr) std::erase_if(parts, [&](auto part_ptr)
{ {
return part_ptr->volume->getDisk()->getName() == disk->getName(); return part_ptr->volume->getDisk()->getName() == disk->getName();
}), parts.end()); });
if (parts.empty()) if (parts.empty())
{ {
@ -3724,7 +3724,7 @@ void MergeTreeData::movePartitionToVolume(const ASTPtr & partition, const String
if (parts.empty()) if (parts.empty())
throw Exception("Nothing to move (сheck that the partition exists).", ErrorCodes::NO_SUCH_DATA_PART); throw Exception("Nothing to move (сheck that the partition exists).", ErrorCodes::NO_SUCH_DATA_PART);
parts.erase(std::remove_if(parts.begin(), parts.end(), [&](auto part_ptr) std::erase_if(parts, [&](auto part_ptr)
{ {
for (const auto & disk : volume->getDisks()) for (const auto & disk : volume->getDisks())
{ {
@ -3734,7 +3734,7 @@ void MergeTreeData::movePartitionToVolume(const ASTPtr & partition, const String
} }
} }
return false; return false;
}), parts.end()); });
if (parts.empty()) if (parts.empty())
{ {
@ -4220,8 +4220,7 @@ void MergeTreeData::filterVisibleDataParts(DataPartsVector & maybe_visible_parts
return !part->version.isVisible(snapshot_version, current_tid); return !part->version.isVisible(snapshot_version, current_tid);
}; };
auto new_end_it = std::remove_if(maybe_visible_parts.begin(), maybe_visible_parts.end(), need_remove_pred); std::erase_if(maybe_visible_parts, need_remove_pred);
maybe_visible_parts.erase(new_end_it, maybe_visible_parts.end());
[[maybe_unused]] size_t visible_size = maybe_visible_parts.size(); [[maybe_unused]] size_t visible_size = maybe_visible_parts.size();
@ -6515,15 +6514,11 @@ ReservationPtr MergeTreeData::balancedReservation(
} }
// Remove irrelevant parts. // Remove irrelevant parts.
covered_parts.erase( std::erase_if(covered_parts,
std::remove_if(
covered_parts.begin(),
covered_parts.end(),
[min_bytes_to_rebalance_partition_over_jbod](const auto & part) [min_bytes_to_rebalance_partition_over_jbod](const auto & part)
{ {
return !(part->isStoredOnDisk() && part->getBytesOnDisk() >= min_bytes_to_rebalance_partition_over_jbod); return !(part->isStoredOnDisk() && part->getBytesOnDisk() >= min_bytes_to_rebalance_partition_over_jbod);
}), });
covered_parts.end());
// Include current submerging big parts which are not yet in `currently_submerging_big_parts` // Include current submerging big parts which are not yet in `currently_submerging_big_parts`
for (const auto & part : covered_parts) for (const auto & part : covered_parts)

View File

@ -176,11 +176,9 @@ SelectPartsDecision MergeTreeDataMergerMutator::selectPartsToMerge(
return active_parts_set.getContainingPart(part->info) != part->name; return active_parts_set.getContainingPart(part->info) != part->name;
}; };
auto new_end_it = std::remove_if(active_parts.begin(), active_parts.end(), remove_pred); std::erase_if(active_parts, remove_pred);
active_parts.erase(new_end_it, active_parts.end());
new_end_it = std::remove_if(outdated_parts.begin(), outdated_parts.end(), remove_pred); std::erase_if(outdated_parts, remove_pred);
outdated_parts.erase(new_end_it, outdated_parts.end());
std::merge(active_parts.begin(), active_parts.end(), std::merge(active_parts.begin(), active_parts.end(),
outdated_parts.begin(), outdated_parts.end(), outdated_parts.begin(), outdated_parts.end(),

View File

@ -611,9 +611,7 @@ int32_t ReplicatedMergeTreeQueue::pullLogsToQueue(zkutil::ZooKeeperPtr zookeeper
/// Multiple log entries that must be copied to the queue. /// Multiple log entries that must be copied to the queue.
log_entries.erase( std::erase_if(log_entries, [&min_log_entry](const String & entry) { return entry < min_log_entry; });
std::remove_if(log_entries.begin(), log_entries.end(), [&min_log_entry](const String & entry) { return entry < min_log_entry; }),
log_entries.end());
if (!log_entries.empty()) if (!log_entries.empty())
{ {

View File

@ -279,10 +279,10 @@ void StorageSystemZooKeeper::fillData(MutableColumns & res_columns, ContextPtr c
if (!prefix.empty()) if (!prefix.empty())
{ {
// Remove nodes that do not match specified prefix // Remove nodes that do not match specified prefix
nodes.erase(std::remove_if(nodes.begin(), nodes.end(), [&prefix, &path_part] (const String & node) std::erase_if(nodes, [&prefix, &path_part] (const String & node)
{ {
return (path_part + '/' + node).substr(0, prefix.size()) != prefix; return (path_part + '/' + node).substr(0, prefix.size()) != prefix;
}), nodes.end()); });
} }
std::vector<std::future<Coordination::GetResponse>> futures; std::vector<std::future<Coordination::GetResponse>> futures;