From ecdca502aaed1233a815f7ac8ef5c72c7c9a4ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Thu, 24 Oct 2019 10:49:13 +0200 Subject: [PATCH] Modernization: stop using make_pair() and make_tuple() In many cases, they can be replaced by the curly braces syntax. Otherwise, we can now use the pair() and tuple() constructors, without the need to specify template parameters, thanks to class template argument deduction (new in C++17). --- src/ComputingTasks.cc | 2 +- src/DynamicModel.cc | 4 ++-- src/DynamicModel.hh | 2 +- src/DynareBison.yy | 42 +++++++++++++++++++++--------------------- src/ExprNode.cc | 4 ++-- src/ModelTree.hh | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 0c097a77..4201c811 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -1377,7 +1377,7 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo if (it.type == 3) // Correlation { // Use lexical ordering for the pair of symbols - pair<string, string> x = it.name < it.name2 ? make_pair(it.name, it.name2) : make_pair(it.name2, it.name); + auto x = it.name < it.name2 ? pair(it.name, it.name2) : pair(it.name2, it.name); if (already_declared_corr.find(x) == already_declared_corr.end()) already_declared_corr.insert(x); diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index cc6ff713..607bc284 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -3469,7 +3469,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de if ((i < n_obs) || (i >= nb_diag + n_obs) || (j1 >= nb_diag)) for (int k = n_obs; k < i_nz_state_var[i]; k++) { - v_index_KF.emplace_back(i + j1 * n, make_pair(i + k * n, k + j1_n_state)); + v_index_KF.emplace_back(i + j1 * n, pair(i + k * n, k + j1_n_state)); } } int size_v_index_KF = v_index_KF.size(); @@ -3488,7 +3488,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de for (int k = n_obs; k < i_nz_state_var[j]; k++) { int k_n = k * n; - v_index_KF_2.emplace_back(i * n + j, make_pair(i + k_n - n_n_obs, j + k_n)); + v_index_KF_2.emplace_back(i * n + j, pair(i + k_n - n_n_obs, j + k_n)); } } int size_v_index_KF_2 = v_index_KF_2.size(); diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 4ec2244a..b8bc1495 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -507,7 +507,7 @@ public: //! Fills eval context with values of model local variables and auxiliary variables void fillEvalContext(eval_context_t &eval_context) const; - auto getStaticOnlyEquationsInfo() const { return make_tuple(static_only_equations, static_only_equations_lineno, static_only_equations_equation_tags); }; + auto getStaticOnlyEquationsInfo() const { return tuple(static_only_equations, static_only_equations_lineno, static_only_equations_equation_tags); }; //! Return the number of blocks unsigned int diff --git a/src/DynareBison.yy b/src/DynareBison.yy index 8839deeb..ca6ce508 100644 --- a/src/DynareBison.yy +++ b/src/DynareBison.yy @@ -562,7 +562,7 @@ parameters : PARAMETERS parameter_list ';'; model_local_variable : MODEL_LOCAL_VARIABLE model_local_variable_list ';'; named_var_elem : symbol EQUAL QUOTED_STRING - { $$ = make_pair($1, $3); } + { $$ = { $1, $3 }; } named_var_1 : '(' named_var_elem { $$ = vector<pair<string, string>>{$2}; } @@ -1820,11 +1820,11 @@ subsamples_eq : subsamples_eq_opt EQUAL subsamples_eq_opt ';' ; subsamples_eq_opt : symbol '.' SUBSAMPLES - { $$ = make_pair($1, ""); } + { $$ = { $1, "" }; } | STD '(' symbol ')' '.' SUBSAMPLES - { $$ = make_pair($3, ""); } + { $$ = { $3, "" }; } | CORR '(' symbol COMMA symbol ')' '.' SUBSAMPLES - { $$ = make_pair($3, $5); } + { $$ = { $3, $5 }; } ; subsamples_name_list : subsamples_name_list COMMA o_subsample_name @@ -1885,17 +1885,17 @@ prior_eq : prior_eq_opt EQUAL prior_eq_opt ';' ; prior_eq_opt : symbol '.' PRIOR - { $$ = make_tuple("par", $1, "", ""); } + { $$ = { "par", $1, "", "" }; } | symbol '.' symbol '.' PRIOR - { $$ = make_tuple("par", $1, "", $3); } + { $$ = { "par", $1, "", $3 }; } | STD '(' symbol ')' '.' PRIOR - { $$ = make_tuple("std", $3, "", ""); } + { $$ = { "std", $3, "", "" }; } | STD '(' symbol ')' '.' symbol '.' PRIOR - { $$ = make_tuple("std", $3, "", $6); } + { $$ = { "std", $3, "", $6 }; } | CORR '(' symbol COMMA symbol ')' '.' PRIOR - { $$ = make_tuple("corr", $3, $5, ""); } + { $$ = { "corr", $3, $5, "" }; } | CORR '(' symbol COMMA symbol ')' '.' symbol '.' PRIOR - { $$ = make_tuple("corr", $3, $5, $8); } + { $$ = { "corr", $3, $5, $8 }; } ; options : symbol '.' OPTIONS '(' options_options_list ')' ';' @@ -1927,17 +1927,17 @@ options_eq : options_eq_opt EQUAL options_eq_opt ';' ; options_eq_opt : symbol '.' OPTIONS - { $$ = make_tuple("par", $1, "", ""); } + { $$ = { "par", $1, "", "" }; } | symbol '.' symbol '.' OPTIONS - { $$ = make_tuple("par", $1, "", $3); } + { $$ = { "par", $1, "", $3 }; } | STD '(' symbol ')' '.' OPTIONS - { $$ = make_tuple("std", $3, "", ""); } + { $$ = { "std", $3, "", "" }; } | STD '(' symbol ')' '.' symbol '.' OPTIONS - { $$ = make_tuple("std", $3, "", $6); } + { $$ = { "std", $3, "", $6 }; } | CORR '(' symbol COMMA symbol ')' '.' OPTIONS - { $$ = make_tuple("corr", $3, $5, ""); } + { $$ = { "corr", $3, $5, "" }; } | CORR '(' symbol COMMA symbol ')' '.' symbol '.' OPTIONS - { $$ = make_tuple("corr", $3, $5, $8); } + { $$ = { "corr", $3, $5, $8 }; } ; estimation : ESTIMATION ';' @@ -3010,11 +3010,11 @@ model_diagnostics : MODEL_DIAGNOSTICS ';' ; calibration_range : '[' expression COMMA expression ']' - { $$ = make_pair($2, $4); } + { $$ = { $2, $4 }; } | PLUS - { $$ = make_pair(driver.add_non_negative_constant("0"), driver.add_inf_constant()); } + { $$ = { driver.add_non_negative_constant("0"), driver.add_inf_constant() }; } | MINUS - { $$ = make_pair(driver.add_uminus(driver.add_inf_constant()), driver.add_non_negative_constant("0")); } + { $$ = { driver.add_uminus(driver.add_inf_constant()), driver.add_non_negative_constant("0") }; } ; moment_calibration : MOMENT_CALIBRATION ';' moment_calibration_list END ';' @@ -3763,9 +3763,9 @@ integer_range : INT_NUMBER ':' INT_NUMBER { $$ = $1 + ':' + $3; } integer_range_w_inf : INT_NUMBER ':' INT_NUMBER - { $$ = make_pair($1, $3); } + { $$ = { $1, $3 }; } | INT_NUMBER ':' INF_CONSTANT - { $$ = make_pair($1, "Inf"); } + { $$ = { $1, "Inf" }; } ; signed_integer_range : signed_integer ':' signed_integer diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 4a88be9d..fd5774b4 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -408,7 +408,7 @@ ExprNode::fillErrorCorrectionRow(int eqn, expr_t e = datatree.AddTimes(datatree.AddVariable(m.first), datatree.AddPossiblyNegativeConstant(-constant)); if (param_id != -1) e = datatree.AddTimes(e, datatree.AddVariable(param_id)); - auto coor = make_tuple(eqn, -orig_lag, colidx); + auto coor = tuple(eqn, -orig_lag, colidx); if (A0star.find(coor) == A0star.end()) A0star[coor] = e; else @@ -5679,7 +5679,7 @@ BinaryOpNode::getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id istarget = false; ordered_symb_ids.emplace_back(id, istarget, scale); } - ec_params_and_vars = make_pair(optim_param_symb_id, ordered_symb_ids); + ec_params_and_vars = { optim_param_symb_id, ordered_symb_ids }; } return ec_params_and_vars; } diff --git a/src/ModelTree.hh b/src/ModelTree.hh index 08e3b8ed..36e3b7f3 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -36,7 +36,7 @@ using namespace std; // Helper to convert a vector into a tuple template <typename T, size_t... Indices> auto vectorToTupleHelper(const vector<T>& v, index_sequence<Indices...>) { - return make_tuple(v[Indices]...); + return tuple(v[Indices]...); } template <size_t N, typename T> auto vectorToTuple(const vector<T>& v) { -- GitLab