[clang-tidy] Replace push_back with emplace_back

Found with modernize-use-emplace

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-09-27 19:24:23 -07:00 committed by Paul Beckingham
parent a468537c1b
commit 897759e4dc
6 changed files with 21 additions and 21 deletions

View file

@ -339,7 +339,7 @@ void CLI2::add (const std::vector <std::string>& arguments)
std::vector <A2> replacement {_original_args[0]};
for (const auto& arg : arguments)
replacement.push_back (A2 (arg, Lexer::Type::word));
replacement.emplace_back(arg, Lexer::Type::word);
for (unsigned int i = 1; i < _original_args.size (); ++i)
replacement.push_back (_original_args[i]);
@ -546,7 +546,7 @@ void CLI2::addFilter (const std::string& arg)
if (arg.length ())
{
std::vector <std::string> filter;
filter.push_back ("(");
filter.emplace_back("(");
std::string lexeme;
Lexer::Type type;
@ -555,7 +555,7 @@ void CLI2::addFilter (const std::string& arg)
while (lex.token (lexeme, type))
filter.push_back (lexeme);
filter.push_back (")");
filter.emplace_back(")");
add (filter);
analyze ();
}
@ -803,7 +803,7 @@ void CLI2::aliasExpansion ()
Lexer::Type type;
Lexer lex (_aliases[raw]);
while (lex.token (lexeme, type))
reconstructed.push_back (A2 (lexeme, type));
reconstructed.emplace_back(lexeme, type);
action = true;
changes = true;
@ -833,7 +833,7 @@ void CLI2::aliasExpansion ()
Lexer::Type type;
Lexer lex (_aliases[i.attribute ("raw")]);
while (lex.token (lexeme, type))
reconstructedOriginals.push_back (A2 (lexeme, type));
reconstructedOriginals.emplace_back(lexeme, type);
action = true;
changes = true;
@ -1483,7 +1483,7 @@ void CLI2::findIDs ()
{
changes = true;
std::string number = a.attribute ("raw");
_id_ranges.push_back (std::pair <std::string, std::string> (number, number));
_id_ranges.emplace_back(number, number);
}
}
else if (a._lextype == Lexer::Type::set)
@ -1496,9 +1496,9 @@ void CLI2::findIDs ()
changes = true;
auto hyphen = element.find ("-");
if (hyphen != std::string::npos)
_id_ranges.push_back (std::pair <std::string, std::string> (element.substr (0, hyphen), element.substr (hyphen + 1)));
_id_ranges.emplace_back(element.substr (0, hyphen), element.substr (hyphen + 1));
else
_id_ranges.push_back (std::pair <std::string, std::string> (element, element));
_id_ranges.emplace_back(element, element);
}
}
@ -1536,7 +1536,7 @@ void CLI2::findIDs ()
changes = true;
a.unTag ("MODIFICATION");
a.tag ("FILTER");
_id_ranges.push_back (std::pair <std::string, std::string> (raw, raw));
_id_ranges.emplace_back(raw, raw);
}
else if (a._lextype == Lexer::Type::set)
{
@ -1551,9 +1551,9 @@ void CLI2::findIDs ()
changes = true;
auto hyphen = element.find ("-");
if (hyphen != std::string::npos)
_id_ranges.push_back (std::pair <std::string, std::string> (element.substr (0, hyphen), element.substr (hyphen + 1)));
_id_ranges.emplace_back(element.substr (0, hyphen), element.substr (hyphen + 1));
else
_id_ranges.push_back (std::pair <std::string, std::string> (element, element));
_id_ranges.emplace_back(element, element);
}
}
}
@ -2047,7 +2047,7 @@ void CLI2::defaultCommand ()
while (lex.token (lexeme, type))
{
reconstructedOriginals.push_back (A2 (lexeme, type));
reconstructedOriginals.emplace_back(lexeme, type);
A2 cmd (lexeme, type);
cmd.tag ("DEFAULT");

View file

@ -122,7 +122,7 @@ void Eval::evaluateInfixExpression (const std::string& e, Variant& v) const
std::string token;
Lexer::Type type;
while (l.token (token, type))
tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));
tokens.emplace_back(token, type);
// Parse for syntax checking and operator replacement.
if (_debug)
@ -149,7 +149,7 @@ void Eval::evaluatePostfixExpression (const std::string& e, Variant& v) const
std::string token;
Lexer::Type type;
while (l.token (token, type))
tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));
tokens.emplace_back(token, type);
if (_debug)
Context::getContext ().debug ("FILTER Postfix " + dump (tokens));

View file

@ -64,7 +64,7 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
for (auto& a : Context::getContext ().cli2._args)
if (a.hasTag ("FILTER"))
precompiled.push_back (std::pair <std::string, Lexer::Type> (a.getToken (), a._lextype));
precompiled.emplace_back(a.getToken (), a._lextype);
if (!precompiled.empty())
{
@ -107,7 +107,7 @@ void Filter::subset (std::vector <Task>& output)
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
for (auto& a : Context::getContext ().cli2._args)
if (a.hasTag ("FILTER"))
precompiled.push_back (std::pair <std::string, Lexer::Type> (a.getToken (), a._lextype));
precompiled.emplace_back(a.getToken (), a._lextype);
// Shortcut indicates that only pending.data needs to be loaded.
bool shortcut = false;

View file

@ -533,7 +533,7 @@ std::vector <std::string>& Hooks::buildHookScriptArgs (std::vector <std::string>
Variant v;
// Hooks API version.
args.push_back ("api:2");
args.emplace_back("api:2");
// Command line Taskwarrior was called with.
getDOM ("context.args", v);

View file

@ -242,7 +242,7 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
std::vector <std::vector <std::string>> headers;
for (unsigned int c = 0; c < _columns.size (); ++c)
{
headers.push_back (std::vector <std::string> ());
headers.emplace_back();
_columns[c]->renderHeader (headers[c], widths[c], _sort[c] ? _sort_header : _header);
if (headers[c].size () > max_lines)
@ -312,7 +312,7 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
for (unsigned int c = 0; c < _columns.size (); ++c)
{
cells.push_back (std::vector <std::string> ());
cells.emplace_back();
_columns[c]->render (cells[c], data[sequence[s]], widths[c], row_color);
if (cells[c].size () > max_lines)

View file

@ -79,7 +79,7 @@ void sort_projects (
// if parent does not exist yet: insert into sorted view
if (parent_pos == sorted.end ())
sorted.push_back (std::make_pair (parent, 1));
sorted.emplace_back (parent, 1);
}
// insert new element below latest parent
@ -88,7 +88,7 @@ void sort_projects (
else
{
// if has no parents: simply push to end of list
sorted.push_back (project);
sorted.emplace_back(project);
}
}
}