From 7d5095796ab616cf9b709036387bb95ab9984141 Mon Sep 17 00:00:00 2001 From: Pavel Solodovnikov Date: Mon, 11 Sep 2017 13:40:26 +0300 Subject: Meta: modernize old-fashioned loops to range-based `for`. Changes done via `clang-tidy` with some manual fine-tuning for the variable naming and `auto` type deduction where appropriate. --- Source/cmFindCommon.cxx | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'Source/cmFindCommon.cxx') diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 9ebe824902..814296201a 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -155,10 +155,9 @@ void cmFindCommon::SelectDefaultMacMode() void cmFindCommon::RerootPaths(std::vector& paths) { #if 0 - for(std::vector::const_iterator i = paths.begin(); - i != paths.end(); ++i) + for(std::string const& p : paths) { - fprintf(stderr, "[%s]\n", i->c_str()); + fprintf(stderr, "[%s]\n", p.c_str()); } #endif // Short-circuit if there is nothing to do. @@ -194,9 +193,8 @@ void cmFindCommon::RerootPaths(std::vector& paths) if (sysroot) { roots.push_back(sysroot); } - for (std::vector::iterator ri = roots.begin(); - ri != roots.end(); ++ri) { - cmSystemTools::ConvertToUnixSlashes(*ri); + for (std::string& r : roots) { + cmSystemTools::ConvertToUnixSlashes(r); } const char* stagePrefix = @@ -206,24 +204,22 @@ void cmFindCommon::RerootPaths(std::vector& paths) std::vector unrootedPaths = paths; paths.clear(); - for (std::vector::const_iterator ri = roots.begin(); - ri != roots.end(); ++ri) { - for (std::vector::const_iterator ui = unrootedPaths.begin(); - ui != unrootedPaths.end(); ++ui) { + for (std::string const& r : roots) { + for (std::string const& up : unrootedPaths) { // Place the unrooted path under the current root if it is not // already inside. Skip the unrooted path if it is relative to // a user home directory or is empty. std::string rootedDir; - if (cmSystemTools::IsSubDirectory(*ui, *ri) || - (stagePrefix && cmSystemTools::IsSubDirectory(*ui, stagePrefix))) { - rootedDir = *ui; - } else if (!ui->empty() && (*ui)[0] != '~') { + if (cmSystemTools::IsSubDirectory(up, r) || + (stagePrefix && cmSystemTools::IsSubDirectory(up, stagePrefix))) { + rootedDir = up; + } else if (!up.empty() && up[0] != '~') { // Start with the new root. - rootedDir = *ri; + rootedDir = r; rootedDir += "/"; // Append the original path with its old root removed. - rootedDir += cmSystemTools::SplitPathRootComponent(*ui); + rootedDir += cmSystemTools::SplitPathRootComponent(up); } // Store the new path. @@ -255,9 +251,8 @@ void cmFindCommon::GetIgnoredPaths(std::vector& ignore) cmSystemTools::ExpandListArgument(ignorePath, ignore); } - for (std::vector::iterator i = ignore.begin(); - i != ignore.end(); ++i) { - cmSystemTools::ConvertToUnixSlashes(*i); + for (std::string& i : ignore) { + cmSystemTools::ConvertToUnixSlashes(i); } } @@ -337,9 +332,8 @@ void cmFindCommon::ComputeFinalPaths() // Combine the seperate path types, filtering out ignores this->SearchPaths.clear(); std::vector& allLabels = this->PathGroupLabelMap[PathGroup::All]; - for (std::vector::const_iterator l = allLabels.begin(); - l != allLabels.end(); ++l) { - this->LabeledPaths[*l].ExtractWithout(ignored, this->SearchPaths); + for (PathLabel const& l : allLabels) { + this->LabeledPaths[l].ExtractWithout(ignored, this->SearchPaths); } // Expand list of paths inside all search roots. -- cgit v1.2.1