Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace some std::find by std::ranges::find #416

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,26 @@
"release"
]
},
{
"name": "clang-base",
"environment": {
"COMPILER_CXX_FLAGS": "$env{COMPILER_C_FLAGS} -stdlib=libc++"
},
"inherits": "unix-sanitizer",
"hidden": true
},
mgovers marked this conversation as resolved.
Show resolved Hide resolved
{
"name": "clang-debug",
"inherits": [
"debug",
"unix-sanitizer"
"clang-base"
]
},
{
"name": "clang-release",
"inherits": [
"release",
"unix-sanitizer"
"clang-base"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced_documentation/build-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You can define the environment variable `CXX` to for example `clang++` to specif

**macOS**

* Clang >= 14.0
* Clang >= 14.0.3
* Latest release tested in CI

### Build System for CMake Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ class DatasetHandler {
Buffer const& get_buffer(Idx i) const { return buffers_[i]; }

Idx find_component(std::string_view component, bool required = false) const {
auto const found = std::find_if(dataset_info_.component_info.cbegin(), dataset_info_.component_info.cend(),
[component](ComponentInfo const& x) { return x.component->name == component; });
auto const found = std::ranges::find_if(dataset_info_.component_info, [component](ComponentInfo const& x) {
return x.component->name == component;
});
if (found == dataset_info_.component_info.cend()) {
if (required) {
using namespace std::string_literals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ class Deserializer {

static Idx find_key_from_map(msgpack::object const& map, std::string_view key) {
auto const kv_map = map.as<MapSpan>();
auto const found =
std::find_if(kv_map.begin(), kv_map.end(), [key](auto const& x) { return key_to_string(x) == key; });
auto const found = std::ranges::find_if(kv_map, [key](auto const& x) { return key_to_string(x) == key; });
if (found == kv_map.end()) {
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Fault final : public Base {

constexpr auto supported = std::array{three_phase, single_phase_to_ground, two_phase, two_phase_to_ground};

if (std::find(cbegin(supported), cend(supported), fault_type_) == cend(supported)) {
if (std::ranges::find(supported, fault_type_) == cend(supported)) {
throw InvalidShortCircuitType(fault_type_);
}

Expand Down Expand Up @@ -184,7 +184,7 @@ class Fault final : public Base {
using enum FaultPhase;

auto const check_supported = [&](auto const& iterable) {
if (std::find(cbegin(iterable), cend(iterable), fault_phase_) == cend(iterable)) {
if (std::ranges::find(iterable, fault_phase_) == cend(iterable)) {
throw InvalidShortCircuitPhases(fault_type_, fault_phase_);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ class SparseGroupedIdxVector {
auto element_size() const { return indptr_.back(); }
auto get_group(Idx element) const -> Idx {
assert(element < element_size());
return std::distance(std::begin(indptr_), std::upper_bound(std::begin(indptr_), std::end(indptr_), element)) -
1;
return std::distance(std::begin(indptr_), std::ranges::upper_bound(indptr_, element)) - 1;
}

SparseGroupedIdxVector() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
static constexpr size_t n_types = sizeof...(C);

static size_t find_index(std::string const& name) {
auto const found = std::find_if(component_index_map.cbegin(), component_index_map.cend(),
[&name](auto x) { return x == name; });
auto const found = std::ranges::find_if(component_index_map, [&name](auto x) { return x == name; });
assert(found != component_index_map.cend());
return found->index;
}
Expand Down