Simplify a few loops using std::ranges::reverse_view

Automatically detected using clang-tidy with modernize-loop-convert check.
master
Sébastien Villemot 2023-12-01 15:06:40 +01:00
parent c5cc61b110
commit c2d6ab8ee0
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 10 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <numeric> #include <numeric>
#include <ranges>
#include <regex> #include <regex>
#include <sstream> #include <sstream>
#include <string_view> #include <string_view>
@ -3485,18 +3486,18 @@ void
DynamicModel::detrendEquations() DynamicModel::detrendEquations()
{ {
// We go backwards in the list of trend_vars, to deal correctly with I(2) processes // We go backwards in the list of trend_vars, to deal correctly with I(2) processes
for (auto it = nonstationary_symbols_map.crbegin(); it != nonstationary_symbols_map.crend(); ++it) for (const auto& it : std::ranges::reverse_view(nonstationary_symbols_map))
{ {
for (auto& equation : equations) for (auto& equation : equations)
{ {
equation = dynamic_cast<BinaryOpNode*>( equation = dynamic_cast<BinaryOpNode*>(
equation->detrend(it->first, it->second.first, it->second.second)); equation->detrend(it.first, it.second.first, it.second.second));
assert(equation); assert(equation);
} }
for (auto& equation : static_only_equations) for (auto& equation : static_only_equations)
{ {
equation = dynamic_cast<BinaryOpNode*>( equation = dynamic_cast<BinaryOpNode*>(
equation->detrend(it->first, it->second.first, it->second.second)); equation->detrend(it.first, it.second.first, it.second.second));
assert(equation); assert(equation);
} }
} }

View File

@ -19,6 +19,7 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <ranges>
#include <sstream> #include <sstream>
#include "ModelEquationBlock.hh" #include "ModelEquationBlock.hh"
@ -385,10 +386,10 @@ void
Epilogue::detrend(const map<int, expr_t>& trend_symbols_map, Epilogue::detrend(const map<int, expr_t>& trend_symbols_map,
const nonstationary_symbols_map_t& nonstationary_symbols_map) const nonstationary_symbols_map_t& nonstationary_symbols_map)
{ {
for (auto it = nonstationary_symbols_map.crbegin(); it != nonstationary_symbols_map.crend(); ++it) for (const auto& it : ranges::reverse_view(nonstationary_symbols_map))
for (auto& [symb_id, expr] : dynamic_def_table) for (auto& [symb_id, expr] : dynamic_def_table)
{ {
expr = expr->detrend(it->first, it->second.first, it->second.second); expr = expr->detrend(it.first, it.second.first, it.second.second);
assert(expr); assert(expr);
} }

View File

@ -29,6 +29,7 @@
#include <boost/graph/strong_components.hpp> #include <boost/graph/strong_components.hpp>
#include <boost/graph/topological_sort.hpp> #include <boost/graph/topological_sort.hpp>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include <ranges>
using namespace boost; using namespace boost;
@ -325,8 +326,8 @@ VariableDependencyGraph::reorderRecursiveVariables(const set<int>& feedback_vert
auto v_index = get(vertex_index, G); auto v_index = get(vertex_index, G);
// Suppress feedback vertices, in decreasing order // Suppress feedback vertices, in decreasing order
for (auto it = feedback_vertices.rbegin(); it != feedback_vertices.rend(); ++it) for (int feedback_vertex : ranges::reverse_view(feedback_vertices))
G.suppress(*it); G.suppress(feedback_vertex);
bool something_has_been_done = true; bool something_has_been_done = true;
while (something_has_been_done) while (something_has_been_done)