diff --git a/include/bout/hypre_interface.hxx b/include/bout/hypre_interface.hxx index 189e91d159..527a5e2ee4 100644 --- a/include/bout/hypre_interface.hxx +++ b/include/bout/hypre_interface.hxx @@ -458,9 +458,9 @@ public: Element& operator+=(BoutReal value_) { ASSERT3(finite(value_)); - auto column_position = std::find(cbegin(positions), cend(positions), column); + auto column_position = std::ranges::find(positions, column); if (column_position != cend(positions)) { - const auto i = std::distance(cbegin(positions), column_position); + const auto i = std::distance(begin(positions), column_position); value += weights[i] * value_; } addValues(value_); diff --git a/include/bout/multiostream.hxx b/include/bout/multiostream.hxx index ca3cc2d0c7..9caceb382d 100644 --- a/include/bout/multiostream.hxx +++ b/include/bout/multiostream.hxx @@ -17,7 +17,7 @@ private: public: void add(std::basic_ostream& str) { - auto pos = std::find(streams_.begin(), streams_.end(), &str); + auto pos = std::ranges::find(streams_, &str); // Already been added if (pos != streams_.end()) { @@ -28,7 +28,7 @@ public: } void remove(std::basic_ostream& str) { - auto pos = std::find(streams_.begin(), streams_.end(), &str); + auto pos = std::ranges::find(streams_, &str); if (pos != streams_.end()) { streams_.erase(pos); diff --git a/include/bout/petsc_interface.hxx b/include/bout/petsc_interface.hxx index 3ef3a2a49a..92a5519fa1 100644 --- a/include/bout/petsc_interface.hxx +++ b/include/bout/petsc_interface.hxx @@ -406,7 +406,7 @@ public: Element& operator+=(BoutReal val) { ASSERT3(std::isfinite(val)); - auto columnPosition = std::find(positions.begin(), positions.end(), petscCol); + auto columnPosition = std::ranges::find(positions, petscCol); if (columnPosition != positions.end()) { const int index = std::distance(positions.begin(), columnPosition); value += weights[index] * val; diff --git a/include/bout/solver.hxx b/include/bout/solver.hxx index 09ede6a32b..b081b8bfd0 100644 --- a/include/bout/solver.hxx +++ b/include/bout/solver.hxx @@ -514,8 +514,7 @@ protected: /// Does \p vars contain a field with \p name? template bool contains(const std::vector>& vars, const std::string& name) { - const auto in_vars = std::find(begin(vars), end(vars), name); - return in_vars != end(vars); + return std::ranges::find(vars, name, &VarStr::name) != std::ranges::end(vars); } /// Vectors of variables to evolve diff --git a/src/field/fieldgroup.cxx b/src/field/fieldgroup.cxx index f85cbb6843..f9f166fa32 100644 --- a/src/field/fieldgroup.cxx +++ b/src/field/fieldgroup.cxx @@ -1,5 +1,5 @@ - #include +#include FieldGroup operator+(const FieldGroup& lhs, const FieldGroup& rhs) { return FieldGroup(lhs) += rhs; @@ -7,16 +7,16 @@ FieldGroup operator+(const FieldGroup& lhs, const FieldGroup& rhs) { void FieldGroup::makeUnique() { // Need to sort vector before making unique - std::sort(fvec.begin(), fvec.end()); + std::ranges::sort(fvec); // Remove duplicate entries (doesn't resize vector though) - auto last = std::unique(fvec.begin(), fvec.end()); + auto fvec_dupes = std::ranges::unique(fvec); // Resizes vector to remove memory no longer required - fvec.erase(last, fvec.end()); + fvec.erase(fvec_dupes.begin(), fvec_dupes.end()); // Now do the same for the vector of Field3Ds - std::sort(f3vec.begin(), f3vec.end()); - auto last_f3 = std::unique(f3vec.begin(), f3vec.end()); - f3vec.erase(last_f3, f3vec.end()); + std::ranges::sort(f3vec); + auto f3vec_dupes = std::ranges::unique(f3vec); + f3vec.erase(f3vec_dupes.begin(), f3vec_dupes.end()); } diff --git a/src/sys/options.cxx b/src/sys/options.cxx index 85cfa7a49a..d659426d0a 100644 --- a/src/sys/options.cxx +++ b/src/sys/options.cxx @@ -760,13 +760,13 @@ struct ConvertContainer> { Container operator()(int value) { Container result(similar_to); - std::fill(std::begin(result), std::end(result), static_cast(value)); + std::ranges::fill(result, static_cast(value)); return result; } Container operator()(BoutReal value) { Container result(similar_to); - std::fill(std::begin(result), std::end(result), static_cast(value)); + std::ranges::fill(result, static_cast(value)); return result; } @@ -779,8 +779,8 @@ struct ConvertContainer> { Container result(similar_to); result.reshape(value.shape()); // Resize to shape of input - std::transform(std::begin(value), std::end(value), std::begin(result), - [](const OtherScalar& x) { return static_cast(x); }); + std::ranges::transform(value, std::begin(result), + [](const auto& x) { return static_cast(x); }); return result; } @@ -877,8 +877,8 @@ Options Options::getUnused(const std::vector& exclude_sources) cons return false; } const auto source = option.attributes.at("source").as(); - return std::find(exclude_sources.begin(), exclude_sources.end(), source) - != exclude_sources.end(); + return std::ranges::find(exclude_sources, source) + != std::ranges::end(exclude_sources); }; const auto conditionally_used = [](const Options& option) -> bool { diff --git a/tests/unit/solver/test_solverfactory.cxx b/tests/unit/solver/test_solverfactory.cxx index 577c2986fe..2168aebc4c 100644 --- a/tests/unit/solver/test_solverfactory.cxx +++ b/tests/unit/solver/test_solverfactory.cxx @@ -17,7 +17,7 @@ TEST(SolverFactoryTest, GetDefaultSolverType) { TEST(SolverFactoryTest, RegisterSolver) { auto available = SolverFactory::getInstance().listAvailable(); - auto found_fake = std::find(begin(available), end(available), "fake_solver"); + auto found_fake = std::ranges::find(available, "fake_solver"); EXPECT_NE(found_fake, end(available)); }