From a468537c1b4c4a7cc78f6b7718d3e33686e5b8b2 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 27 Sep 2019 19:20:23 -0700 Subject: [PATCH] [clang-tidy] Use new range based loops Found with modernize-loop-convert Signed-off-by: Rosen Penev --- src/Context.cpp | 4 ++-- src/Eval.cpp | 28 ++++++++++++++-------------- src/ViewTask.cpp | 4 ++-- src/dependency.cpp | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index 5a650cd8f..988bc74e5 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -534,8 +534,8 @@ int Context::initialize (int argc, const char** argv) // //////////////////////////////////////////////////////////////////////////// - for (unsigned int i = 0; i < NUM_MODIFIER_NAMES; ++i) - cli2.entity ("modifier", modifierNames[i]); + for (auto & modifierName : modifierNames) + cli2.entity ("modifier", modifierName); for (auto& op : Eval::getOperators ()) cli2.entity ("operator", op); diff --git a/src/Eval.cpp b/src/Eval.cpp index de278aecb..445a90e2c 100644 --- a/src/Eval.cpp +++ b/src/Eval.cpp @@ -195,8 +195,8 @@ void Eval::debug (bool value) std::vector Eval::getOperators () { std::vector all; - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) - all.push_back (operators[i].op); + for (auto & i : operators) + all.push_back (i.op); return all; } @@ -206,9 +206,9 @@ std::vector Eval::getOperators () std::vector Eval::getBinaryOperators () { std::vector all; - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) - if (operators[i].type == 'b') - all.push_back (operators[i].op); + for (auto & i : operators) + if (i.type == 'b') + all.push_back (i.op); return all; } @@ -338,9 +338,9 @@ void Eval::evaluatePostfixStack ( case Lexer::Type::identifier: { bool found = false; - for (auto source = _sources.begin (); source != _sources.end (); ++source) + for (auto _source : _sources) { - if ((*source) (token.first, v)) + if (_source (token.first, v)) { if (_debug) Context::getContext ().debug (format ("Eval identifier source '{1}' → ↑'{2}'", token.first, (std::string) v)); @@ -669,10 +669,10 @@ bool Eval::parsePrimitive ( else { bool found = false; - for (auto source = _sources.begin (); source != _sources.end (); ++source) + for (auto _source : _sources) { Variant v; - if ((*source) (infix[i].first, v)) + if (_source (infix[i].first, v)) { found = true; break; @@ -810,13 +810,13 @@ bool Eval::identifyOperator ( unsigned int& precedence, char& associativity) const { - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) + for (auto & i : operators) { - if (operators[i].op == op) + if (i.op == op) { - type = operators[i].type; - precedence = operators[i].precedence; - associativity = operators[i].associativity; + type = i.type; + precedence = i.precedence; + associativity = i.associativity; return true; } } diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index b39057e1f..488a467f1 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -320,8 +320,8 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (obfuscate) if (_columns[c]->type () == "string") - for (unsigned int line = 0; line < cells[c].size (); ++line) - cells[c][line] = obfuscateText (cells[c][line]); + for (auto & line : cells[c]) + line = obfuscateText (line); } // Listing breaks are simply blank lines inserted when a column value diff --git a/src/dependency.cpp b/src/dependency.cpp index 26fdf013a..03af7e596 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -91,9 +91,9 @@ bool dependencyIsCircular (const Task& task) // This is a basic depth first search that always terminates given the // fact that we do not visit any task twice - for (unsigned int i = 0; i < deps_current.size (); i++) + for (const auto & i : deps_current) { - if (Context::getContext ().tdb2.get (deps_current[i], current)) + if (Context::getContext ().tdb2.get (i, current)) { auto current_uuid = current.get ("uuid");