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).issue#70
parent
2a127b1f23
commit
ecdca502aa
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue