Use new kind of loop.

This commit is contained in:
Andreas Jönsson 2015-05-10 10:27:36 +02:00
parent 501ce1d689
commit dd846658e6

View File

@ -780,12 +780,11 @@ int stoiStrict(const generic_string& input)
bool allLinesAreNumeric(const std::vector<generic_string>& lines) bool allLinesAreNumeric(const std::vector<generic_string>& lines)
{ {
const auto endit = lines.end(); for (const generic_string& line : lines)
for (auto it = lines.begin(); it != endit; ++it)
{ {
try try
{ {
stoiStrict(*it); stoiStrict(line);
} }
catch (std::invalid_argument&) catch (std::invalid_argument&)
{ {
@ -819,9 +818,9 @@ std::vector<generic_string> numericSort(std::vector<generic_string> input, bool
{ {
// Pre-condition: all strings in "input" are convertible to int with stoiStrict. // Pre-condition: all strings in "input" are convertible to int with stoiStrict.
std::vector<int> inputAsInts; std::vector<int> inputAsInts;
for (auto it = input.begin(); it != input.end(); ++it) for (const generic_string& line : input)
{ {
inputAsInts.push_back(stoiStrict(*it)); inputAsInts.push_back(stoiStrict(line));
} }
std::sort(inputAsInts.begin(), inputAsInts.end(), [isDescending](int a, int b) std::sort(inputAsInts.begin(), inputAsInts.end(), [isDescending](int a, int b)
{ {
@ -835,9 +834,9 @@ std::vector<generic_string> numericSort(std::vector<generic_string> input, bool
} }
}); });
std::vector<generic_string> output; std::vector<generic_string> output;
for (auto it = inputAsInts.begin(); it != inputAsInts.end(); ++it) for (const int& sortedInt : inputAsInts)
{ {
output.push_back(std::to_wstring(*it)); output.push_back(std::to_wstring(sortedInt));
} }
return output; return output;
} }