diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 4dbb45011e031f592fca0fd2a92760ad01375ae2..09a05a7cf432281709e6bfec73835023e667cf97 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -362,9 +362,9 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli || mod_file_struct.order_option >= 3) mod_file_struct.k_order_solver = true; - if (bool hp = options_list.num_options.find("hp_filter") != options_list.num_options.end(), - bandpass = options_list.num_options.find("bandpass.indicator") != options_list.num_options.end(), - one_sided_hp = options_list.num_options.find("one_sided_hp_filter") != options_list.num_options.end(); + if (bool hp = options_list.num_options.contains("hp_filter"), + bandpass = options_list.num_options.contains("bandpass.indicator"), + one_sided_hp = options_list.num_options.contains("one_sided_hp_filter"); (hp && bandpass) || (hp && one_sided_hp) || (bandpass && one_sided_hp)) { cerr << "ERROR: stoch_simul: can only use one of hp, one-sided hp, and bandpass filters" @@ -745,7 +745,7 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni { mod_file_struct.discretionary_policy_present = true; - if (options_list.symbol_list_options.find("instruments") == options_list.symbol_list_options.end()) + if (!options_list.symbol_list_options.contains("instruments")) { cerr << "ERROR: discretionary_policy: the instruments option is required." << endl; exit(EXIT_FAILURE); @@ -971,7 +971,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli mod_file_struct.dsge_var_calibrated = it->second; // Fill in mod_file_struct.dsge_var_estimated - if (options_list.string_options.find("dsge_var") != options_list.string_options.end()) + if (options_list.string_options.contains("dsge_var")) mod_file_struct.dsge_var_estimated = true; // Fill in mod_file_struct.bayesian_irf_present @@ -979,7 +979,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli it != options_list.num_options.end() && it->second == "true") mod_file_struct.bayesian_irf_present = true; - if (options_list.num_options.find("dsge_varlag") != options_list.num_options.end()) + if (options_list.num_options.contains("dsge_varlag")) if (mod_file_struct.dsge_var_calibrated.empty() && !mod_file_struct.dsge_var_estimated) { @@ -995,14 +995,14 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } - if (options_list.string_options.find("datafile") == options_list.string_options.end() + if (!options_list.string_options.contains("datafile") && !mod_file_struct.estimation_data_statement_present) { cerr << "ERROR: The estimation statement requires a data file to be supplied via the datafile option." << endl; exit(EXIT_FAILURE); } - if (options_list.string_options.find("mode_file") != options_list.string_options.end() + if (options_list.string_options.contains("mode_file") && mod_file_struct.estim_params_use_calib) { cerr << "ERROR: The mode_file option of the estimation statement is incompatible with the use_calibration option of the estimated_params_init block." << endl; @@ -1018,7 +1018,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } } - else if (options_list.num_options.find("mh_tune_jscale.guess") != options_list.num_options.end()) + else if (options_list.num_options.contains("mh_tune_jscale.guess")) { cerr << "ERROR: The option mh_tune_guess in estimation statement cannot be used without option mh_tune_jscale." << endl; exit(EXIT_FAILURE); @@ -1265,23 +1265,23 @@ AbstractEstimatedParamsStatement::commonCheckPass() const // Use lexical ordering for the pair of symbols auto x = it.name < it.name2 ? make_pair(it.name, it.name2) : make_pair(it.name2, it.name); - if (already_declared_corr.find(x) == already_declared_corr.end()) - already_declared_corr.insert(x); - else + if (already_declared_corr.contains(x)) { cerr << "ERROR: in `" << blockName() << "' block, the correlation between " << it.name << " and " << it.name2 << " is declared twice." << endl; exit(EXIT_FAILURE); } + else + already_declared_corr.insert(x); } else { - if (already_declared.find(it.name) == already_declared.end()) - already_declared.insert(it.name); - else + if (already_declared.contains(it.name)) { cerr << "ERROR: in `" << blockName() << "' block, the symbol " << it.name << " is declared twice." << endl; exit(EXIT_FAILURE); } + else + already_declared.insert(it.name); } } @@ -2554,9 +2554,9 @@ MSSBVAREstimationStatement::checkPass(ModFileStructure &mod_file_struct, Warning { mod_file_struct.bvar_present = true; - if (options_list.num_options.find("ms.create_init") == options_list.num_options.end() - && (options_list.string_options.find("datafile") == options_list.string_options.end() - || options_list.num_options.find("ms.initial_year") == options_list.num_options.end())) + if (!options_list.num_options.contains("ms.create_init") + && (!options_list.string_options.contains("datafile") + || !options_list.num_options.contains("ms.initial_year"))) { cerr << "ERROR: If you do not pass no_create_init to ms_estimation, " << "you must pass the datafile and initial_year options." << endl; @@ -2603,9 +2603,9 @@ MSSBVARSimulationStatement::writeOutput(ostream &output, const string &basename, options_list.writeOutput(output); // Redeclare drop option if necessary - if ((options_list.num_options.find("ms.mh_replic") != options_list.num_options.end() - || options_list.num_options.find("ms.thinning_factor") != options_list.num_options.end()) - && (options_list.num_options.find("ms.drop") == options_list.num_options.end())) + if ((options_list.num_options.contains("ms.mh_replic") + || options_list.num_options.contains("ms.thinning_factor")) + && !options_list.num_options.contains("ms.drop")) output << "options_.ms.drop = 0.1*options_.ms.mh_replic*options_.ms.thinning_factor;" << endl; output << "[options_, oo_] = ms_simulation(M_, options_, oo_);" << endl; @@ -2664,8 +2664,8 @@ MSSBVARComputeProbabilitiesStatement::checkPass(ModFileStructure &mod_file_struc { mod_file_struct.bvar_present = true; - if (options_list.num_options.find("ms.real_time_smoothed_probabilities") != options_list.num_options.end() - && options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end()) + if (options_list.num_options.contains("ms.real_time_smoothed_probabilities") + && options_list.num_options.contains("ms.filtered_probabilities")) { cerr << "ERROR: You may only pass one of real_time_smoothed " << "and filtered_probabilities to ms_compute_probabilities." << endl; @@ -2706,9 +2706,9 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli { mod_file_struct.bvar_present = true; - if (bool regime_present = options_list.num_options.find("ms.regime") != options_list.num_options.end(), - regimes_present = options_list.num_options.find("ms.regimes") != options_list.num_options.end(), - filtered_probabilities_present = options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end(); + if (bool regime_present = options_list.num_options.contains("ms.regime"), + regimes_present = options_list.num_options.contains("ms.regimes"), + filtered_probabilities_present = options_list.num_options.contains("ms.filtered_probabilities"); (filtered_probabilities_present && regime_present) || (filtered_probabilities_present && regimes_present) || (regimes_present && regime_present)) @@ -2765,8 +2765,8 @@ MSSBVARForecastStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo { mod_file_struct.bvar_present = true; - if (options_list.num_options.find("ms.regimes") != options_list.num_options.end() - && options_list.num_options.find("ms.regime") != options_list.num_options.end()) + if (options_list.num_options.contains("ms.regimes") + && options_list.num_options.contains("ms.regime")) { cerr << "ERROR: You may only pass one of regime and regimes to ms_forecast" << endl; exit(EXIT_FAILURE); @@ -2803,9 +2803,9 @@ MSSBVARVarianceDecompositionStatement::checkPass(ModFileStructure &mod_file_stru { mod_file_struct.bvar_present = true; - if (bool regime_present = options_list.num_options.find("ms.regime") != options_list.num_options.end(), - regimes_present = options_list.num_options.find("ms.regimes") != options_list.num_options.end(), - filtered_probabilities_present = options_list.num_options.find("ms.filtered_probabilities") != options_list.num_options.end(); + if (bool regime_present = options_list.num_options.contains("ms.regime"), + regimes_present = options_list.num_options.contains("ms.regimes"), + filtered_probabilities_present = options_list.num_options.contains("ms.filtered_probabilities"); (filtered_probabilities_present && regime_present) || (filtered_probabilities_present && regimes_present) || (regimes_present && regime_present)) @@ -3240,7 +3240,7 @@ ConditionalForecastStatement::ConditionalForecastStatement(OptionsList options_l void ConditionalForecastStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - if (options_list.string_options.find("parameter_set") == options_list.string_options.end()) + if (!options_list.string_options.contains("parameter_set")) { cerr << "ERROR: You must pass the `parameter_set` option to conditional_forecast" << endl; exit(EXIT_FAILURE); @@ -3501,8 +3501,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg) exit(EXIT_FAILURE); } - if (restriction_map.find({ from_regime, to_regime }) != - restriction_map.end()) + if (restriction_map.contains({ from_regime, to_regime })) { cerr << "ERROR: two restrictions were given for: " << from_regime << ", " << to_regime << endl; @@ -3555,7 +3554,7 @@ MarkovSwitchingStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo vector<bool> all_restrictions_in_col(num_regimes, true); for (int row = 0; row < num_regimes; row++) for (int col = 0; col < num_regimes; col++) - if (restriction_map.find({ row+1, col+1 }) != restriction_map.end()) + if (restriction_map.contains({ row+1, col+1 })) { row_trans_prob_sum[row] += restriction_map[{ row+1, col+1 }]; col_trans_prob_sum[col] += restriction_map[{ row+1, col+1 }]; @@ -3604,7 +3603,7 @@ MarkovSwitchingStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo } } - if (options_list.symbol_list_options.find("ms.parameters") != options_list.symbol_list_options.end()) + if (options_list.symbol_list_options.contains("ms.parameters")) mod_file_struct.ms_dsge_present = true; } @@ -3677,9 +3676,9 @@ SvarStatement::SvarStatement(OptionsList options_list_arg) : void SvarStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { - bool has_coefficients = options_list.string_options.find("ms.coefficients") != options_list.string_options.end(), - has_variances = options_list.string_options.find("ms.variances") != options_list.string_options.end(), - has_constants = options_list.string_options.find("ms.constants") != options_list.string_options.end(); + bool has_coefficients = options_list.string_options.contains("ms.coefficients"), + has_variances = options_list.string_options.contains("ms.variances"), + has_constants = options_list.string_options.contains("ms.constants"); assert((has_coefficients && !has_variances && !has_constants) || (!has_coefficients && has_variances && !has_constants) || (!has_coefficients && !has_variances && has_constants)); @@ -3785,8 +3784,8 @@ EstimationDataStatement::checkPass(ModFileStructure &mod_file_struct, WarningCon exit(EXIT_FAILURE); } - bool has_file = options_list.string_options.find("file") != options_list.string_options.end(), - has_series = options_list.string_options.find("series") != options_list.string_options.end(); + bool has_file = options_list.string_options.contains("file"), + has_series = options_list.string_options.contains("series"); if (!has_file && !has_series) { cerr << "ERROR: The file or series option must be passed to the data statement." << endl; @@ -4031,8 +4030,8 @@ JointPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } - if (options_list.num_options.find("mean") == options_list.num_options.end() - && options_list.num_options.find("mode") == options_list.num_options.end()) + if (!options_list.num_options.contains("mean") + && !options_list.num_options.contains("mode")) { cerr << "ERROR: You must pass at least one of mean and mode to the prior statement." << endl; exit(EXIT_FAILURE); @@ -4188,14 +4187,14 @@ BasicPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli exit(EXIT_FAILURE); } - if (options_list.num_options.find("mean") == options_list.num_options.end() - && options_list.num_options.find("mode") == options_list.num_options.end()) + if (!options_list.num_options.contains("mean") + && !options_list.num_options.contains("mode")) { cerr << "ERROR: You must pass at least one of mean and mode to the prior statement." << endl; exit(EXIT_FAILURE); } - if (bool has_stdev = options_list.num_options.find("stdev") != options_list.num_options.end(); + if (bool has_stdev = options_list.num_options.contains("stdev"); (!has_stdev && !variance) || (has_stdev && variance)) { cerr << "ERROR: You must pass exactly one of stdev and variance to the prior statement." << endl; @@ -4881,7 +4880,7 @@ void CalibSmootherStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); - if (options_list.string_options.find("parameter_set") == options_list.string_options.end()) + if (!options_list.string_options.contains("parameter_set")) output << "options_.parameter_set = 'calibration';" << endl; symbol_list.writeOutput("var_list_", output); output << "options_.smoother = true;" << endl @@ -4916,7 +4915,7 @@ ExtendedPathStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso { mod_file_struct.extended_path_present = true; - if (options_list.num_options.find("periods") == options_list.num_options.end()) + if (!options_list.num_options.contains("periods")) { cerr << "ERROR: the 'periods' option of 'extended_path' is mandatory" << endl; exit(EXIT_FAILURE); @@ -5006,13 +5005,13 @@ MethodOfMomentsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo mod_file_struct.order_option = max(mod_file_struct.order_option, order); } - if (options_list.string_options.find("datafile") == options_list.string_options.end()) + if (!options_list.string_options.contains("datafile")) { cerr << "ERROR: The method_of_moments statement requires a data file to be supplied via the datafile option." << endl; exit(EXIT_FAILURE); } - if (options_list.string_options.find("mom.mom_method") == options_list.string_options.end()) + if (!options_list.string_options.contains("mom.mom_method")) { cerr << "ERROR: The method_of_moments statement requires a method to be supplied via the mom_method option. Possible values are GMM or SMM." << endl; exit(EXIT_FAILURE); diff --git a/src/ConfigFile.cc b/src/ConfigFile.cc index d7147d53e16eb5a7d179572d27a5cbe2eac9ec5f..dfb69ee5d5f920ae3b71e56671b8d4ea01bc9ecd 100644 --- a/src/ConfigFile.cc +++ b/src/ConfigFile.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2010-2021 Dynare Team + * Copyright © 2010-2022 Dynare Team * * This file is part of Dynare. * @@ -401,7 +401,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) if (!begin_weight) { if (!node_name.empty()) - if (member_nodes.find(node_name) != member_nodes.end()) + if (member_nodes.contains(node_name)) { cerr << "ERROR (in config file): Node entered twice in specification of cluster." << endl; exit(EXIT_FAILURE); @@ -428,7 +428,7 @@ ConfigFile::getConfigFileInfo(const string &config_file) } } if (!node_name.empty()) - if (member_nodes.find(node_name) == member_nodes.end()) + if (!member_nodes.contains(node_name)) member_nodes[node_name] = 1.0; else { @@ -498,7 +498,7 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, const member exit(EXIT_FAILURE); } else - if (name.empty() || slave_nodes.find(name) != slave_nodes.end()) + if (name.empty() || slave_nodes.contains(name)) { cerr << "ERROR: Every node must be assigned a unique name." << endl; exit(EXIT_FAILURE); @@ -519,7 +519,7 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, const member exit(EXIT_FAILURE); } else - if (name.empty() || clusters.find(name) != clusters.end()) + if (name.empty() || clusters.contains(name)) { cerr << "ERROR: The cluster must be assigned a unique name." << endl; exit(EXIT_FAILURE); @@ -641,7 +641,7 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const exit(EXIT_FAILURE); } - if (!cluster_name.empty() && clusters.find(cluster_name) == clusters.end()) + if (!cluster_name.empty() && !clusters.contains(cluster_name)) { cerr << "ERROR: Cluster Name " << cluster_name << " was not found in the config file." << endl; exit(EXIT_FAILURE); @@ -649,7 +649,7 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const for (const auto &cluster : clusters) for (const auto &itmn : cluster.second.member_nodes) - if (slave_nodes.find(itmn.first) == slave_nodes.end()) + if (!slave_nodes.contains(itmn.first)) { cerr << "Error: node " << itmn.first << " specified in cluster " << cluster.first << " was not found" << endl; exit(EXIT_FAILURE); diff --git a/src/DataTree.cc b/src/DataTree.cc index 7574a895e8e8a5bda5c312077b378e05aca7da91..58eb599135043550130ce7448bafb6382ab75bf3 100644 --- a/src/DataTree.cc +++ b/src/DataTree.cc @@ -733,7 +733,7 @@ DataTree::AddLocalVariable(int symb_id, expr_t value) noexcept(false) assert(symbol_table.getType(symb_id) == SymbolType::modelLocalVariable); // Throw an exception if symbol already declared - if (local_variables_table.find(symb_id) != local_variables_table.end()) + if (local_variables_table.contains(symb_id)) throw LocalVariableException(symbol_table.getName(symb_id)); local_variables_table[symb_id] = value; @@ -796,7 +796,7 @@ DataTree::isSymbolUsed(int symb_id) const if (it.first.first == symb_id) return true; - if (local_variables_table.find(symb_id) != local_variables_table.end()) + if (local_variables_table.contains(symb_id)) return true; return false; diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 247bbad092dc801126fcfe84268e18b1331fd39e..d200e06f8c919e0ba3312fa1b1ee0d9e43b36b9e 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -2502,7 +2502,7 @@ DynamicModel::removeEquationsHelper(set<pair<string, string>> &listed_eqs_by_tag eqs_to_delete_by_number = listed_eqs_by_number; else for (size_t i = 0; i < all_equations.size(); i++) - if (listed_eqs_by_number.find(i) == listed_eqs_by_number.end()) + if (!listed_eqs_by_number.contains(i)) eqs_to_delete_by_number.insert(i); // remove from equations, equations_lineno, equation_tags @@ -2511,7 +2511,7 @@ DynamicModel::removeEquationsHelper(set<pair<string, string>> &listed_eqs_by_tag map<int, int> old_eqn_num_2_new; vector<int> excluded_vars; for (size_t i = 0; i < all_equations.size(); i++) - if (eqs_to_delete_by_number.find(i) != eqs_to_delete_by_number.end()) + if (eqs_to_delete_by_number.contains(i)) { if (excluded_vars_change_type) { @@ -2600,7 +2600,7 @@ DynamicModel::removeEquations(const vector<pair<string, string>> &listed_eqs_by_ They become exogenous if they are still used somewhere, otherwise they are completely excluded from the model. */ for (auto ev : excluded_vars) - if (eqn_vars.find(ev) != eqn_vars.end()) + if (eqn_vars.contains(ev)) { symbol_table.changeType(ev, SymbolType::exogenous); cerr << "Variable '" << symbol_table.getName(ev) << "' turned into an exogenous, as its defining equation has been removed (but it still appears in an equation)" << endl; @@ -2700,8 +2700,7 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, for (int var = 0; var < block_size; var++) { for (int eq = 0; eq < block_size; eq++) - if (blocks_derivatives[blk].find({ eq, var, lag }) - != blocks_derivatives[blk].end()) + if (blocks_derivatives[blk].contains({ eq, var, lag })) { if (lag == -1) local_state_var.push_back(getBlockVariableID(blk, var)); @@ -2728,8 +2727,7 @@ DynamicModel::writeBlockDriverOutput(ostream &output, const string &basename, for (int other_endo : blocks_other_endo[blk]) { for (int eq = 0; eq < block_size; eq++) - if (blocks_derivatives_other_endo[blk].find({ eq, other_endo, lag }) - != blocks_derivatives_other_endo[blk].end()) + if (blocks_derivatives_other_endo[blk].contains({ eq, other_endo, lag })) { output << " " << ++count_lead_lag_incidence; goto other_endo_found; @@ -4308,7 +4306,7 @@ DynamicModel::computeRevXref(map<pair<int, int>, set<int>> &xrefset, const set<p for (const auto &it : eiref) { set<int> eq; - if (xrefset.find(it) != xrefset.end()) + if (xrefset.contains(it)) eq = xrefset[it]; eq.insert(eqn); xrefset[it] = eq; @@ -4393,19 +4391,19 @@ DynamicModel::determineBlockDerivativesType(int blk) equations[eq_orig]->collectEndogenous(endos_and_lags); for (int var = 0; var < size; var++) if (int var_orig = getBlockVariableID(blk, var); - endos_and_lags.find({ var_orig, lag }) != endos_and_lags.end()) + endos_and_lags.contains({ var_orig, lag })) { if (getBlockEquationType(blk, eq) == EquationType::evaluateRenormalized && eq < nb_recursive) /* It’s a normalized recursive equation, we have to recompute the derivative using the chain rule */ derivType[{ lag, eq, var }] = BlockDerivativeType::normalizedChainRule; - else if (derivType.find({ lag, eq, var }) == derivType.end()) + else if (!derivType.contains({ lag, eq, var })) derivType[{ lag, eq, var }] = BlockDerivativeType::standard; if (var < nb_recursive) for (int feedback_var = nb_recursive; feedback_var < size; feedback_var++) - if (derivType.find({ lag, var, feedback_var }) != derivType.end()) + if (derivType.contains({ lag, var, feedback_var })) /* A new derivative needs to be computed using the chain rule (a feedback variable appears in the recursive equation defining the current variable) */ @@ -4783,7 +4781,7 @@ DynamicModel::expandEqTags() { set<int> existing_tags = equation_tags.getEqnsByKey("name"); for (int eq = 0; eq < static_cast<int>(equations.size()); eq++) - if (existing_tags.find(eq) == existing_tags.end()) + if (!existing_tags.contains(eq)) if (auto lhs_expr = dynamic_cast<VariableNode *>(equations[eq]->arg1); lhs_expr && !equation_tags.exists("name", symbol_table.getName(lhs_expr->symb_id))) @@ -5679,7 +5677,7 @@ DynamicModel::substituteDiff(VarExpectationModelTable &var_expectation_model_tab for (const auto &equation : equations) equation->collectVariables(SymbolType::modelLocalVariable, used_local_vars); for (auto &it : local_variables_table) - if (used_local_vars.find(it.first) != used_local_vars.end()) + if (used_local_vars.contains(it.first)) it.second->findDiffNodes(diff_nodes); // Mark diff operators to be substituted in equations diff --git a/src/DynareMain.cc b/src/DynareMain.cc index 723d948a437862d4ae020c212b28b625e4f59e5f..fee13b3aa4e66cdc4b6d9737f713f0c43fe00ecd 100644 --- a/src/DynareMain.cc +++ b/src/DynareMain.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2003-2021 Dynare Team + * Copyright © 2003-2022 Dynare Team * * This file is part of Dynare. * @@ -442,7 +442,7 @@ main(int argc, char **argv) // Forbid some basenames, since they will cause trouble (see preprocessor#62) set<string> forbidden_basenames = { "T", "y", "x", "params", "steady_state", "it_", "true" }; - if (forbidden_basenames.find(basename) != forbidden_basenames.end()) + if (forbidden_basenames.contains(basename)) { cerr << "ERROR: Please use another name for your .mod file. The one you have chosen (" << argv[1] << ") conflicts with internal Dynare names." << endl; diff --git a/src/EquationTags.cc b/src/EquationTags.cc index 026c17397bcd4f083f6fd85dae630b0d31d74727..647a359755d4bc40b2a169f9683a09f5cb0dc2fc 100644 --- a/src/EquationTags.cc +++ b/src/EquationTags.cc @@ -27,7 +27,7 @@ EquationTags::getEqnsByKey(const string &key) const { set<int> retval; for (const auto & [eqn, tags] : eqn_tags) - if (tags.find(key) != tags.end()) + if (tags.contains(key)) retval.insert(eqn); return retval; } diff --git a/src/EquationTags.hh b/src/EquationTags.hh index c79b05006d700cf29c4d5b7241f0477932b06171..873b349ec66c1d8a3e55a17830183e26f9f9edb9 100644 --- a/src/EquationTags.hh +++ b/src/EquationTags.hh @@ -44,10 +44,10 @@ public: // Add multiple equation tags for the given equation inline void add(int eqn, map<string, string> tags) { - if (eqn_tags.find(eqn) == eqn_tags.end()) - eqn_tags[eqn] = move(tags); - else + if (eqn_tags.contains(eqn)) eqn_tags[eqn].insert(tags.begin(), tags.end()); + else + eqn_tags[eqn] = move(tags); } //! Add a single equation tag for the given equation @@ -112,13 +112,13 @@ public: inline bool exists(const int eqn) const { - return eqn_tags.find(eqn) != eqn_tags.end(); + return eqn_tags.contains(eqn); } //! Returns true if equation tag with key exists for a given equation inline bool exists(const int eqn, const string &key) const { - return exists(eqn) && eqn_tags.at(eqn).find(key) != eqn_tags.at(eqn).end(); + return exists(eqn) && eqn_tags.at(eqn).contains(key); } //! Returns true if equation tag with key and value exists for a given equation diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 6f2c3e89c46bcdbd72cf2ef45bc8db5b1264ded0..35738af681eb27fe65ce5ec39fce98b7e0e815de 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -39,7 +39,7 @@ ExprNode::getDerivative(int deriv_id) prepareForDerivation(); // Return zero if derivative is necessarily null (using symbolic a priori) - if (non_null_derivatives.find(deriv_id) == non_null_derivatives.end()) + if (!non_null_derivatives.contains(deriv_id)) return datatree.Zero; // If derivative is stored in cache, use the cached value, otherwise compute it (and cache it) @@ -93,7 +93,7 @@ ExprNode::checkIfTemporaryTermThenWrite(ostream &output, ExprNodeOutputType outp const temporary_terms_t &temporary_terms, const temporary_terms_idxs_t &temporary_terms_idxs) const { - if (temporary_terms.find(const_cast<ExprNode *>(this)) == temporary_terms.end()) + if (!temporary_terms.contains(const_cast<ExprNode *>(this))) return false; auto it2 = temporary_terms_idxs.find(const_cast<ExprNode *>(this)); @@ -348,7 +348,7 @@ ExprNode::fillErrorCorrectionRow(int eqn, exit(EXIT_FAILURE); } int colidx = static_cast<int>(distance(nontarget_lhs.begin(), find(nontarget_lhs.begin(), nontarget_lhs.end(), orig_vid))); - if (A0.find({eqn, colidx}) != A0.end()) + if (A0.contains({eqn, colidx})) { cerr << "ExprNode::fillErrorCorrection: Error filling A0 matrix: " << "symb_id encountered more than once in equation" << endl; @@ -364,10 +364,10 @@ ExprNode::fillErrorCorrectionRow(int eqn, datatree.AddPossiblyNegativeConstant(-constant)); if (param_id != -1) e = datatree.AddTimes(e, datatree.AddVariable(param_id)); - if (auto coor = make_pair(eqn, colidx); A0star.find(coor) == A0star.end()) - A0star[coor] = e; - else + if (auto coor = make_pair(eqn, colidx); A0star.contains(coor)) A0star[coor] = datatree.AddPlus(e, A0star[coor]); + else + A0star[coor] = e; } } } @@ -907,7 +907,7 @@ VariableNode::writeJsonOutput(ostream &output, const deriv_node_temp_terms_t &tef_terms, bool isdynamic) const { - if (temporary_terms.find(const_cast<VariableNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<VariableNode *>(this))) { output << "T" << idx; return; @@ -1332,7 +1332,7 @@ VariableNode::computeSubExprContainingVariable(int symb_id_arg, int lag_arg, set BinaryOpNode * VariableNode::normalizeEquationHelper(const set<expr_t> &contain_var, expr_t rhs) const { - assert(contain_var.count(const_cast<VariableNode *>(this)) > 0); + assert(contain_var.contains(const_cast<VariableNode *>(this))); if (get_type() == SymbolType::modelLocalVariable) return datatree.getLocalVariable(symb_id)->normalizeEquationHelper(contain_var, rhs); @@ -1547,9 +1547,10 @@ int VariableNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const { auto [lag_equiv_repr, index] = getLagEquivalenceClass(); - if (lhs_lag_equiv.find(lag_equiv_repr) == lhs_lag_equiv.end()) + if (lhs_lag_equiv.contains(lag_equiv_repr)) + return maxLag(); + else return 0; - return maxLag(); } expr_t @@ -2218,7 +2219,7 @@ UnaryOpNode::cost(const map<pair<int, int>, temporary_terms_t> &temp_terms_map, { // For a temporary term, the cost is null for (const auto &it : temp_terms_map) - if (it.second.find(const_cast<UnaryOpNode *>(this)) != it.second.end()) + if (it.second.contains(const_cast<UnaryOpNode *>(this))) return 0; return cost(arg->cost(temp_terms_map, is_matlab), is_matlab); @@ -2230,7 +2231,7 @@ UnaryOpNode::cost(const vector<vector<temporary_terms_t>> &blocks_temporary_term // For a temporary term, the cost is null for (const auto &blk_tt : blocks_temporary_terms) for (const auto &eq_tt : blk_tt) - if (eq_tt.find(const_cast<UnaryOpNode *>(this)) != eq_tt.end()) + if (eq_tt.contains(const_cast<UnaryOpNode *>(this))) return 0; return cost(arg->cost(blocks_temporary_terms, is_matlab), is_matlab); @@ -2513,7 +2514,7 @@ UnaryOpNode::writeJsonOutput(ostream &output, const deriv_node_temp_terms_t &tef_terms, bool isdynamic) const { - if (temporary_terms.find(const_cast<UnaryOpNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<UnaryOpNode *>(this))) { output << "T" << idx; return; @@ -3009,7 +3010,7 @@ UnaryOpNode::compile(ostream &CompileCode, unsigned int &instruction_number, const deriv_node_temp_terms_t &tef_terms) const { if (auto this2 = const_cast<UnaryOpNode *>(this); - temporary_terms.find(this2) != temporary_terms.end()) + temporary_terms.contains(this2)) { if (dynamic) { @@ -3052,14 +3053,14 @@ void UnaryOpNode::computeSubExprContainingVariable(int symb_id, int lag, set<expr_t> &contain_var) const { arg->computeSubExprContainingVariable(symb_id, lag, contain_var); - if (contain_var.count(arg) > 0) + if (contain_var.contains(arg)) contain_var.insert(const_cast<UnaryOpNode *>(this)); } BinaryOpNode * UnaryOpNode::normalizeEquationHelper(const set<expr_t> &contain_var, expr_t rhs) const { - assert(contain_var.count(const_cast<UnaryOpNode *>(this)) > 0); + assert(contain_var.contains(const_cast<UnaryOpNode *>(this))); switch (op_code) { @@ -3275,9 +3276,10 @@ int UnaryOpNode::VarMaxLag(const set<expr_t> &lhs_lag_equiv) const { auto [lag_equiv_repr, index] = getLagEquivalenceClass(); - if (lhs_lag_equiv.find(lag_equiv_repr) == lhs_lag_equiv.end()) + if (lhs_lag_equiv.contains(lag_equiv_repr)) + return arg->maxLag(); + else return 0; - return arg->maxLag(); } expr_t @@ -3603,7 +3605,7 @@ UnaryOpNode::substituteUnaryOpNodes(const lag_equivalence_table_t &nodes, subst_ else subst_table[rit->second] = dynamic_cast<VariableNode *>(aux_var->decreaseLeadsLags(base_index - rit->first)); - assert(subst_table.find(this) != subst_table.end()); + assert(subst_table.contains(this)); return const_cast<VariableNode *>(subst_table.at(this)); } @@ -3995,7 +3997,7 @@ int BinaryOpNode::precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const { // A temporary term behaves as a variable - if (temporary_terms.find(const_cast<BinaryOpNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<BinaryOpNode *>(this))) return 100; switch (op_code) @@ -4035,7 +4037,7 @@ int BinaryOpNode::precedenceJson(const temporary_terms_t &temporary_terms) const { // A temporary term behaves as a variable - if (temporary_terms.find(const_cast<BinaryOpNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<BinaryOpNode *>(this))) return 100; switch (op_code) @@ -4072,7 +4074,7 @@ BinaryOpNode::cost(const map<pair<int, int>, temporary_terms_t> &temp_terms_map, { // For a temporary term, the cost is null for (const auto &it : temp_terms_map) - if (it.second.find(const_cast<BinaryOpNode *>(this)) != it.second.end()) + if (it.second.contains(const_cast<BinaryOpNode *>(this))) return 0; int arg_cost = arg1->cost(temp_terms_map, is_matlab) + arg2->cost(temp_terms_map, is_matlab); @@ -4086,7 +4088,7 @@ BinaryOpNode::cost(const vector<vector<temporary_terms_t>> &blocks_temporary_ter // For a temporary term, the cost is null for (const auto &blk_tt : blocks_temporary_terms) for (const auto &eq_tt : blk_tt) - if (eq_tt.find(const_cast<BinaryOpNode *>(this)) != eq_tt.end()) + if (eq_tt.contains(const_cast<BinaryOpNode *>(this))) return 0; int arg_cost = arg1->cost(blocks_temporary_terms, is_matlab) + arg2->cost(blocks_temporary_terms, is_matlab); @@ -4277,7 +4279,7 @@ BinaryOpNode::compile(ostream &CompileCode, unsigned int &instruction_number, { // If current node is a temporary term if (auto this2 = const_cast<BinaryOpNode *>(this); - temporary_terms.find(this2) != temporary_terms.end()) + temporary_terms.contains(this2)) { if (dynamic) { @@ -4376,7 +4378,7 @@ BinaryOpNode::writeJsonOutput(ostream &output, bool isdynamic) const { // If current node is a temporary term - if (temporary_terms.find(const_cast<BinaryOpNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<BinaryOpNode *>(this))) { output << "T" << idx; return; @@ -4817,17 +4819,17 @@ BinaryOpNode::computeSubExprContainingVariable(int symb_id, int lag, set<expr_t> { arg1->computeSubExprContainingVariable(symb_id, lag, contain_var); arg2->computeSubExprContainingVariable(symb_id, lag, contain_var); - if (contain_var.count(arg1) > 0 || contain_var.count(arg2) > 0) + if (contain_var.contains(arg1) || contain_var.contains(arg2)) contain_var.insert(const_cast<BinaryOpNode *>(this)); } BinaryOpNode * BinaryOpNode::normalizeEquationHelper(const set<expr_t> &contain_var, expr_t rhs) const { - assert(contain_var.count(const_cast<BinaryOpNode *>(this)) > 0); + assert(contain_var.contains(const_cast<BinaryOpNode *>(this))); - bool arg1_contains_var = contain_var.count(arg1) > 0; - bool arg2_contains_var = contain_var.count(arg2) > 0; + bool arg1_contains_var = contain_var.contains(arg1); + bool arg2_contains_var = contain_var.contains(arg2); assert(arg1_contains_var || arg2_contains_var); if (arg1_contains_var && arg2_contains_var) @@ -4887,8 +4889,8 @@ BinaryOpNode::normalizeEquation(int symb_id, int lag) const set<expr_t> contain_var; computeSubExprContainingVariable(symb_id, lag, contain_var); - bool arg1_contains_var = contain_var.count(arg1) > 0; - bool arg2_contains_var = contain_var.count(arg2) > 0; + bool arg1_contains_var = contain_var.contains(arg1); + bool arg2_contains_var = contain_var.contains(arg2); assert(arg1_contains_var || arg2_contains_var); if (arg1_contains_var && arg2_contains_var) @@ -5521,7 +5523,7 @@ BinaryOpNode::getPacOptimizingShareAndExprNodesHelper(int lhs_symb_id, int lhs_o set<int> endogs; collectVariables(SymbolType::endogenous, endogs); // Test whether it contains the LHS in level - if (endogs.count(lhs_orig_symb_id) > 0) + if (endogs.contains(lhs_orig_symb_id)) { set<int> params; if (arg1->isParamTimesEndogExpr() && !arg2->isParamTimesEndogExpr()) @@ -5619,7 +5621,7 @@ BinaryOpNode::fillAutoregressiveRow(int eqn, const vector<int> &lhs, map<tuple<i if (find(lhs.begin(), lhs.end(), vid) == lhs.end()) continue; - if (AR.find({eqn, -lag, vid}) != AR.end()) + if (AR.contains({eqn, -lag, vid})) { cerr << "BinaryOpNode::fillAutoregressiveRow: Error filling AR matrix: " << "lag/symb_id encountered more than once in equation" << endl; @@ -5827,7 +5829,7 @@ int TrinaryOpNode::precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const { // A temporary term behaves as a variable - if (temporary_terms.find(const_cast<TrinaryOpNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<TrinaryOpNode *>(this))) return 100; switch (op_code) @@ -5845,7 +5847,7 @@ TrinaryOpNode::cost(const map<pair<int, int>, temporary_terms_t> &temp_terms_map { // For a temporary term, the cost is null for (const auto &it : temp_terms_map) - if (it.second.find(const_cast<TrinaryOpNode *>(this)) != it.second.end()) + if (it.second.contains(const_cast<TrinaryOpNode *>(this))) return 0; int arg_cost = arg1->cost(temp_terms_map, is_matlab) @@ -5861,7 +5863,7 @@ TrinaryOpNode::cost(const vector<vector<temporary_terms_t>> &blocks_temporary_te // For a temporary term, the cost is null for (const auto &blk_tt : blocks_temporary_terms) for (const auto &eq_tt : blk_tt) - if (eq_tt.find(const_cast<TrinaryOpNode *>(this)) != eq_tt.end()) + if (eq_tt.contains(const_cast<TrinaryOpNode *>(this))) return 0; int arg_cost = arg1->cost(blocks_temporary_terms, is_matlab) @@ -5976,7 +5978,7 @@ TrinaryOpNode::compile(ostream &CompileCode, unsigned int &instruction_number, { // If current node is a temporary term if (auto this2 = const_cast<TrinaryOpNode *>(this); - temporary_terms.find(this2) != temporary_terms.end()) + temporary_terms.contains(this2)) { if (dynamic) { @@ -6035,7 +6037,7 @@ TrinaryOpNode::writeJsonOutput(ostream &output, bool isdynamic) const { // If current node is a temporary term - if (temporary_terms.find(const_cast<TrinaryOpNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<TrinaryOpNode *>(this))) { output << "T" << idx; return; @@ -6206,7 +6208,7 @@ TrinaryOpNode::computeSubExprContainingVariable(int symb_id, int lag, set<expr_t arg1->computeSubExprContainingVariable(symb_id, lag, contain_var); arg2->computeSubExprContainingVariable(symb_id, lag, contain_var); arg3->computeSubExprContainingVariable(symb_id, lag, contain_var); - if (contain_var.count(arg1) > 0 || contain_var.count(arg2) > 0 || contain_var.count(arg3) > 0) + if (contain_var.contains(arg1) || contain_var.contains(arg2) || contain_var.contains(arg3)) contain_var.insert(const_cast<TrinaryOpNode *>(this)); } @@ -6937,7 +6939,7 @@ AbstractExternalFunctionNode::differentiateForwardVars(const vector<string> &sub bool AbstractExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, const deriv_node_temp_terms_t &tef_terms) const { - return tef_terms.find({ the_symb_id, arguments }) != tef_terms.end(); + return tef_terms.contains({ the_symb_id, arguments }); } int @@ -7073,7 +7075,7 @@ AbstractExternalFunctionNode::computeSubExprContainingVariable(int symb_id, int for (auto arg : arguments) { arg->computeSubExprContainingVariable(symb_id, lag, contain_var); - var_present = var_present || contain_var.count(arg) > 0; + var_present = var_present || contain_var.contains(arg); } if (var_present) contain_var.insert(const_cast<AbstractExternalFunctionNode *>(this)); @@ -7208,7 +7210,7 @@ ExternalFunctionNode::compile(ostream &CompileCode, unsigned int &instruction_nu const deriv_node_temp_terms_t &tef_terms) const { if (auto this2 = const_cast<ExternalFunctionNode *>(this); - temporary_terms.find(this2) != temporary_terms.end()) + temporary_terms.contains(this2)) { if (dynamic) { @@ -7300,7 +7302,7 @@ ExternalFunctionNode::writeJsonOutput(ostream &output, const deriv_node_temp_terms_t &tef_terms, bool isdynamic) const { - if (temporary_terms.find(const_cast<ExternalFunctionNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<ExternalFunctionNode *>(this))) { output << "T" << idx; return; @@ -7533,7 +7535,7 @@ FirstDerivExternalFunctionNode::writeJsonOutput(ostream &output, bool isdynamic) const { // If current node is a temporary term - if (temporary_terms.find(const_cast<FirstDerivExternalFunctionNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<FirstDerivExternalFunctionNode *>(this))) { output << "T" << idx; return; @@ -7601,7 +7603,7 @@ FirstDerivExternalFunctionNode::compile(ostream &CompileCode, unsigned int &inst const deriv_node_temp_terms_t &tef_terms) const { if (auto this2 = const_cast<FirstDerivExternalFunctionNode *>(this); - temporary_terms.find(this2) != temporary_terms.end()) + temporary_terms.contains(this2)) { if (dynamic) { @@ -7885,7 +7887,7 @@ SecondDerivExternalFunctionNode::writeJsonOutput(ostream &output, bool isdynamic) const { // If current node is a temporary term - if (temporary_terms.find(const_cast<SecondDerivExternalFunctionNode *>(this)) != temporary_terms.end()) + if (temporary_terms.contains(const_cast<SecondDerivExternalFunctionNode *>(this))) { output << "T" << idx; return; diff --git a/src/ExternalFunctionsTable.hh b/src/ExternalFunctionsTable.hh index 6c4a4d4530eb0346842cdaaad634c7f6766f9e97..59ac58f96151a99adf3d823d1727e15480522249 100644 --- a/src/ExternalFunctionsTable.hh +++ b/src/ExternalFunctionsTable.hh @@ -79,7 +79,7 @@ public: inline bool ExternalFunctionsTable::exists(int symb_id) const { - return externalFunctionTable.find(symb_id) != externalFunctionTable.end(); + return externalFunctionTable.contains(symb_id); } inline int diff --git a/src/ModFile.cc b/src/ModFile.cc index e1c0111155b7c0b9218149af6b57ababb302d8cd..2c468a4792cf25712dbf03c3679c88fb6c241137 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -83,7 +83,7 @@ ModFile::evalAllExpressions(bool warn_uninit) if (auto type = symbol_table.getType(id); (type == SymbolType::endogenous || type == SymbolType::exogenous || type == SymbolType::exogenousDet || type == SymbolType::parameter || type == SymbolType::modelLocalVariable) - && global_eval_context.find(id) == global_eval_context.end()) + && !global_eval_context.contains(id)) { if (warn_uninit) warnings << "WARNING: Can't find a numeric initial value for " diff --git a/src/ModelTree.cc b/src/ModelTree.cc index a78a57b767cc87449aadf284d65a7676377a3be3..bd96cf0e00fa4f25c64fd6c16e8503a6e492b9b0 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -484,7 +484,7 @@ ModelTree::equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &fi { set<pair<int, int>> result; derivative->collectEndogenous(result); - bool variable_not_in_derivative = result.find({ var, 0 }) == result.end(); + bool variable_not_in_derivative = !result.contains({ var, 0 }); try { @@ -790,8 +790,8 @@ ModelTree::reduceBlockDecomposition() bool is_lead = false, is_lag = false; for (int var = 0; var < blocks[blk-1].size; var++) { - is_lag = is_lag || endos_and_lags.find({ getBlockVariableID(blk-1, var), -1 }) != endos_and_lags.end(); - is_lead = is_lead || endos_and_lags.find({ getBlockVariableID(blk-1, var), 1 }) != endos_and_lags.end(); + is_lag = is_lag || endos_and_lags.contains({ getBlockVariableID(blk-1, var), -1 }); + is_lead = is_lead || endos_and_lags.contains({ getBlockVariableID(blk-1, var), 1 }); } if ((blocks[blk-1].simulation_type == BlockSimulationType::evaluateForward @@ -837,8 +837,7 @@ ModelTree::determineLinearBlocks() set<pair<int, int>> endogenous; d1->collectEndogenous(endogenous); for (int l = 0; l < blocks[blk].size; l++) - if (endogenous.find({ endo_idx_block2orig[blocks[blk].first_equation+l], 0 }) - != endogenous.end()) + if (endogenous.contains({ endo_idx_block2orig[blocks[blk].first_equation+l], 0 })) { blocks[blk].linear = false; goto the_end; @@ -855,8 +854,7 @@ ModelTree::determineLinearBlocks() set<pair<int, int>> endogenous; d1->collectEndogenous(endogenous); for (int l = 0; l < blocks[blk].size; l++) - if (endogenous.find({ endo_idx_block2orig[blocks[blk].first_equation+l], lag }) - != endogenous.end()) + if (endogenous.contains({ endo_idx_block2orig[blocks[blk].first_equation+l], lag })) { blocks[blk].linear = false; goto the_end2; @@ -1302,7 +1300,7 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, bool write_tef_terms, d output << R"("model_local_variables": [)"; bool printed = false; for (int id : local_variables_vector) - if (used_local_vars.find(id) != used_local_vars.end()) + if (used_local_vars.contains(id)) { if (printed) output << ", "; @@ -1583,7 +1581,7 @@ void ModelTree::addTrendVariables(const vector<int> &trend_vars, expr_t growth_factor) noexcept(false) { for (int id : trend_vars) - if (trend_symbols_map.find(id) != trend_symbols_map.end()) + if (trend_symbols_map.contains(id)) throw TrendException(symbol_table.getName(id)); else trend_symbols_map[id] = growth_factor; @@ -1593,7 +1591,7 @@ void ModelTree::addNonstationaryVariables(const vector<int> &nonstationary_vars, bool log_deflator, expr_t deflator) noexcept(false) { for (int id : nonstationary_vars) - if (nonstationary_symbols_map.find(id) != nonstationary_symbols_map.end()) + if (nonstationary_symbols_map.contains(id)) throw TrendException(symbol_table.getName(id)); else nonstationary_symbols_map[id] = { log_deflator, deflator }; @@ -1702,7 +1700,7 @@ ModelTree::computeParamsDerivativesTemporaryTerms() bool ModelTree::isNonstationary(int symb_id) const { - return nonstationary_symbols_map.find(symb_id) != nonstationary_symbols_map.end(); + return nonstationary_symbols_map.contains(symb_id); } void diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 0f0181e280707d5b870b0b073f6be98e2f016697..0c0be897be1158285dd422101fed18127d9731b6 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -42,8 +42,7 @@ ParsingDriver::symbol_exists_and_is_not_modfile_local_or_external_function(const void ParsingDriver::check_symbol_existence_in_model_block(const string &name) { - if (!mod_file->symbol_table.exists(name) - || undeclared_model_vars.find(name) != undeclared_model_vars.end()) + if (!mod_file->symbol_table.exists(name) || undeclared_model_vars.contains(name)) undeclared_model_variable_error("Unknown symbol: " + name, name); } @@ -306,7 +305,7 @@ ParsingDriver::predetermined_variables(const vector<string> &symbol_list) void ParsingDriver::add_equation_tags(string key, string value) { - if (eq_tags.find(key) != eq_tags.end()) + if (eq_tags.contains(key)) error("Tag '" + key + "' cannot be declared twice for the same equation"); eq_tags[key] = value; @@ -594,7 +593,7 @@ ParsingDriver::hist_val(const string &name, const string &lag, expr_t rhs) pair<int, int> key(symb_id, ilag); - if (hist_values.find(key) != hist_values.end()) + if (hist_values.contains(key)) error("hist_val: (" + name + ", " + lag + ") declared twice"); hist_values[move(key)] = rhs; @@ -643,7 +642,7 @@ void ParsingDriver::add_generate_irfs_exog_element(string exo, const string &value) { check_symbol_is_exogenous(exo, false); - if (generate_irf_exos.find(exo) != generate_irf_exos.end()) + if (generate_irf_exos.contains(exo)) error("You have set the exogenous variable " + exo + " twice."); generate_irf_exos[move(exo)] = stod(value); @@ -981,9 +980,8 @@ ParsingDriver::add_det_shock(const string &var, const vector<pair<int, int>> &pe int symb_id = mod_file->symbol_table.getID(var); - if (det_shocks.find(symb_id) != det_shocks.end() - || learnt_shocks_add.find(symb_id) != learnt_shocks_add.end() - || learnt_shocks_multiply.find(symb_id) != learnt_shocks_multiply.end()) + if (det_shocks.contains(symb_id) || learnt_shocks_add.contains(symb_id) + || learnt_shocks_multiply.contains(symb_id)) error("shocks/conditional_forecast_paths: variable " + var + " declared twice"); if (periods.size() != values.size()) @@ -1016,8 +1014,8 @@ ParsingDriver::add_heteroskedastic_shock(const string &var, const vector<pair<in int symb_id = mod_file->symbol_table.getID(var); - if ((!scales && heteroskedastic_shocks_values.find(symb_id) != heteroskedastic_shocks_values.end()) - || (scales && heteroskedastic_shocks_scales.find(symb_id) != heteroskedastic_shocks_scales.end())) + if ((!scales && heteroskedastic_shocks_values.contains(symb_id)) + || (scales && heteroskedastic_shocks_scales.contains(symb_id))) error("heteroskedastic_shocks: variable " + var + " declared twice"); if (periods.size() != values.size()) @@ -1046,8 +1044,7 @@ ParsingDriver::add_stderr_shock(const string &var, expr_t value) check_symbol_existence(var); int symb_id = mod_file->symbol_table.getID(var); - if (var_shocks.find(symb_id) != var_shocks.end() - || std_shocks.find(symb_id) != std_shocks.end()) + if (var_shocks.contains(symb_id) || std_shocks.contains(symb_id)) error("shocks: variance or stderr of shock on " + var + " declared twice"); std_shocks[symb_id] = value; @@ -1066,8 +1063,7 @@ ParsingDriver::add_var_shock(const string &var, expr_t value) check_symbol_existence(var); int symb_id = mod_file->symbol_table.getID(var); - if (var_shocks.find(symb_id) != var_shocks.end() - || std_shocks.find(symb_id) != std_shocks.end()) + if (var_shocks.contains(symb_id) || std_shocks.contains(symb_id)) error("shocks: variance or stderr of shock on " + var + " declared twice"); var_shocks[symb_id] = value; @@ -1090,10 +1086,8 @@ ParsingDriver::add_covar_shock(const string &var1, const string &var2, expr_t va pair<int, int> key(symb_id1, symb_id2), key_inv(symb_id2, symb_id1); - if (covar_shocks.find(key) != covar_shocks.end() - || covar_shocks.find(key_inv) != covar_shocks.end() - || corr_shocks.find(key) != corr_shocks.end() - || corr_shocks.find(key_inv) != corr_shocks.end()) + if (covar_shocks.contains(key) || covar_shocks.contains(key_inv) + || corr_shocks.contains(key) || corr_shocks.contains(key_inv)) error("shocks: covariance or correlation shock on variable pair (" + var1 + ", " + var2 + ") declared twice"); @@ -1117,10 +1111,8 @@ ParsingDriver::add_correl_shock(const string &var1, const string &var2, expr_t v pair<int, int> key(symb_id1, symb_id2), key_inv(symb_id2, symb_id1); - if (covar_shocks.find(key) != covar_shocks.end() - || covar_shocks.find(key_inv) != covar_shocks.end() - || corr_shocks.find(key) != corr_shocks.end() - || corr_shocks.find(key_inv) != corr_shocks.end()) + if (covar_shocks.contains(key) || covar_shocks.contains(key_inv) + || corr_shocks.contains(key) || corr_shocks.contains(key_inv)) error("shocks: covariance or correlation shock on variable pair (" + var1 + ", " + var2 + ") declared twice"); @@ -1185,7 +1177,7 @@ ParsingDriver::add_restriction_in_equation(const string &equation, const vector< if (eqn < 1) error("equation numbers must be greater than or equal to 1."); - if (svar_equation_restrictions.count(eqn) > 0) + if (svar_equation_restrictions.contains(eqn)) error("equation number " + equation + " referenced more than once under a single lag."); vector<int> svar_restriction_symbols; @@ -1387,8 +1379,7 @@ ParsingDriver::steady() void ParsingDriver::option_num(string name_option, string opt1, string opt2) { - if (options_list.paired_num_options.find(name_option) - != options_list.paired_num_options.end()) + if (options_list.paired_num_options.contains(name_option)) error("option " + name_option + " declared twice"); options_list.paired_num_options[move(name_option)] = { move(opt1), move(opt2) }; @@ -1397,7 +1388,7 @@ ParsingDriver::option_num(string name_option, string opt1, string opt2) void ParsingDriver::option_num(string name_option, string opt) { - if (options_list.num_options.find(name_option) != options_list.num_options.end()) + if (options_list.num_options.contains(name_option)) error("option " + name_option + " declared twice"); options_list.num_options[move(name_option)] = move(opt); @@ -1406,8 +1397,7 @@ ParsingDriver::option_num(string name_option, string opt) void ParsingDriver::option_str(string name_option, string opt) { - if (options_list.string_options.find(name_option) - != options_list.string_options.end()) + if (options_list.string_options.contains(name_option)) error("option " + name_option + " declared twice"); options_list.string_options[move(name_option)] = move(opt); @@ -1416,8 +1406,7 @@ ParsingDriver::option_str(string name_option, string opt) void ParsingDriver::option_date(string name_option, string opt) { - if (options_list.date_options.find(name_option) - != options_list.date_options.end()) + if (options_list.date_options.contains(name_option)) error("option " + name_option + " declared twice"); options_list.date_options[move(name_option)] = move(opt); @@ -1426,8 +1415,7 @@ ParsingDriver::option_date(string name_option, string opt) void ParsingDriver::option_symbol_list(string name_option, vector<string> symbol_list) { - if (options_list.symbol_list_options.find(name_option) - != options_list.symbol_list_options.end()) + if (options_list.symbol_list_options.contains(name_option)) error("option " + name_option + " declared twice"); if (name_option.compare("irf_shocks") == 0) @@ -1454,8 +1442,7 @@ ParsingDriver::option_symbol_list(string name_option, vector<string> symbol_list void ParsingDriver::option_vec_int(string name_option, vector<int> opt) { - if (options_list.vector_int_options.find(name_option) - != options_list.vector_int_options.end()) + if (options_list.vector_int_options.contains(name_option)) error("option " + name_option + " declared twice"); if (opt.empty()) @@ -1467,8 +1454,7 @@ ParsingDriver::option_vec_int(string name_option, vector<int> opt) void ParsingDriver::option_vec_str(string name_option, vector<string> opt) { - if (options_list.vector_str_options.find(name_option) - != options_list.vector_str_options.end()) + if (options_list.vector_str_options.contains(name_option)) error("option " + name_option + " declared twice"); if (opt.empty()) @@ -1480,8 +1466,7 @@ ParsingDriver::option_vec_str(string name_option, vector<string> opt) void ParsingDriver::option_vec_cellstr(string name_option, vector<string> opt) { - if (options_list.vector_cellstr_options.find(name_option) - != options_list.vector_cellstr_options.end()) + if (options_list.vector_cellstr_options.contains(name_option)) error("option " + name_option + " declared twice"); if (opt.empty()) @@ -1506,7 +1491,7 @@ void ParsingDriver::stoch_simul(SymbolList symbol_list) { //make sure default order is known to preprocessor, see #49 - if (options_list.num_options.find("order") == options_list.num_options.end()) + if (!options_list.num_options.contains("order")) options_list.num_options["order"] = "2"; symbol_list.removeDuplicates("stoch_simul", warnings); @@ -1701,7 +1686,7 @@ ParsingDriver::copy_subsamples(string to_name1, string to_name2, string from_nam if (!from_name2.empty()) check_symbol_existence(from_name2); - if (subsample_declarations.find({ from_name1, from_name2 }) == subsample_declarations.end()) + if (!subsample_declarations.contains({ from_name1, from_name2 })) { string err{from_name1}; if (!from_name2.empty()) @@ -1728,7 +1713,7 @@ ParsingDriver::check_symbol_is_statement_variable(const string &name) void ParsingDriver::set_subsample_name_equal_to_date_range(string name, string date1, string date2) { - if (subsample_declaration_map.find(name) != subsample_declaration_map.end()) + if (subsample_declaration_map.contains(name)) error("Symbol " + name + " may only be assigned once in a SUBSAMPLE statement"); subsample_declaration_map[move(name)] = { move(date1), move(date2) }; } @@ -1766,7 +1751,7 @@ ParsingDriver::check_subsample_declaration_exists(const string &name1, const str } auto tmp_map = it->second; - if (tmp_map.find(subsample_name) == tmp_map.end()) + if (!tmp_map.contains(subsample_name)) error("The subsample name " + subsample_name + " was not previously declared in a subsample statement."); } @@ -2027,7 +2012,7 @@ void ParsingDriver::set_trend_element(string arg1, expr_t arg2) { check_symbol_existence(arg1); - if (trend_elements.find(arg1) != trend_elements.end()) + if (trend_elements.contains(arg1)) error("observation_trends: " + arg1 + " declared twice"); trend_elements[move(arg1)] = arg2; } @@ -2055,7 +2040,7 @@ ParsingDriver::set_filter_initial_state_element(const string &name, const string if ((type == SymbolType::exogenous || type == SymbolType::exogenousDet) && ilag == 0) error("filter_initial_state: exogenous variable " + name + " must be provided with a lag"); - if (filter_initial_state_elements.find({ symb_id, ilag }) != filter_initial_state_elements.end()) + if (filter_initial_state_elements.contains({ symb_id, ilag })) error("filter_initial_state: (" + name + ", " + lag + ") declared twice"); if (mod_file->dynamic_model.minLagForSymbol(symb_id) > ilag - 1) @@ -2068,7 +2053,7 @@ void ParsingDriver::set_optim_weights(string name, expr_t value) { check_symbol_is_endogenous(name); - if (var_weights.find(name) != var_weights.end()) + if (var_weights.contains(name)) error("optim_weights: " + name + " declared twice"); var_weights[move(name)] = move(value); } @@ -2081,7 +2066,7 @@ ParsingDriver::set_optim_weights(const string &name1, const string &name2, expr_ pair<string, string> covar_key{name1, name2}; - if (covar_weights.find(covar_key) != covar_weights.end()) + if (covar_weights.contains(covar_key)) error("optim_weights: pair of variables (" + name1 + ", " + name2 + ") declared twice"); @@ -2420,9 +2405,9 @@ ParsingDriver::ms_variance_decomposition() void ParsingDriver::svar() { - bool has_coefficients = options_list.string_options.find("ms.coefficients") != options_list.string_options.end(), - has_variances = options_list.string_options.find("ms.variances") != options_list.string_options.end(), - has_constants = options_list.string_options.find("ms.constants") != options_list.string_options.end(); + bool has_coefficients = options_list.string_options.contains("ms.coefficients"), + has_variances = options_list.string_options.contains("ms.variances"), + has_constants = options_list.string_options.contains("ms.constants"); if (!has_coefficients && !has_variances && !has_constants) error("You must pass one of 'coefficients', 'variances', or 'constants'."); @@ -2461,7 +2446,7 @@ ParsingDriver::markov_switching() else if (stoi(it0->second) <= 0) error("The value passed to the number_of_regimes option must be greater than zero."); - if (options_list.num_options.find("ms.duration") == options_list.num_options.end()) + if (!options_list.num_options.contains("ms.duration")) error("A duration option must be passed to the markov_switching statement."); mod_file->addStatement(make_unique<MarkovSwitchingStatement>(options_list)); @@ -2555,7 +2540,7 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2) { expr_t id = model_tree->AddEqual(arg1, arg2); - if (eq_tags.find("static") != eq_tags.end()) + if (eq_tags.contains("static")) { // If the equation is tagged [static] if (!id->isInStaticForm()) @@ -2563,11 +2548,10 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2) dynamic_model->addStaticOnlyEquation(id, location.begin.line, eq_tags); } - else if (eq_tags.find("bind") != eq_tags.end() - || eq_tags.find("relax") != eq_tags.end()) + else if (eq_tags.contains("bind") || eq_tags.contains("relax")) { // If the equation has a “bind” or “relax” tag (occbin case) - if (eq_tags.find("name") == eq_tags.end()) + if (!eq_tags.contains("name")) error("An equation with a 'bind' or 'relax' tag must have a 'name' tag"); auto regimes_bind = strsplit(eq_tags["bind"], ','); auto regimes_relax = strsplit(eq_tags["relax"], ','); @@ -3161,7 +3145,7 @@ ParsingDriver::add_model_var_or_external_function(const string &function_name, b } else { // e.g. model_var(lag) => ADD MODEL VARIABLE WITH LEAD (NumConstNode)/LAG (UnaryOpNode) - if (undeclared_model_vars.find(function_name) != undeclared_model_vars.end()) + if (undeclared_model_vars.contains(function_name)) undeclared_model_variable_error("Unknown symbol: " + function_name, function_name); pair<bool, double> rv = is_there_one_integer_argument(); diff --git a/src/StaticModel.cc b/src/StaticModel.cc index 3123b088bfe0dd06cdd590bd59f9ab94d6509cda..23769b1872b3414653cecceba03f3e5e88fc23cb 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -69,7 +69,7 @@ StaticModel::StaticModel(const DynamicModel &m) : try { // If equation is dynamic, replace it by an equation marked [static] - if (dynamic_equations.find(i) != dynamic_equations.end()) + if (dynamic_equations.contains(i)) { auto [static_only_equations, static_only_equations_lineno, diff --git a/src/SubModel.cc b/src/SubModel.cc index 3b8233dd66df453a4b43b342af9e0103638e6189..0438a7c05ca370d869a14e14de07d8f28c783f94 100644 --- a/src/SubModel.cc +++ b/src/SubModel.cc @@ -774,7 +774,7 @@ VarExpectationModelTable::addVarExpectationModel(string name_arg, expr_t express bool VarExpectationModelTable::isExistingVarExpectationModelName(const string &name_arg) const { - return names.find(name_arg) != names.end(); + return names.contains(name_arg); } bool @@ -923,7 +923,7 @@ VarExpectationModelTable::transformPass(ExprNode::subst_table_t &diff_subst_tabl dynamic_model.AddVariable(variable, -lag + time_shift[name]))); } - if (var_expectation_subst_table.find(name) != var_expectation_subst_table.end()) + if (var_expectation_subst_table.contains(name)) { cerr << "ERROR: model name '" << name << "' is used by several var_expectation_model statements" << endl; exit(EXIT_FAILURE); @@ -987,7 +987,7 @@ PacModelTable::addPacModel(string name_arg, string aux_model_name_arg, string di bool PacModelTable::isExistingPacModelName(const string &name_arg) const { - return names.find(name_arg) != names.end(); + return names.contains(name_arg); } bool @@ -1002,7 +1002,7 @@ PacModelTable::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation for (auto &[name, gv] : growth) if (gv) { - if (target_info.find(name) != target_info.end()) + if (target_info.contains(name)) { cerr << "ERROR: for PAC model '" << name << "', it is not possible to declare a 'growth' option in the 'pac_model' command when there is also a 'pac_target_info' block" << endl; exit(EXIT_FAILURE); @@ -1011,7 +1011,7 @@ PacModelTable::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation } for (auto &[name, auxn] : auxname) - if (!auxn.empty() && target_info.find(name) != target_info.end()) + if (!auxn.empty() && target_info.contains(name)) { cerr << "ERROR: for PAC model '" << name << "', it is not possible to declare an 'auxname' option in the 'pac_model' command when there is also a 'pac_target_info' block" << endl; exit(EXIT_FAILURE); @@ -1020,7 +1020,7 @@ PacModelTable::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation for (auto &[name, k] : kind) if (k != PacTargetKind::unspecified) { - if (target_info.find(name) != target_info.end()) + if (target_info.contains(name)) { cerr << "ERROR: for PAC model '" << name << "', it is not possible to declare a 'kind' option in the 'pac_model' command when there is also a 'pac_target_info' block" << endl; exit(EXIT_FAILURE); @@ -1146,7 +1146,7 @@ PacModelTable::transformPass(const lag_equivalence_table_t &unary_ops_nodes, } // Perform transformations for the pac_target_info block (if any) - if (target_info.find(name) != target_info.end()) + if (target_info.contains(name)) { // Substitute unary ops and diffs in the target… expr_t &target = get<0>(target_info[name]); @@ -1326,7 +1326,7 @@ PacModelTable::transformPass(const lag_equivalence_table_t &unary_ops_nodes, growth_correction_term = dynamic_model.AddTimes(growth[name], dynamic_model.AddVariable(growth_neutrality_params[name])); if (aux_model_name[name].empty()) { - if (target_info.find(name) != target_info.end()) + if (target_info.contains(name)) { cerr << "ERROR: the block 'pac_target_info(" << name << ")' is not supported in the context of a PAC model with model-consistent expectations (MCE)." << endl; exit(EXIT_FAILURE); @@ -1344,7 +1344,7 @@ PacModelTable::transformPass(const lag_equivalence_table_t &unary_ops_nodes, } else { - if (target_info.find(name) != target_info.end()) + if (target_info.contains(name)) { assert(growth_correction_term == dynamic_model.Zero); dynamic_model.computePacBackwardExpectationSubstitutionWithComponents(name, lhs[name], diff --git a/src/SubModel.hh b/src/SubModel.hh index 3bb4263305b5e634c2c0ea530581ecc1462a66dc..af19c6dbe6442cd98226cdf4f63191d37078f9ce 100644 --- a/src/SubModel.hh +++ b/src/SubModel.hh @@ -108,7 +108,7 @@ private: inline bool TrendComponentModelTable::isExistingTrendComponentModelName(const string &name_arg) const { - return names.find(name_arg) != names.end(); + return names.contains(name_arg); } inline bool @@ -181,7 +181,7 @@ private: inline bool VarModelTable::isExistingVarModelName(const string &name_arg) const { - return names.find(name_arg) != names.end(); + return names.contains(name_arg); } inline bool diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index c1050843749cbf34eb6b44382fb47aa1adffd1c3..8d4cc8d34aa64a18a85aa09c6bb7f03f1c8852b1 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -797,7 +797,7 @@ bool SymbolTable::isPredetermined(int symb_id) const noexcept(false) { validateSymbID(symb_id); - return predetermined_variables.find(symb_id) != predetermined_variables.end(); + return predetermined_variables.contains(symb_id); } int diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index 0972173a4fa4a59dbfb585de731b80f4bf7fd585..3d7e28aec3ce1b8c6e72b54cd6aff08230a25e73 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -480,7 +480,7 @@ SymbolTable::validateSymbID(int symb_id) const noexcept(false) inline bool SymbolTable::exists(const string &name) const { - return symbol_table.find(name) != symbol_table.end(); + return symbol_table.contains(name); } inline string diff --git a/src/macro/Environment.cc b/src/macro/Environment.cc index 883adf67baff8c4ec9e8a0a6659b04a84a3eb492..7e568fa3d31d5ed68216420ae1a13008351d8d00 100644 --- a/src/macro/Environment.cc +++ b/src/macro/Environment.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2019-2020 Dynare Team + * Copyright © 2019-2022 Dynare Team * * This file is part of Dynare. * @@ -26,7 +26,7 @@ void Environment::define(VariablePtr var, ExpressionPtr value) { string name = var->getName(); - if (functions.count(name)) + if (functions.contains(name)) throw StackTrace("Variable " + name + " was previously defined as a function"); variables[move(name)] = value->eval(*this); } @@ -35,7 +35,7 @@ void Environment::define(FunctionPtr func, ExpressionPtr value) { string name = func->getName(); - if (variables.count(name)) + if (variables.contains(name)) throw StackTrace("Variable " + name + " was previously defined as a variable"); functions[name] = {move(func), move(value)}; }