From 1bed0be2cd0913a2d0f21c4ff5ebe058e23fdfb5 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Mon, 27 Jun 2022 06:18:54 +0400 Subject: cmFindPackageCommand: Use `std::any_of` instead of "manual" `for` loops --- Source/cmFindPackageCommand.cxx | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 4ad9124..5dab179 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -2279,12 +2279,10 @@ private: std::vector const& Vector; bool Search(std::string const& parent, cmFileList& lister) override { - for (std::string const& i : this->Vector) { - if (this->Consider(parent + i, lister)) { - return true; - } - } - return false; + return std::any_of(this->Vector.cbegin(), this->Vector.cend(), + [this, &parent, &lister](std::string const& i) { + return this->Consider(parent + i, lister); + }); } std::unique_ptr Clone() const override { @@ -2349,12 +2347,10 @@ private: this->SortOrder, this->SortDirection); } - for (std::string const& i : matches) { - if (this->Consider(parent + i, lister)) { - return true; - } - } - return false; + return std::any_of(matches.cbegin(), matches.cend(), + [this, &parent, &lister](std::string const& i) { + return this->Consider(parent + i, lister); + }); } std::unique_ptr Clone() const override { @@ -2401,12 +2397,10 @@ private: } } - for (std::string const& i : matches) { - if (this->Consider(parent + i, lister)) { - return true; - } - } - return false; + return std::any_of(matches.cbegin(), matches.cend(), + [this, &parent, &lister](std::string const& i) { + return this->Consider(parent + i, lister); + }); } std::unique_ptr Clone() const override { @@ -2483,12 +2477,10 @@ private: std::vector const& files = g.GetFiles(); // Look for directories among the matches. - for (std::string const& f : files) { - if (this->Consider(f, lister)) { - return true; - } - } - return false; + return std::any_of(files.cbegin(), files.cend(), + [this, &lister](std::string const& f) { + return this->Consider(f, lister); + }); } std::unique_ptr Clone() const override { -- cgit v0.12