C++11: Cleaned up commands code with range-based for

This commit is contained in:
Paul Beckingham 2015-05-11 17:45:15 -04:00
parent bd3d58484a
commit 5a57dfd70d
42 changed files with 911 additions and 1065 deletions

View file

@ -51,21 +51,15 @@ int CmdCompletionCommands::execute (std::string& output)
// Get a list of all commands.
std::vector <std::string> commands;
std::map <std::string, Command*>::iterator command;
for (command = context.commands.begin ();
command != context.commands.end ();
++command)
{
commands.push_back (command->first);
}
for (auto& command : context.commands)
commands.push_back (command.first);
// Sort alphabetically.
std::sort (commands.begin (), commands.end ());
std::stringstream out;
std::vector <std::string>::iterator c;
for (c = commands.begin (); c != commands.end (); ++c)
out << *c << "\n";
for (auto& c : commands)
out << c << "\n";
output = out.str ();
return 0;
@ -87,21 +81,15 @@ int CmdZshCommands::execute (std::string& output)
// Get a list of all commands.
std::vector <std::string> commands;
std::map <std::string, Command*>::iterator command;
for (command = context.commands.begin ();
command != context.commands.end ();
++command)
{
commands.push_back (command->first);
}
for (auto& command : context.commands)
commands.push_back (command.first);
// Sort alphabetically.
std::sort (commands.begin (), commands.end ());
std::stringstream out;
std::vector <std::string>::iterator c;
for (c = commands.begin (); c != commands.end (); ++c)
out << *c << ":" << context.commands[*c]->description () << "\n";
for (auto& c : commands)
out << c << ":" << context.commands[c]->description () << "\n";
output = out.str ();
return 0;