Bytecode: port to C++11 range-based for loops

Performed using modernize-loop-convert from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html
time-shift
Sébastien Villemot 2021-02-01 12:32:17 +01:00
parent 2f587cf5c3
commit 7840d1396e
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
5 changed files with 33 additions and 33 deletions

View File

@ -374,13 +374,13 @@ public:
dollar = "$";
pound = "£";
tilde = "~";
for (unsigned int i = 0; i < str.length(); i++)
for (const char & i : str)
{
if (dollar.compare(&str[i]) != 0 && pound.compare(&str[i]) != 0)
temp += str[i];
if (dollar.compare(&i) != 0 && pound.compare(&i) != 0)
temp += i;
else
{
if (dollar.compare(&str[i]) == 0)
if (dollar.compare(&i) == 0)
pos1 = int (temp.length());
else
pos2 = int (temp.length());

View File

@ -461,12 +461,12 @@ Interpreter::simulate_a_block(vector_table_conditional_local_type vector_table_c
memcpy(y_save, y, y_size*sizeof(double)*(periods+y_kmax+y_kmin));
if (vector_table_conditional_local.size())
{
for (vector_table_conditional_local_type::iterator it1 = vector_table_conditional_local.begin(); it1 != vector_table_conditional_local.end(); it1++)
for (auto & it1 : vector_table_conditional_local)
{
if (it1->is_cond)
if (it1.is_cond)
{
//mexPrintf("y[%d] = %f\n", it1->var_endo + y_kmin * size, y[it1->var_endo + y_kmin * size]);
y[it1->var_endo + y_kmin * size] = it1->constrained_value;
y[it1.var_endo + y_kmin * size] = it1.constrained_value;
}
}
@ -606,24 +606,24 @@ Interpreter::check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector<s_plan>
{
vector<int> exogenous = fb->get_exogenous();
vector<int> endogenous = fb->get_endogenous();
for (vector<s_plan>::iterator it = sconstrained_extended_path.begin(); it != sconstrained_extended_path.end(); it++)
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 ((find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it.var_num) == exogenous.end()))
{
ostringstream tmp;
tmp << "\n the conditional forecast involving as constrained variable " << get_variable(SymbolType::endogenous, it->exo_num) << " and as endogenized exogenous " << get_variable(SymbolType::exogenous, it->var_num) << " that do not appear in block=" << Block_Count+1 << ")\n You should not use block in model options\n";
tmp << "\n the conditional forecast involving as constrained variable " << get_variable(SymbolType::endogenous, it.exo_num) << " and as endogenized exogenous " << get_variable(SymbolType::exogenous, it.var_num) << " that do not appear in block=" << Block_Count+1 << ")\n You should not use block in model options\n";
throw FatalExceptionHandling(tmp.str());
}
else if ((find(endogenous.begin(), endogenous.end(), it->exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it->var_num) != exogenous.end()) && ((fb->get_type() == static_cast<uint8_t>(BlockSimulationType::evaluateForward)) || (fb->get_type() != static_cast<uint8_t>(BlockSimulationType::evaluateBackward))))
else if ((find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it.var_num) != exogenous.end()) && ((fb->get_type() == static_cast<uint8_t>(BlockSimulationType::evaluateForward)) || (fb->get_type() != static_cast<uint8_t>(BlockSimulationType::evaluateBackward))))
{
ostringstream tmp;
tmp << "\n the conditional forecast cannot be implemented for the block=" << Block_Count+1 << ") that has to be evaluated instead to be solved\n You should not use block in model options\n";
throw FatalExceptionHandling(tmp.str());
}
else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it->var_num) != previous_block_exogenous.end())
else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it.var_num) != previous_block_exogenous.end())
{
ostringstream tmp;
tmp << "\n the conditional forecast involves in the block " << Block_Count+1 << " the endogenized exogenous " << get_variable(SymbolType::exogenous, it->var_num) << " that appear also in a previous block\n You should not use block in model options\n";
tmp << "\n the conditional forecast involves in the block " << Block_Count+1 << " the endogenized exogenous " << get_variable(SymbolType::exogenous, it.var_num) << " that appear also in a previous block\n You should not use block in model options\n";
throw FatalExceptionHandling(tmp.str());
}
}
@ -908,9 +908,9 @@ Interpreter::extended_path(string file_name, string bin_basename, bool evaluate,
mexPrintf("|%s|", elastic(dates[t], date_length+2, false).c_str());
mexEvalString("drawnow;");
}
for (vector<s_plan>::const_iterator it = sextended_path.begin(); it != sextended_path.end(); it++)
for (const auto & it : sextended_path)
{
x[y_kmin + (it->exo_num - 1) * /*(nb_periods + y_kmax + y_kmin)*/ nb_row_x] = it->value[t];
x[y_kmin + (it.exo_num - 1) * /*(nb_periods + y_kmax + y_kmin)*/ nb_row_x] = it.value[t];
}
it_code = Init_Code;

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2007-2020 Dynare Team
* Copyright © 2007-2021 Dynare Team
*
* This file is part of Dynare.
*
@ -2040,8 +2040,8 @@ dynSparseMatrix::Clear_u()
void
dynSparseMatrix::Print_u()
{
for (unsigned int i = 0; i < u_liste.size(); i++)
mexPrintf("%d ", u_liste[i]);
for (int i : u_liste)
mexPrintf("%d ", i);
}
void

