Remove all instances of the “map.find(key)->second” pattern
This is unsafe since the find() method can return a past-the-end iterator, which should be tested for. Replace most instances by calls to the std::map::at() method (which throws if the key is unknown), and which is incidentally more readable.master
parent
18037fd29a
commit
3d9ac26aa6
|
@ -738,7 +738,7 @@ ConfigFile::writeCluster(ostream &output) const
|
|||
<< "'ProgramConfig', '" << follower_node.second.programConfig << "', "
|
||||
<< "'MatlabOctavePath', '" << follower_node.second.matlabOctavePath << "', "
|
||||
<< "'OperatingSystem', '" << follower_node.second.operatingSystem << "', "
|
||||
<< "'NodeWeight', '" << (cluster_it->second.member_nodes.find(follower_node.first))->second << "', "
|
||||
<< "'NodeWeight', '" << cluster_it->second.member_nodes.at(follower_node.first) << "', "
|
||||
<< "'NumberOfThreadsPerJob', " << follower_node.second.numberOfThreadsPerJob << ", ";
|
||||
|
||||
if (follower_node.second.singleCompThread)
|
||||
|
|
|
@ -4130,7 +4130,7 @@ DynamicModel::substituteLeadLagInternal(AuxVarType type, bool deterministic_mode
|
|||
|
||||
for (int used_local_var : used_local_vars)
|
||||
{
|
||||
const expr_t value = local_variables_table.find(used_local_var)->second;
|
||||
const expr_t value = local_variables_table.at(used_local_var);
|
||||
expr_t subst;
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -916,17 +916,17 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
|
|||
<< "gp = zeros(" << equations.size() << ", " << getJacobianColsNbr() << ", " << symbol_table.param_nbr() << ");" << endl
|
||||
<< gp_output.str()
|
||||
<< "if nargout >= 3" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.find({ 0, 2 })->second.size() << ",4);" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.at({ 0, 2 }).size() << ",4);" << endl
|
||||
<< rpp_output.str()
|
||||
<< "gpp = zeros(" << params_derivatives.find({ 1, 2 })->second.size() << ",5);" << endl
|
||||
<< "gpp = zeros(" << params_derivatives.at({ 1, 2 }).size() << ",5);" << endl
|
||||
<< gpp_output.str()
|
||||
<< "end" << endl
|
||||
<< "if nargout >= 5" << endl
|
||||
<< "hp = zeros(" << params_derivatives.find({ 2, 1 })->second.size() << ",5);" << endl
|
||||
<< "hp = zeros(" << params_derivatives.at({ 2, 1 }).size() << ",5);" << endl
|
||||
<< hp_output.str()
|
||||
<< "end" << endl
|
||||
<< "if nargout >= 6" << endl
|
||||
<< "g3p = zeros(" << params_derivatives.find({ 3, 1 })->second.size() << ",6);" << endl
|
||||
<< "g3p = zeros(" << params_derivatives.at({ 3, 1 }).size() << ",6);" << endl
|
||||
<< g3p_output.str()
|
||||
<< "end" << endl
|
||||
<< "end" << endl;
|
||||
|
@ -952,19 +952,19 @@ DynamicModel::writeParamsDerivativesFile(const string &basename) const
|
|||
<< "@inbounds begin" << endl
|
||||
<< gp_output.str()
|
||||
<< "end" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.find({ 0, 2 })->second.size() << ",4);" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.at({ 0, 2 }).size() << ",4);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< rpp_output.str()
|
||||
<< "end" << endl
|
||||
<< "gpp = zeros(" << params_derivatives.find({ 1, 2 })->second.size() << ",5);" << endl
|
||||
<< "gpp = zeros(" << params_derivatives.at({ 1, 2 }).size() << ",5);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< gpp_output.str()
|
||||
<< "end" << endl
|
||||
<< "hp = zeros(" << params_derivatives.find({ 2, 1 })->second.size() << ",5);" << endl
|
||||
<< "hp = zeros(" << params_derivatives.at({ 2, 1 }).size() << ",5);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< hp_output.str()
|
||||
<< "end" << endl
|
||||
<< "g3p = zeros(" << params_derivatives.find({ 3, 1 })->second.size() << ",6);" << endl
|
||||
<< "g3p = zeros(" << params_derivatives.at({ 3, 1 }).size() << ",6);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< g3p_output.str()
|
||||
<< "end" << endl
|
||||
|
|
|
@ -80,8 +80,9 @@ ExternalFunctionsTable::exists(int symb_id) const
|
|||
inline int
|
||||
ExternalFunctionsTable::getNargs(int symb_id) const noexcept(false)
|
||||
{
|
||||
if (exists(symb_id))
|
||||
return externalFunctionTable.find(symb_id)->second.nargs;
|
||||
if (auto it = externalFunctionTable.find(symb_id);
|
||||
it != externalFunctionTable.end())
|
||||
return it->second.nargs;
|
||||
else
|
||||
throw UnknownExternalFunctionSymbolIDException(symb_id);
|
||||
}
|
||||
|
@ -89,8 +90,9 @@ ExternalFunctionsTable::getNargs(int symb_id) const noexcept(false)
|
|||
inline int
|
||||
ExternalFunctionsTable::getFirstDerivSymbID(int symb_id) const noexcept(false)
|
||||
{
|
||||
if (exists(symb_id))
|
||||
return externalFunctionTable.find(symb_id)->second.firstDerivSymbID;
|
||||
if (auto it = externalFunctionTable.find(symb_id);
|
||||
it != externalFunctionTable.end())
|
||||
return it->second.firstDerivSymbID;
|
||||
else
|
||||
throw UnknownExternalFunctionSymbolIDException(symb_id);
|
||||
}
|
||||
|
@ -98,8 +100,9 @@ ExternalFunctionsTable::getFirstDerivSymbID(int symb_id) const noexcept(false)
|
|||
inline int
|
||||
ExternalFunctionsTable::getSecondDerivSymbID(int symb_id) const noexcept(false)
|
||||
{
|
||||
if (exists(symb_id))
|
||||
return externalFunctionTable.find(symb_id)->second.secondDerivSymbID;
|
||||
if (auto it = externalFunctionTable.find(symb_id);
|
||||
it != externalFunctionTable.end())
|
||||
return it->second.secondDerivSymbID;
|
||||
else
|
||||
throw UnknownExternalFunctionSymbolIDException(symb_id);
|
||||
}
|
||||
|
|
|
@ -1188,7 +1188,7 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, bool write_tef_terms, d
|
|||
if (exchange(printed_something, true))
|
||||
output << ", ";
|
||||
|
||||
expr_t value = local_variables_table.find(id)->second;
|
||||
expr_t value = local_variables_table.at(id);
|
||||
if (write_tef_terms)
|
||||
{
|
||||
vector<string> efout;
|
||||
|
@ -1323,7 +1323,7 @@ ModelTree::writeLatexModelFile(const string &mod_basename, const string &latex_b
|
|||
// Write model local variables
|
||||
for (int id : local_variables_vector)
|
||||
{
|
||||
expr_t value = local_variables_table.find(id)->second;
|
||||
expr_t value = local_variables_table.at(id);
|
||||
|
||||
content_output << R"(\begin{dmath*})" << endl
|
||||
<< symbol_table.getTeXName(id) << " = ";
|
||||
|
|
|
@ -1587,7 +1587,7 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
|
|||
<< R"(, "nparamcols": )" << symbol_table.param_nbr()
|
||||
<< R"(, "entries": [)";
|
||||
for (bool printed_something {false};
|
||||
const auto &[vidx, d] : params_derivatives.find({ 0, 1 })->second)
|
||||
const auto &[vidx, d] : params_derivatives.at({ 0, 1 }))
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
rp_output << ", ";
|
||||
|
@ -1618,7 +1618,7 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
|
|||
<< R"(, "nparamcols": )" << symbol_table.param_nbr()
|
||||
<< R"(, "entries": [)";
|
||||
for (bool printed_something {false};
|
||||
const auto &[vidx, d] : params_derivatives.find({ 1, 1 })->second)
|
||||
const auto &[vidx, d] : params_derivatives.at({ 1, 1 }))
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
gp_output << ", ";
|
||||
|
@ -1656,7 +1656,7 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
|
|||
<< R"(, "nparam2cols": )" << symbol_table.param_nbr()
|
||||
<< R"(, "entries": [)";
|
||||
for (bool printed_something {false};
|
||||
const auto &[vidx, d] : params_derivatives.find({ 0, 2 })->second)
|
||||
const auto &[vidx, d] : params_derivatives.at({ 0, 2 }))
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
rpp_output << ", ";
|
||||
|
@ -1690,7 +1690,7 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
|
|||
<< R"(, "nparam2cols": )" << symbol_table.param_nbr()
|
||||
<< R"(, "entries": [)";
|
||||
for (bool printed_something {false};
|
||||
const auto &[vidx, d] : params_derivatives.find({ 1, 2 })->second)
|
||||
const auto &[vidx, d] : params_derivatives.at({ 1, 2 }))
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
gpp_output << ", ";
|
||||
|
@ -1732,7 +1732,7 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
|
|||
<< R"(, "nparamcols": )" << symbol_table.param_nbr()
|
||||
<< R"(, "entries": [)";
|
||||
for (bool printed_something {false};
|
||||
const auto &[vidx, d] : params_derivatives.find({ 2, 1 })->second)
|
||||
const auto &[vidx, d] : params_derivatives.at({ 2, 1 }))
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
hp_output << ", ";
|
||||
|
@ -1779,7 +1779,7 @@ ModelTree::writeJsonParamsDerivativesHelper(bool writeDetails) const
|
|||
<< R"(, "nparamcols": )" << symbol_table.param_nbr()
|
||||
<< R"(, "entries": [)";
|
||||
for (bool printed_something {false};
|
||||
const auto &[vidx, d] : params_derivatives.find({ 3, 1 })->second)
|
||||
const auto &[vidx, d] : params_derivatives.at({ 3, 1 }))
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
g3p_output << ", ";
|
||||
|
|
|
@ -53,7 +53,7 @@ StaticModel::StaticModel(const DynamicModel &m) :
|
|||
{
|
||||
// Convert model local variables (need to be done first)
|
||||
for (int it : m.local_variables_vector)
|
||||
AddLocalVariable(it, m.local_variables_table.find(it)->second->toStatic(*this));
|
||||
AddLocalVariable(it, m.local_variables_table.at(it)->toStatic(*this));
|
||||
|
||||
// Convert equations
|
||||
int static_only_index = 0;
|
||||
|
|
|
@ -284,13 +284,13 @@ StaticModel::writeParamsDerivativesFile(const string &basename) const
|
|||
<< symbol_table.param_nbr() << ");" << endl
|
||||
<< gp_output.str()
|
||||
<< "if nargout >= 3" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.find({ 0, 2 })->second.size() << ",4);" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.at({ 0, 2 }).size() << ",4);" << endl
|
||||
<< rpp_output.str()
|
||||
<< "gpp = zeros(" << params_derivatives.find({ 1, 2 })->second.size() << ",5);" << endl
|
||||
<< "gpp = zeros(" << params_derivatives.at({ 1, 2 }).size() << ",5);" << endl
|
||||
<< gpp_output.str()
|
||||
<< "end" << endl
|
||||
<< "if nargout >= 5" << endl
|
||||
<< "hp = zeros(" << params_derivatives.find({ 2, 1 })->second.size() << ",5);" << endl
|
||||
<< "hp = zeros(" << params_derivatives.at({ 2, 1 }).size() << ",5);" << endl
|
||||
<< hp_output.str()
|
||||
<< "end" << endl
|
||||
<< "end" << endl;
|
||||
|
@ -316,15 +316,15 @@ StaticModel::writeParamsDerivativesFile(const string &basename) const
|
|||
<< "@inbounds begin" << endl
|
||||
<< gp_output.str()
|
||||
<< "end" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.find({ 0, 2 })->second.size() << ",4);" << endl
|
||||
<< "rpp = zeros(" << params_derivatives.at({ 0, 2 }).size() << ",4);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< rpp_output.str()
|
||||
<< "end" << endl
|
||||
<< "gpp = zeros(" << params_derivatives.find({ 1, 2 })->second.size() << ",5);" << endl
|
||||
<< "gpp = zeros(" << params_derivatives.at({ 1, 2 }).size() << ",5);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< gpp_output.str()
|
||||
<< "end" << endl
|
||||
<< "hp = zeros(" << params_derivatives.find({ 2, 1 })->second.size() << ",5);" << endl
|
||||
<< "hp = zeros(" << params_derivatives.at({ 2, 1 }).size() << ",5);" << endl
|
||||
<< "@inbounds begin" << endl
|
||||
<< hp_output.str()
|
||||
<< "end" << endl
|
||||
|
|
|
@ -130,7 +130,7 @@ const vector<string> &
|
|||
TrendComponentModelTable::getEqTags(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return eqtags.find(name_arg)->second;
|
||||
return eqtags.at(name_arg);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -148,28 +148,28 @@ const vector<int> &
|
|||
TrendComponentModelTable::getNonTargetLhs(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return nontarget_lhs.find(name_arg)->second;
|
||||
return nontarget_lhs.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<int> &
|
||||
TrendComponentModelTable::getTargetLhs(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return target_lhs.find(name_arg)->second;
|
||||
return target_lhs.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<int> &
|
||||
TrendComponentModelTable::getLhs(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return lhs.find(name_arg)->second;
|
||||
return lhs.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<expr_t> &
|
||||
TrendComponentModelTable::getLhsExprT(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return lhs_expr_t.find(name_arg)->second;
|
||||
return lhs_expr_t.at(name_arg);
|
||||
}
|
||||
|
||||
const map<string, vector<string>> &
|
||||
|
@ -194,7 +194,7 @@ const vector<int> &
|
|||
TrendComponentModelTable::getTargetEqNums(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return target_eqnums.find(name_arg)->second;
|
||||
return target_eqnums.at(name_arg);
|
||||
}
|
||||
|
||||
const map<string, vector<int>> &
|
||||
|
@ -207,21 +207,21 @@ const vector<int> &
|
|||
TrendComponentModelTable::getNonTargetEqNums(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return nontarget_eqnums.find(name_arg)->second;
|
||||
return nontarget_eqnums.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<int> &
|
||||
TrendComponentModelTable::getEqNums(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return eqnums.find(name_arg)->second;
|
||||
return eqnums.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<int> &
|
||||
TrendComponentModelTable::getMaxLags(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return max_lags.find(name_arg)->second;
|
||||
return max_lags.at(name_arg);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -237,7 +237,7 @@ const vector<bool> &
|
|||
TrendComponentModelTable::getDiff(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return diff.find(name_arg)->second;
|
||||
return diff.at(name_arg);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -575,7 +575,7 @@ const vector<string> &
|
|||
VarModelTable::getEqTags(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return eqtags.find(name_arg)->second;
|
||||
return eqtags.at(name_arg);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -643,14 +643,14 @@ const vector<bool> &
|
|||
VarModelTable::getDiff(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return diff.find(name_arg)->second;
|
||||
return diff.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<int> &
|
||||
VarModelTable::getEqNums(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return eqnums.find(name_arg)->second;
|
||||
return eqnums.at(name_arg);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -693,7 +693,7 @@ const vector<int> &
|
|||
VarModelTable::getMaxLags(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return max_lags.find(name_arg)->second;
|
||||
return max_lags.at(name_arg);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -709,28 +709,28 @@ const vector<int> &
|
|||
VarModelTable::getLhs(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return lhs.find(name_arg)->second;
|
||||
return lhs.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<int> &
|
||||
VarModelTable::getLhsOrigIds(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return lhs_orig_symb_ids.find(name_arg)->second;
|
||||
return lhs_orig_symb_ids.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<set<pair<int, int>>> &
|
||||
VarModelTable::getRhs(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return rhs.find(name_arg)->second;
|
||||
return rhs.at(name_arg);
|
||||
}
|
||||
|
||||
const vector<expr_t> &
|
||||
VarModelTable::getLhsExprT(const string &name_arg) const
|
||||
{
|
||||
checkModelName(name_arg);
|
||||
return lhs_expr_t.find(name_arg)->second;
|
||||
return lhs_expr_t.at(name_arg);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ Environment::print(ostream &output, const vector<string> &vars, const optional<i
|
|||
else
|
||||
for (const auto &it : vars)
|
||||
if (isFunctionDefined(it))
|
||||
printFunction(output, functions.find(it)->second, line, save);
|
||||
printFunction(output, functions.at(it), line, save);
|
||||
|
||||
if (parent)
|
||||
parent->print(output, vars, line, save);
|
||||
|
|
Loading…
Reference in New Issue