Skip to content

Commit

Permalink
fixup! refactor: replace usages of std::find, std::find_if and std::r…
Browse files Browse the repository at this point in the history
…everse with the respective functions using C++20 ranges
  • Loading branch information
Taepper committed Jan 8, 2025
1 parent 267053e commit 2aaf721
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions include/silo/common/cons_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! (no reference counting). This is meant to be used with recursive
//! algorithms to maintain a path back up.

#include <algorithm>
#include <functional>
#include <memory>
#include <optional>
Expand Down
16 changes: 7 additions & 9 deletions src/config/config_specification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ namespace silo::config {

std::optional<ConfigAttributeSpecification> 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;
}
Expand All @@ -49,10 +47,10 @@ std::optional<ConfigAttributeSpecification> ConfigSpecification::
std::optional<ConfigAttributeSpecification> 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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/silo/common/lineage_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ std::optional<std::vector<Idx>> 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;
Expand Down
8 changes: 4 additions & 4 deletions src/silo/config/config_repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
7 changes: 3 additions & 4 deletions src/silo/config/database_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,9 @@ ColumnType DatabaseMetadata::getColumnType() const {
}

std::optional<DatabaseMetadata> 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;
}
Expand Down
7 changes: 3 additions & 4 deletions src/silo/query_engine/actions/tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,9 @@ std::vector<Tuple::ComparatorField> 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] =
Expand Down

0 comments on commit 2aaf721

Please sign in to comment.