Commit 608c4345 authored by Sébastien Villemot's avatar Sébastien Villemot

Replace most calls to make_pair by braced-initializer lists or emplace()/emplace_back()

parent 7d9cd718
This diff is collapsed.
......@@ -379,7 +379,7 @@ PacModelStatement::getPacModelInfoForPacExpectation(pair<string, pair<string, pa
int growth_symb_id = -1;
if (!growth.empty())
growth_symb_id = symbol_table.getID(growth);
pac_model_info = make_pair(name, make_pair(var_name, make_pair(discount, make_pair(growth_symb_id, undiff))));
pac_model_info = { name, { var_name, { discount, { growth_symb_id, undiff } } }};
}
VarModelStatement::VarModelStatement(SymbolList symbol_list_arg,
......@@ -407,7 +407,7 @@ VarModelStatement::getVarModelInfo(string &var_model_name,
else
{
auto it = options_list.num_options.find("var.order");
var_model_info[name] = make_pair(symbol_list, atoi(it->second.c_str()));
var_model_info[name] = { symbol_list, atoi(it->second.c_str()) };
}
}
......@@ -3134,7 +3134,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg)
exit(EXIT_FAILURE);
}
if (restriction_map.find(make_pair(from_regime, to_regime)) !=
if (restriction_map.find({ from_regime, to_regime }) !=
restriction_map.end())
{
cerr << "ERROR: two restrictions were given for: " << from_regime << ", "
......@@ -3149,7 +3149,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(OptionsList options_list_arg)
<< " must be less than 1" << endl;
exit(EXIT_FAILURE);
}
restriction_map[make_pair(from_regime, to_regime)] = transition_probability;
restriction_map[{ from_regime, to_regime }] = transition_probability;
}
catch (const bad_lexical_cast &)
{
......@@ -3189,10 +3189,10 @@ 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(make_pair(row+1, col+1)) != restriction_map.end())
if (restriction_map.find({ row+1, col+1 }) != restriction_map.end())
{
row_trans_prob_sum[row] += restriction_map[make_pair(row+1, col+1)];
col_trans_prob_sum[col] += restriction_map[make_pair(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 }];
}
else
{
......
......@@ -65,7 +65,7 @@ DataTree::AddNonNegativeConstant(const string &value)
VariableNode *
DataTree::AddVariableInternal(int symb_id, int lag)
{
auto it = variable_node_map.find(make_pair(symb_id, lag));
auto it = variable_node_map.find({ symb_id, lag });
if (it != variable_node_map.end())
return it->second;
else
......@@ -506,7 +506,7 @@ DataTree::AddVarExpectation(const int symb_id, const int forecast_horizon, const
{
assert(symbol_table.getType(symb_id) == eEndogenous);
auto it = var_expectation_node_map.find(make_pair(model_name, make_pair(symb_id, forecast_horizon)));
auto it = var_expectation_node_map.find({ model_name, { symb_id, forecast_horizon } });
if (it != var_expectation_node_map.end())
return it->second;
......@@ -548,7 +548,7 @@ DataTree::AddExternalFunction(int symb_id, const vector<expr_t> &arguments)
{
assert(symbol_table.getType(symb_id) == eExternalFunction);
auto it = external_function_node_map.find(make_pair(arguments, symb_id));
auto it = external_function_node_map.find({ arguments, symb_id });
if (it != external_function_node_map.end())
return it->second;
......@@ -561,8 +561,7 @@ DataTree::AddFirstDerivExternalFunction(int top_level_symb_id, const vector<expr
assert(symbol_table.getType(top_level_symb_id) == eExternalFunction);
auto it
= first_deriv_external_function_node_map.find(make_pair(make_pair(arguments, input_index),
top_level_symb_id));
= first_deriv_external_function_node_map.find({ { arguments, input_index }, top_level_symb_id });
if (it != first_deriv_external_function_node_map.end())
return it->second;
......@@ -575,9 +574,8 @@ DataTree::AddSecondDerivExternalFunction(int top_level_symb_id, const vector<exp
assert(symbol_table.getType(top_level_symb_id) == eExternalFunction);
auto it
= second_deriv_external_function_node_map.find(make_pair(make_pair(arguments,
make_pair(input_index1, input_index2)),
top_level_symb_id));
= second_deriv_external_function_node_map.find({ { arguments, { input_index1, input_index2 } },
top_level_symb_id });
if (it != second_deriv_external_function_node_map.end())
return it->second;
......
......@@ -330,7 +330,7 @@ inline expr_t
DataTree::AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set, int param1_symb_id, int param2_symb_id, const string &adl_param_name, const vector<int> &adl_lags)
{
// If the node already exists in tree, share it
auto it = unary_op_node_map.find(make_pair(make_pair(arg, op_code), make_pair(make_pair(arg_exp_info_set, make_pair(param1_symb_id, param2_symb_id)), make_pair(adl_param_name, adl_lags))));
auto it = unary_op_node_map.find({ { arg, op_code }, { { arg_exp_info_set, { param1_symb_id, param2_symb_id } }, { adl_param_name, adl_lags } } });
if (it != unary_op_node_map.end())
return it->second;
......@@ -355,7 +355,7 @@ DataTree::AddUnaryOp(UnaryOpcode op_code, expr_t arg, int arg_exp_info_set, int
inline expr_t
DataTree::AddBinaryOp(expr_t arg1, BinaryOpcode op_code, expr_t arg2, int powerDerivOrder)
{
auto it = binary_op_node_map.find(make_pair(make_pair(make_pair(arg1, arg2), powerDerivOrder), op_code));
auto it = binary_op_node_map.find({ { { arg1, arg2 }, powerDerivOrder }, op_code });
if (it != binary_op_node_map.end())
return it->second;
......@@ -376,7 +376,7 @@ DataTree::AddBinaryOp(expr_t arg1, BinaryOpcode op_code, expr_t arg2, int powerD
inline expr_t
DataTree::AddTrinaryOp(expr_t arg1, TrinaryOpcode op_code, expr_t arg2, expr_t arg3)
{
auto it = trinary_op_node_map.find(make_pair(make_pair(make_pair(arg1, arg2), arg3), op_code));
auto it = trinary_op_node_map.find({ { { arg1, arg2 }, arg3 }, op_code });
if (it != trinary_op_node_map.end())
return it->second;
......
This diff is collapsed.
This diff is collapsed.
......@@ -399,9 +399,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
vms->fillVarModelInfoFromEquations(eqnumber, lhs, rhs, nonstationary,
diff, orig_diff_var, max_lag);
var_model_info_pac_expectation[var_model_name] =
make_pair(make_pair(make_pair(lhs, lhs_expr_t),
make_pair(diff, orig_diff_var)),
make_pair(make_pair(max_lag, nonstationary), eqnumber));
{ { { lhs, lhs_expr_t }, { diff, orig_diff_var } }, { { max_lag, nonstationary }, eqnumber } };
}
auto *pms = dynamic_cast<PacModelStatement *>(*it);
if (pms != nullptr)
......
This diff is collapsed.
......@@ -288,7 +288,7 @@ protected:
inline void
setBlockLeadLag(int block, int max_lag, int max_lead)
{
block_lag_lead[block] = make_pair(max_lag, max_lead);
block_lag_lead[block] = { max_lag, max_lead };
};
//! Return the type of equation (equation_number) belonging to the block block_number
......
......@@ -612,7 +612,7 @@ ParsingDriver::add_VAR_restriction_coeff(string *name1, string *name2, string *l
int symb_id2 = name2 == nullptr ? -1 : mod_file->symbol_table.getID(*name2);
int lag = atoi(lagstr->c_str());
var_restriction_coeff = make_pair(symb_id1, make_pair(symb_id2, lag));
var_restriction_coeff = { symb_id1, { symb_id2, lag } };
delete name1;
if (name2 != nullptr)
......@@ -632,13 +632,9 @@ ParsingDriver::add_VAR_restriction_equation_or_crossequation(string *numberstr)
assert(var_restriction_eq_or_crosseq.size() > 0 && var_restriction_eq_or_crosseq.size() < 3);
double number = atof(numberstr->c_str());
if (var_restriction_eq_or_crosseq.size() == 1)
var_restriction_equation_or_crossequation = make_pair(make_pair(var_restriction_eq_or_crosseq[0],
make_pair(make_pair(-1, make_pair(-1, -1)), (expr_t) nullptr)),
number);
var_restriction_equation_or_crossequation = { { var_restriction_eq_or_crosseq[0], { { -1, { -1, -1 } }, (expr_t) nullptr } }, number };
else
var_restriction_equation_or_crossequation = make_pair(make_pair(var_restriction_eq_or_crosseq[0],
var_restriction_eq_or_crosseq[1]),
number);
var_restriction_equation_or_crossequation = { { var_restriction_eq_or_crosseq[0], var_restriction_eq_or_crosseq[1] }, number };
var_restriction_eq_or_crosseq.clear();
}
......@@ -648,7 +644,7 @@ ParsingDriver::multiply_arg2_by_neg_one()
assert(var_restriction_eq_or_crosseq.size() == 2);
expr_t exprtm1 = add_times(var_restriction_eq_or_crosseq[1].second,
add_uminus(add_non_negative_constant(new string("-1"))));
var_restriction_eq_or_crosseq[1] = make_pair(var_restriction_eq_or_crosseq[1].first, exprtm1);
var_restriction_eq_or_crosseq[1] = { var_restriction_eq_or_crosseq[1].first, exprtm1 };
}
void
......@@ -679,7 +675,7 @@ ParsingDriver::add_VAR_covariance_number_restriction(string *name1, string *name
int symb_id1 = mod_file->symbol_table.getID(*name1);
int symb_id2 = mod_file->symbol_table.getID(*name2);
double value = atof(valuestr->c_str());
covariance_number_restriction[make_pair(symb_id1, symb_id2)] = value;
covariance_number_restriction[{ symb_id1, symb_id2 }] = value;
delete name1;
delete name2;
delete valuestr;
......@@ -692,7 +688,7 @@ ParsingDriver::add_VAR_covariance_pair_restriction(string *name11, string *name1
int symb_id12 = mod_file->symbol_table.getID(*name12);
int symb_id21 = mod_file->symbol_table.getID(*name21);
int symb_id22 = mod_file->symbol_table.getID(*name22);
covariance_pair_restriction[make_pair(symb_id11, symb_id12)] = make_pair(symb_id21, symb_id22);
covariance_pair_restriction[{ symb_id11, symb_id12 }] = { symb_id21, symb_id22 };
delete name11;
delete name12;
delete name21;
......@@ -762,7 +758,7 @@ ParsingDriver::init_val(string *name, expr_t rhs)
&& type != eExogenousDet)
error("initval/endval: " + *name + " should be an endogenous or exogenous variable");
init_values.push_back(make_pair(symb_id, rhs));
init_values.emplace_back(symb_id, rhs);
delete name;
}
......@@ -824,7 +820,7 @@ ParsingDriver::homotopy_val(string *name, expr_t val1, expr_t val2)
&& type != eExogenousDet)
error("homotopy_val: " + *name + " should be a parameter or exogenous variable");
homotopy_values.push_back(make_pair(symb_id, make_pair(val1, val2)));
homotopy_values.emplace_back(symb_id, make_pair(val1, val2));
delete name;
}
......@@ -1492,7 +1488,7 @@ ParsingDriver::option_num(const string &name_option, string *opt1, string *opt2)
!= options_list.paired_num_options.end())
error("option " + name_option + " declared twice");
options_list.paired_num_options[name_option] = make_pair(*opt1, *opt2);
options_list.paired_num_options[name_option] = { *opt1, *opt2 };
delete opt1;
delete opt2;
}
......@@ -1779,7 +1775,7 @@ ParsingDriver::set_subsamples(string *name1, string *name2)
mod_file->addStatement(new SubsamplesStatement(*name1, *name2, subsample_declaration_map,
mod_file->symbol_table));
subsample_declarations[make_pair(*name1, *name2)] = subsample_declaration_map;
subsample_declarations[{ *name1, *name2 }] = subsample_declaration_map;
subsample_declaration_map.clear();
delete name1;
delete name2;
......@@ -1795,7 +1791,7 @@ ParsingDriver::copy_subsamples(string *to_name1, string *to_name2, string *from_
if (!from_name2->empty())
check_symbol_existence(*from_name2);
if (subsample_declarations.find(make_pair(*from_name1, *from_name2)) == subsample_declarations.end())
if (subsample_declarations.find({ *from_name1, *from_name2 }) == subsample_declarations.end())
{
string err = *from_name1;
if (!from_name2->empty())
......@@ -1806,8 +1802,8 @@ ParsingDriver::copy_subsamples(string *to_name1, string *to_name2, string *from_
mod_file->addStatement(new SubsamplesEqualStatement(*to_name1, *to_name2, *from_name1, *from_name2,
mod_file->symbol_table));
subsample_declarations[make_pair(*to_name1, *to_name2)]
= subsample_declarations[make_pair(*from_name1, *from_name2)];
subsample_declarations[{ *to_name1, *to_name2 }]
= subsample_declarations[{ *from_name1, *from_name2 }];
delete to_name1;
delete to_name2;
......@@ -1829,7 +1825,7 @@ ParsingDriver::set_subsample_name_equal_to_date_range(string *name, string *date
{
if (subsample_declaration_map.find(*name) != subsample_declaration_map.end())
error("Symbol " + *name + " may only be assigned once in a SUBSAMPLE statement");
subsample_declaration_map[*name] = make_pair(*date1, *date2);
subsample_declaration_map[*name] = { *date1, *date2 };
delete name;
delete date1;
delete date2;
......@@ -1856,10 +1852,10 @@ ParsingDriver::check_subsample_declaration_exists(string *name1, string *name2,
if (!name2->empty())
check_symbol_existence(*name2);
subsample_declarations_t::const_iterator it = subsample_declarations.find(make_pair(*name1, *name2));
subsample_declarations_t::const_iterator it = subsample_declarations.find({ *name1, *name2 });
if (it == subsample_declarations.end())
{
it = subsample_declarations.find(make_pair(*name2, *name1));
it = subsample_declarations.find({ *name2, *name1 });
if (it == subsample_declarations.end())
{
string err = *name1;
......@@ -2305,7 +2301,7 @@ ParsingDriver::add_mc_filename(string *filename, string *prior)
for (auto & it : filename_list)
if (it.first == *filename)
error("model_comparison: filename " + *filename + " declared twice");
filename_list.push_back(make_pair(*filename, *prior));
filename_list.emplace_back(*filename, *prior);
delete filename;
delete prior;
}
......@@ -3124,13 +3120,13 @@ pair<bool, double>
ParsingDriver::is_there_one_integer_argument() const
{
if (stack_external_function_args.top().size() != 1)
return make_pair(false, 0);
return { false, 0 };
auto *numNode = dynamic_cast<NumConstNode *>(stack_external_function_args.top().front());
auto *unaryNode = dynamic_cast<UnaryOpNode *>(stack_external_function_args.top().front());
if (numNode == nullptr && unaryNode == nullptr)
return make_pair(false, 0);
return { false, 0 };
eval_context_t ectmp;
double model_var_arg;
......@@ -3142,12 +3138,12 @@ ParsingDriver::is_there_one_integer_argument() const
}
catch (ExprNode::EvalException &e)
{
return make_pair(false, 0);
return { false, 0 };
}
}
else
if (unaryNode->get_op_code() != oUminus)
return make_pair(false, 0);
return { false, 0 };
else
{
try
......@@ -3156,13 +3152,13 @@ ParsingDriver::is_there_one_integer_argument() const
}
catch (ExprNode::EvalException &e)
{
return make_pair(false, 0);
return { false, 0 };
}
}
if (model_var_arg != floor(model_var_arg))
return make_pair(false, 0);
return make_pair(true, model_var_arg);
return { false, 0 };
return { true, model_var_arg };
}
expr_t
......
This diff is collapsed.
......@@ -193,7 +193,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
output << "[";
for (size_t j = 0; j < symb_ids.size(); j++)
{
auto it = variable_node_map.find(make_pair(symb_ids[j], 0));
auto it = variable_node_map.find({ symb_ids[j], 0 });
assert(it != variable_node_map.end());
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, output_type);
if (j < symb_ids.size()-1)
......@@ -254,7 +254,7 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode
output << " ";
if (symb_ids.size() > 1)
std::cout << "Error: in C, multiple returns are not permitted in steady_state_model" << std::endl;
auto it = variable_node_map.find(make_pair(symb_ids[0], 0));
auto it = variable_node_map.find({ symb_ids[0], 0 });
assert(it != variable_node_map.end());
if (it->second->get_type() == eModFileLocalVariable)
output << "double ";
......@@ -291,7 +291,7 @@ SteadyStateModel::writeJsonSteadyStateFile(ostream &output, bool transformComput
if (j != 0)
output << ",";
auto it =
variable_node_map.find(make_pair(symb_ids[j], 0));
variable_node_map.find({ symb_ids[j], 0 });
assert(it != variable_node_map.end());
output << "\"";
dynamic_cast<ExprNode *>(it->second)->writeJsonOutput(output, {}, {}, false);
......
......@@ -110,7 +110,7 @@ MacroDriver::init_loop(const string &name, const MacroValue *value) noexcept(fal
const auto *mv2 = dynamic_cast<const ArrayMV<string> *>(value);
if (!mv1 && !mv2)
throw MacroValue::TypeError("Argument of @#for loop must be an array expression");
loop_stack.push(make_pair(name, make_pair(value, 0)));
loop_stack.emplace(name, make_pair(value, 0));
}
bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment