use emplace
Allows removing the constructor name as emplace forwards the arguments directly. Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
22
src/CLI2.cpp
22
src/CLI2.cpp
@@ -302,7 +302,7 @@ void CLI2::entity (const std::string& category, const std::string& name)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// The category/name pair was not found, therefore add it.
|
// The category/name pair was not found, therefore add it.
|
||||||
_entities.insert (std::pair <std::string, std::string> (category, name));
|
_entities.emplace (category, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -325,7 +325,7 @@ void CLI2::add (const std::vector <std::string>& arguments, int offset /* = 0 */
|
|||||||
std::vector <A2> replacement {_original_args.begin(), _original_args.begin() + offset + 1};
|
std::vector <A2> replacement {_original_args.begin(), _original_args.begin() + offset + 1};
|
||||||
|
|
||||||
for (const auto& arg : arguments)
|
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 + offset; i < _original_args.size (); ++i)
|
for (unsigned int i = 1 + offset; i < _original_args.size (); ++i)
|
||||||
replacement.push_back (_original_args[i]);
|
replacement.push_back (_original_args[i]);
|
||||||
@@ -849,7 +849,7 @@ void CLI2::aliasExpansion ()
|
|||||||
Lexer::Type type;
|
Lexer::Type type;
|
||||||
Lexer lex (_aliases[raw]);
|
Lexer lex (_aliases[raw]);
|
||||||
while (lex.token (lexeme, type))
|
while (lex.token (lexeme, type))
|
||||||
reconstructed.push_back (A2 (lexeme, type));
|
reconstructed.emplace_back (lexeme, type);
|
||||||
|
|
||||||
action = true;
|
action = true;
|
||||||
changes = true;
|
changes = true;
|
||||||
@@ -879,7 +879,7 @@ void CLI2::aliasExpansion ()
|
|||||||
Lexer::Type type;
|
Lexer::Type type;
|
||||||
Lexer lex (_aliases[i.attribute ("raw")]);
|
Lexer lex (_aliases[i.attribute ("raw")]);
|
||||||
while (lex.token (lexeme, type))
|
while (lex.token (lexeme, type))
|
||||||
reconstructedOriginals.push_back (A2 (lexeme, type));
|
reconstructedOriginals.emplace_back (lexeme, type);
|
||||||
|
|
||||||
action = true;
|
action = true;
|
||||||
changes = true;
|
changes = true;
|
||||||
@@ -1536,7 +1536,7 @@ void CLI2::findIDs ()
|
|||||||
{
|
{
|
||||||
changes = true;
|
changes = true;
|
||||||
std::string number = a.attribute ("raw");
|
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)
|
else if (a._lextype == Lexer::Type::set)
|
||||||
@@ -1549,9 +1549,9 @@ void CLI2::findIDs ()
|
|||||||
changes = true;
|
changes = true;
|
||||||
auto hyphen = element.find ('-');
|
auto hyphen = element.find ('-');
|
||||||
if (hyphen != std::string::npos)
|
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
|
else
|
||||||
_id_ranges.push_back (std::pair <std::string, std::string> (element, element));
|
_id_ranges.emplace_back (element, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1589,7 +1589,7 @@ void CLI2::findIDs ()
|
|||||||
changes = true;
|
changes = true;
|
||||||
a.unTag ("MODIFICATION");
|
a.unTag ("MODIFICATION");
|
||||||
a.tag ("FILTER");
|
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)
|
else if (a._lextype == Lexer::Type::set)
|
||||||
{
|
{
|
||||||
@@ -1604,9 +1604,9 @@ void CLI2::findIDs ()
|
|||||||
changes = true;
|
changes = true;
|
||||||
auto hyphen = element.find ('-');
|
auto hyphen = element.find ('-');
|
||||||
if (hyphen != std::string::npos)
|
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
|
else
|
||||||
_id_ranges.push_back (std::pair <std::string, std::string> (element, element));
|
_id_ranges.emplace_back (element, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2145,7 +2145,7 @@ void CLI2::defaultCommand ()
|
|||||||
|
|
||||||
while (lex.token (lexeme, type))
|
while (lex.token (lexeme, type))
|
||||||
{
|
{
|
||||||
reconstructedOriginals.push_back (A2 (lexeme, type));
|
reconstructedOriginals.emplace_back (lexeme, type);
|
||||||
|
|
||||||
A2 cmd (lexeme, type);
|
A2 cmd (lexeme, type);
|
||||||
cmd.tag ("DEFAULT");
|
cmd.tag ("DEFAULT");
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ void Eval::evaluateInfixExpression (const std::string& e, Variant& v) const
|
|||||||
std::string token;
|
std::string token;
|
||||||
Lexer::Type type;
|
Lexer::Type type;
|
||||||
while (l.token (token, 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.
|
// Parse for syntax checking and operator replacement.
|
||||||
if (_debug)
|
if (_debug)
|
||||||
@@ -149,7 +149,7 @@ void Eval::evaluatePostfixExpression (const std::string& e, Variant& v) const
|
|||||||
std::string token;
|
std::string token;
|
||||||
Lexer::Type type;
|
Lexer::Type type;
|
||||||
while (l.token (token, type))
|
while (l.token (token, type))
|
||||||
tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));
|
tokens.emplace_back (token, type);
|
||||||
|
|
||||||
if (_debug)
|
if (_debug)
|
||||||
Context::getContext ().debug ("[1;37;42mFILTER[0m Postfix " + dump (tokens));
|
Context::getContext ().debug ("[1;37;42mFILTER[0m Postfix " + dump (tokens));
|
||||||
|
|||||||
@@ -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;
|
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
||||||
for (auto& a : Context::getContext ().cli2._args)
|
for (auto& a : Context::getContext ().cli2._args)
|
||||||
if (a.hasTag ("FILTER"))
|
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.size ())
|
if (precompiled.size ())
|
||||||
{
|
{
|
||||||
@@ -107,7 +107,7 @@ void Filter::subset (std::vector <Task>& output)
|
|||||||
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
std::vector <std::pair <std::string, Lexer::Type>> precompiled;
|
||||||
for (auto& a : Context::getContext ().cli2._args)
|
for (auto& a : Context::getContext ().cli2._args)
|
||||||
if (a.hasTag ("FILTER"))
|
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.
|
// Shortcut indicates that only pending.data needs to be loaded.
|
||||||
bool shortcut = false;
|
bool shortcut = false;
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ void TF2::add_task (Task& task)
|
|||||||
|
|
||||||
// For faster lookup
|
// For faster lookup
|
||||||
if (Context::getContext ().cli2.getCommand () == "import")
|
if (Context::getContext ().cli2.getCommand () == "import")
|
||||||
_tasks_map.insert (std::pair<std::string, Task> (task.get("uuid"), task));
|
_tasks_map.emplace (task.get("uuid"), task);
|
||||||
|
|
||||||
Task::status status = task.getStatus ();
|
Task::status status = task.getStatus ();
|
||||||
if (task.id == 0 &&
|
if (task.id == 0 &&
|
||||||
@@ -410,7 +410,7 @@ void TF2::load_tasks (bool from_gc /* = false */)
|
|||||||
_tasks.push_back (task);
|
_tasks.push_back (task);
|
||||||
|
|
||||||
if (Context::getContext ().cli2.getCommand () == "import") // For faster lookup only
|
if (Context::getContext ().cli2.getCommand () == "import") // For faster lookup only
|
||||||
_tasks_map.insert (std::pair<std::string, Task> (task.get("uuid"), task));
|
_tasks_map.emplace (task.get("uuid"), task);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TDB2::gc() calls this after loading both pending and completed
|
// TDB2::gc() calls this after loading both pending and completed
|
||||||
|
|||||||
@@ -790,7 +790,7 @@ void Task::parseJSON (const json::object* root_obj)
|
|||||||
name << "annotation_" << ann_timestamp;
|
name << "annotation_" << ann_timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
annos.insert (std::make_pair (name.str (), json::decode (what->_data)));
|
annos.emplace (name.str (), json::decode (what->_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
setAnnotations (annos);
|
setAnnotations (annos);
|
||||||
|
|||||||
@@ -656,7 +656,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
|
|||||||
while (annotations.find (name.str ()) != annotations.end ());
|
while (annotations.find (name.str ()) != annotations.end ());
|
||||||
|
|
||||||
auto text = Lexer::trim (value.substr (gap + 4), "\t ");
|
auto text = Lexer::trim (value.substr (gap + 4), "\t ");
|
||||||
annotations.insert (std::make_pair (name.str (), text));
|
annotations.emplace (name.str (), text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ int CmdGet::execute (std::string& output)
|
|||||||
Task t;
|
Task t;
|
||||||
Variant result;
|
Variant result;
|
||||||
if (getDOM (arg.attribute ("raw"), t, result))
|
if (getDOM (arg.attribute ("raw"), t, result))
|
||||||
results.push_back ((std::string) result);
|
results.emplace_back (result);
|
||||||
else
|
else
|
||||||
results.push_back ("");
|
results.emplace_back ("");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void sort_projects (
|
|||||||
|
|
||||||
// if parent does not exist yet: insert into sorted view
|
// if parent does not exist yet: insert into sorted view
|
||||||
if (parent_pos == sorted.end ())
|
if (parent_pos == sorted.end ())
|
||||||
sorted.push_back (std::make_pair (parent, 1));
|
sorted.emplace_back (parent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert new element below latest parent
|
// insert new element below latest parent
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ int main (int, char**)
|
|||||||
while (l2.token (token, type))
|
while (l2.token (token, type))
|
||||||
{
|
{
|
||||||
std::cout << "# «" << token << "» " << Lexer::typeName (type) << "\n";
|
std::cout << "# «" << token << "» " << Lexer::typeName (type) << "\n";
|
||||||
tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));
|
tokens.emplace_back (token, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
t.is (tokens[0].first, "one", "tokens[0] = 'one'"); // 30
|
t.is (tokens[0].first, "one", "tokens[0] = 'one'"); // 30
|
||||||
@@ -147,7 +147,7 @@ int main (int, char**)
|
|||||||
while (l3.token (token, type))
|
while (l3.token (token, type))
|
||||||
{
|
{
|
||||||
std::cout << "# «" << token << "» " << Lexer::typeName (type) << "\n";
|
std::cout << "# «" << token << "» " << Lexer::typeName (type) << "\n";
|
||||||
tokens.push_back (std::pair <std::string, Lexer::Type> (token, type));
|
tokens.emplace_back (token, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
t.is ((int)tokens.size (), 7, "7 tokens");
|
t.is ((int)tokens.size (), 7, "7 tokens");
|
||||||
|
|||||||
Reference in New Issue
Block a user