View File

@ -739,17 +739,17 @@ main(int nrhs, const char *prhs[])
}
}
int i = 0;
for (vector<s_plan>::iterator it = splan.begin(); it != splan.end(); it++)
for (auto & it : splan)
{
mexPrintf("----------------------------------------------------------------------------------------------------\n");
mexPrintf("surprise #%d\n", i+1);
if (it->exo.length())
mexPrintf(" plan fliping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it->var.c_str(), it->var_num, it->exo.c_str(), it->exo_num);
if (it.exo.length())
mexPrintf(" plan fliping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num, it.exo.c_str(), it.exo_num);
else
mexPrintf(" plan shocks on var=%s for the following periods and with the following values:\n", it->var.c_str());
for (vector<pair<int, double>>::iterator it1 = it->per_value.begin(); it1 != it->per_value.end(); it1++)
mexPrintf(" plan shocks on var=%s for the following periods and with the following values:\n", it.var.c_str());
for (auto & it1 : it.per_value)
{
mexPrintf(" %3d %10.5f\n", it1->first, it1->second);
mexPrintf(" %3d %10.5f\n", it1.first, it1.second);
}
i++;
}
@ -817,17 +817,17 @@ main(int nrhs, const char *prhs[])
}
}
int i = 0;
for (vector<s_plan>::iterator it = spfplan.begin(); it != spfplan.end(); it++)
for (auto & it : spfplan)
{
mexPrintf("----------------------------------------------------------------------------------------------------\n");
mexPrintf("perfect foresight #%d\n", i+1);
if (it->exo.length())
mexPrintf(" plan flipping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it->var.c_str(), it->var_num, it->exo.c_str(), it->exo_num);
if (it.exo.length())
mexPrintf(" plan flipping var=%s (%d) exo=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num, it.exo.c_str(), it.exo_num);
else
mexPrintf(" plan shocks on var=%s (%d) for the following periods and with the following values:\n", it->var.c_str(), it->var_num);
for (vector<pair<int, double>>::iterator it1 = it->per_value.begin(); it1 != it->per_value.end(); it1++)
mexPrintf(" plan shocks on var=%s (%d) for the following periods and with the following values:\n", it.var.c_str(), it.var_num);
for (auto & it1 : it.per_value)
{
mexPrintf(" %3d %10.5f\n", it1->first, it1->second);
mexPrintf(" %3d %10.5f\n", it1.first, it1.second);
}
i++;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2007-2011 Dynare Team
* Copyright © 2007-2021 Dynare Team
*
* This file is part of Dynare.
*
@ -517,6 +517,6 @@ Free_Array(mxArray *array)
void
Free_global()
{
for (map<string, mxArray *>::iterator it = mxglobal.begin(); it != mxglobal.end(); it++)
Free_Array(it->second);
for (auto & it : mxglobal)
Free_Array(it.second);
}