From 2aaf721897938ac62c146354865ee1a671647619 Mon Sep 17 00:00:00 2001 From: Alexander Taepper Date: Wed, 8 Jan 2025 09:22:21 +0100 Subject: [PATCH] fixup! refactor: replace usages of std::find, std::find_if and std::reverse with the respective functions using C++20 ranges --- include/silo/common/cons_list.h | 1 + src/config/config_specification.cpp | 16 +++++++--------- src/silo/common/lineage_tree.cpp | 3 +-- src/silo/config/config_repository.cpp | 8 ++++---- src/silo/config/database_config.cpp | 7 +++---- src/silo/query_engine/actions/tuple.cpp | 7 +++---- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/include/silo/common/cons_list.h b/include/silo/common/cons_list.h index 1c24891fa..14bc31de0 100644 --- a/include/silo/common/cons_list.h +++ b/include/silo/common/cons_list.h @@ -4,6 +4,7 @@ //! (no reference counting). This is meant to be used with recursive //! algorithms to maintain a path back up. +#include #include #include #include diff --git a/src/config/config_specification.cpp b/src/config/config_specification.cpp index 1533239cc..6ea2d582c 100644 --- a/src/config/config_specification.cpp +++ b/src/config/config_specification.cpp @@ -34,12 +34,10 @@ namespace silo::config { std::optional ConfigSpecification:: getAttributeSpecificationFromAmbiguousKey(const AmbiguousConfigKeyPath& key) const { - auto maybe_result = std::ranges::find_if( - attribute_specifications, - [&](const auto& attribute_spec) { + auto maybe_result = + std::ranges::find_if(attribute_specifications, [&](const auto& attribute_spec) { return AmbiguousConfigKeyPath::from(attribute_spec.key) == key; - } - ); + }); if (maybe_result == attribute_specifications.end()) { return std::nullopt; } @@ -49,10 +47,10 @@ std::optional ConfigSpecification:: std::optional ConfigSpecification::getAttributeSpecification( const ConfigKeyPath& key ) const { - auto maybe_result = std::ranges::find_if( - attribute_specifications, - [&](const auto& attribute_spec) { return attribute_spec.key == key; } - ); + auto maybe_result = + std::ranges::find_if(attribute_specifications, [&](const auto& attribute_spec) { + return attribute_spec.key == key; + }); if (maybe_result == attribute_specifications.end()) { return std::nullopt; } diff --git a/src/silo/common/lineage_tree.cpp b/src/silo/common/lineage_tree.cpp index ed4625557..20fba853d 100644 --- a/src/silo/common/lineage_tree.cpp +++ b/src/silo/common/lineage_tree.cpp @@ -102,8 +102,7 @@ std::optional> Graph::getCycle() const { // We need to remove leading vertices up until the cycle SILO_ASSERT_GE(witness_lasso.value().size(), 2UL); const Idx cycle_node = witness_lasso.value().back(); - auto cycle_node_first_occurrence = - std::ranges::find(witness_lasso.value(), cycle_node); + auto cycle_node_first_occurrence = std::ranges::find(witness_lasso.value(), cycle_node); SILO_ASSERT(cycle_node_first_occurrence < witness_lasso.value().end()); witness_lasso.value().erase(witness_lasso.value().begin(), cycle_node_first_occurrence); return witness_lasso; diff --git a/src/silo/config/config_repository.cpp b/src/silo/config/config_repository.cpp index bd17e3c53..e6f85ea18 100644 --- a/src/silo/config/config_repository.cpp +++ b/src/silo/config/config_repository.cpp @@ -80,10 +80,10 @@ void validatePartitionBy(const DatabaseConfig& config) { const std::string partition_by = config.schema.partition_by.value(); - const auto& partition_by_metadata = std::ranges::find_if( - config.schema.metadata, - [&](const DatabaseMetadata& metadata) { return metadata.name == partition_by; } - ); + const auto& partition_by_metadata = + std::ranges::find_if(config.schema.metadata, [&](const DatabaseMetadata& metadata) { + return metadata.name == partition_by; + }); if (partition_by_metadata == config.schema.metadata.end()) { throw ConfigException("partitionBy '" + partition_by + "' is not in metadata"); } diff --git a/src/silo/config/database_config.cpp b/src/silo/config/database_config.cpp index a4c95f3a7..06026aa1f 100644 --- a/src/silo/config/database_config.cpp +++ b/src/silo/config/database_config.cpp @@ -188,10 +188,9 @@ ColumnType DatabaseMetadata::getColumnType() const { } std::optional DatabaseConfig::getMetadata(const std::string& name) const { - auto element = - std::ranges::find_if(schema.metadata, [&name](const auto& metadata) { - return metadata.name == name; - }); + auto element = std::ranges::find_if(schema.metadata, [&name](const auto& metadata) { + return metadata.name == name; + }); if (element == std::end(schema.metadata)) { return std::nullopt; } diff --git a/src/silo/query_engine/actions/tuple.cpp b/src/silo/query_engine/actions/tuple.cpp index 238998d21..8b78842b1 100644 --- a/src/silo/query_engine/actions/tuple.cpp +++ b/src/silo/query_engine/actions/tuple.cpp @@ -316,10 +316,9 @@ std::vector Tuple::getCompareFields( tuple_field_comparators.resize(order_by_fields.size()); size_t offset = 0; for (const auto& metadata : columns_metadata) { - auto element = std::ranges::find_if( - order_by_fields, - [&](const auto& order_by_field) { return metadata.name == order_by_field.name; } - ); + auto element = std::ranges::find_if(order_by_fields, [&](const auto& order_by_field) { + return metadata.name == order_by_field.name; + }); if (element != order_by_fields.end()) { const size_t index = std::distance(order_by_fields.begin(), element); tuple_field_comparators[index] =