From 14518f552c0b8169bc33f56daa93f63bd5b42280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Mon, 15 Jul 2024 18:28:17 +0200 Subject: [PATCH] C++20 modernization: use ranges library --- mex/sources/bytecode/Interpreter.cc | 11 +++++------ mex/sources/libkorder/tl/equivalence.cc | 10 ++-------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index 2753c116de..32515f83d5 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -660,24 +660,23 @@ Interpreter::check_for_controlled_exo_validity(const vector<s_plan>& sconstraine vector<int> endogenous {evaluator.getCurrentBlockVariables()}; for (auto& it : sconstrained_extended_path) { - if (find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end() - && find(exogenous.begin(), exogenous.end(), it.var_num) == exogenous.end()) + if (ranges::find(endogenous, it.exo_num) != endogenous.end() + && ranges::find(exogenous, it.var_num) == exogenous.end()) throw FatalException {"\nThe conditional forecast involving as constrained variable " + symbol_table.getName(SymbolType::endogenous, it.exo_num) + " and as endogenized exogenous " + symbol_table.getName(SymbolType::exogenous, it.var_num) + " that do not appear in block=" + to_string(block_num + 1) + ")\nYou should not use block in model options"}; - else if (find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end() - && find(exogenous.begin(), exogenous.end(), it.var_num) != exogenous.end() + else if (ranges::find(endogenous, it.exo_num) != endogenous.end() + && ranges::find(exogenous, it.var_num) != exogenous.end() && (type == BlockSimulationType::evaluateForward || type == BlockSimulationType::evaluateBackward)) throw FatalException {"\nThe conditional forecast cannot be implemented for the block=" + to_string(block_num + 1) + ") that has to be evaluated instead to be solved\nYou should not " "use block in model options"}; - else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it.var_num) - != previous_block_exogenous.end()) + else if (ranges::find(previous_block_exogenous, it.var_num) != previous_block_exogenous.end()) throw FatalException { "\nThe conditional forecast involves in the block " + to_string(block_num + 1) + " the endogenized exogenous " diff --git a/mex/sources/libkorder/tl/equivalence.cc b/mex/sources/libkorder/tl/equivalence.cc index 3b348b4ced..3b560bfd3f 100644 --- a/mex/sources/libkorder/tl/equivalence.cc +++ b/mex/sources/libkorder/tl/equivalence.cc @@ -22,6 +22,7 @@ #include "permutation.hh" #include "tl_exception.hh" +#include <algorithm> #include <iostream> #include <numeric> @@ -85,14 +86,7 @@ OrdSequence::add(const OrdSequence& s) bool OrdSequence::has(int i) const { - auto vit = data.begin(); - while (vit != data.end()) - { - if (*vit == i) - return true; - ++vit; - } - return false; + return std::ranges::find(data, i) != data.end(); } /* Return an average of the class. */ -- GitLab