From 06d05e9a8dac23d0176c14109d88f65c652a67c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Mon, 16 May 2022 15:23:35 +0200 Subject: [PATCH] C++17 modernization: use std::optional for SymbolTable::getEquationNumberForMultiplier() --- src/DynamicModel.cc | 8 ++++---- src/SymbolTable.cc | 4 ++-- src/SymbolTable.hh | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 81afb452..9d79ef1d 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -4735,13 +4735,13 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model) if (symbol_table.getType(symb_id) == SymbolType::endogenous && lag == 0) { neweqs.push_back(AddEqual(equations[0]->getNonZeroPartofEquation()->getDerivative(deriv_id), Zero)); - if (int i = symbol_table.getEquationNumberForMultiplier(symb_id); - i != -1) + if (optional<int> i = symbol_table.getEquationNumberForMultiplier(symb_id); + i) { // This is a derivative w.r.t. a Lagrange multiplier - neweqs_lineno.push_back(old_equations_lineno[i]); + neweqs_lineno.push_back(old_equations_lineno[*i]); map<string, string> tags; - auto tmp = old_equation_tags.getTagsByEqn(i); + auto tmp = old_equation_tags.getTagsByEqn(*i); for (const auto &[key, value] : tmp) tags[key] = value; neweqs_tags[neweqs.size()-1] = tags; diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index dae16a23..0900016f 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -1087,13 +1087,13 @@ SymbolTable::getUltimateOrigSymbID(int symb_id) const return symb_id; } -int +optional<int> SymbolTable::getEquationNumberForMultiplier(int symb_id) const { for (const auto &aux_var : aux_vars) if (aux_var.get_symb_id() == symb_id && aux_var.get_type() == AuxVarType::multiplier) return aux_var.get_equation_number_for_multiplier(); - return -1; + return nullopt; } const set<int> & diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index e5b21442..50d451d9 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -464,8 +464,8 @@ public: no original variable (e.g. aux var for lead, Lagrange Multiplier or diff associated to a complex expression). */ int getUltimateOrigSymbID(int symb_id) const; - //! If this is a Lagrange multiplier, return its associated equation number; otherwise return -1 - int getEquationNumberForMultiplier(int symb_id) const; + //! If this is a Lagrange multiplier, return its associated equation number; otherwise return nullopt + optional<int> getEquationNumberForMultiplier(int symb_id) const; /* Return all the information about a given auxiliary variable. Throws UnknownSymbolIDException if it is not an aux var */ const AuxVarInfo &getAuxVarInfo(int symb_id) const; -- GitLab