Browse Source

clang-tidy: fix `readability-use-anyofallof` lints

Ben Boeckel 2 years ago
parent
commit
707172c66e

+ 6 - 7
Source/cmGlobalVisualStudio7Generator.cxx

@@ -737,13 +737,12 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
 bool cmGlobalVisualStudio7Generator::IsDependedOn(
   OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn)
 {
-  for (cmTargetDepend const& l : projectTargets) {
-    TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(l);
-    if (tgtdeps.count(gtIn)) {
-      return true;
-    }
-  }
-  return false;
+  return std::any_of(projectTargets.begin(), projectTargets.end(),
+                     [this, gtIn](cmTargetDepend const& l) {
+                       TargetDependSet const& tgtdeps =
+                         this->GetTargetDirectDepends(l);
+                       return tgtdeps.count(gtIn);
+                     });
 }
 
 std::string cmGlobalVisualStudio7Generator::Encoding()

+ 16 - 13
Source/cmGlobalVisualStudio8Generator.cxx

@@ -405,20 +405,23 @@ bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
   cmGeneratorTarget* target)
 {
   // Look for utility dependencies that magically link.
-  for (BT<std::pair<std::string, bool>> const& ui : target->GetUtilities()) {
-    if (cmGeneratorTarget* depTarget =
-          target->GetLocalGenerator()->FindGeneratorTargetToUse(
-            ui.Value.first)) {
-      if (depTarget->IsInBuildSystem() &&
-          depTarget->GetProperty("EXTERNAL_MSPROJECT")) {
-        // This utility dependency names an external .vcproj target.
-        // We use LinkLibraryDependencies="true" to link to it without
-        // predicting the .lib file location or name.
-        return true;
+  auto const& utilities = target->GetUtilities();
+  return std::any_of(
+    utilities.begin(), utilities.end(),
+    [target](BT<std::pair<std::string, bool>> const& ui) {
+      if (cmGeneratorTarget* depTarget =
+            target->GetLocalGenerator()->FindGeneratorTargetToUse(
+              ui.Value.first)) {
+        if (depTarget->IsInBuildSystem() &&
+            depTarget->GetProperty("EXTERNAL_MSPROJECT")) {
+          // This utility dependency names an external .vcproj target.
+          // We use LinkLibraryDependencies="true" to link to it without
+          // predicting the .lib file location or name.
+          return true;
+        }
       }
-    }
-  }
-  return false;
+      return false;
+    });
 }
 
 static cmVS7FlagTable cmVS8ExtraFlagTable[] = {

+ 29 - 51
Source/cmVisualStudio10TargetGenerator.cxx

@@ -1056,14 +1056,11 @@ bool cmVisualStudio10TargetGenerator::HasCustomCommands() const
     return true;
   }
 
-  for (cmGeneratorTarget::AllConfigSource const& si :
-       this->GeneratorTarget->GetAllConfigSources()) {
-    if (si.Source->GetCustomCommand()) {
-      return true;
-    }
-  }
-
-  return false;
+  auto const& config_sources = this->GeneratorTarget->GetAllConfigSources();
+  return std::any_of(config_sources.begin(), config_sources.end(),
+                     [](cmGeneratorTarget::AllConfigSource const& si) {
+                       return si.Source->GetCustomCommand();
+                     });
 }
 
 void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
@@ -3069,12 +3066,9 @@ std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes(
 
 bool cmVisualStudio10TargetGenerator::ComputeClOptions()
 {
-  for (std::string const& c : this->Configurations) {
-    if (!this->ComputeClOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(
+    this->Configurations.begin(), this->Configurations.end(),
+    [this](std::string const& c) { return this->ComputeClOptions(c); });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeClOptions(
@@ -3445,12 +3439,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
 
 bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
 {
-  for (std::string const& c : this->Configurations) {
-    if (!this->ComputeRcOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(
+    this->Configurations.begin(), this->Configurations.end(),
+    [this](std::string const& c) { return this->ComputeRcOptions(c); });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
@@ -3499,13 +3490,12 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
   if (!this->GlobalGenerator->IsCudaEnabled()) {
     return true;
   }
-  for (std::string const& c : this->Configurations) {
-    if (this->GeneratorTarget->IsLanguageUsed("CUDA", c) &&
-        !this->ComputeCudaOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(this->Configurations.begin(), this->Configurations.end(),
+                     [this](std::string const& c) {
+                       return !this->GeneratorTarget->IsLanguageUsed("CUDA",
+                                                                     c) ||
+                         this->ComputeCudaOptions(c);
+                     });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
@@ -3675,12 +3665,9 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
   if (!this->GlobalGenerator->IsCudaEnabled()) {
     return true;
   }
-  for (std::string const& c : this->Configurations) {
-    if (!this->ComputeCudaLinkOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(
+    this->Configurations.begin(), this->Configurations.end(),
+    [this](std::string const& c) { return this->ComputeCudaLinkOptions(c); });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
@@ -3774,12 +3761,9 @@ bool cmVisualStudio10TargetGenerator::ComputeMarmasmOptions()
   if (!this->GlobalGenerator->IsMarmasmEnabled()) {
     return true;
   }
-  for (std::string const& c : this->Configurations) {
-    if (!this->ComputeMarmasmOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(
+    this->Configurations.begin(), this->Configurations.end(),
+    [this](std::string const& c) { return this->ComputeMarmasmOptions(c); });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeMarmasmOptions(
@@ -3827,12 +3811,9 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
   if (!this->GlobalGenerator->IsMasmEnabled()) {
     return true;
   }
-  for (std::string const& c : this->Configurations) {
-    if (!this->ComputeMasmOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(
+    this->Configurations.begin(), this->Configurations.end(),
+    [this](std::string const& c) { return this->ComputeMasmOptions(c); });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
@@ -3880,12 +3861,9 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
   if (!this->GlobalGenerator->IsNasmEnabled()) {
     return true;
   }
-  for (std::string const& c : this->Configurations) {
-    if (!this->ComputeNasmOptions(c)) {
-      return false;
-    }
-  }
-  return true;
+  return std::all_of(
+    this->Configurations.begin(), this->Configurations.end(),
+    [this](std::string const& c) { return this->ComputeNasmOptions(c); });
 }
 
 bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(

+ 4 - 12
Source/cmVisualStudioGeneratorOptions.cxx

@@ -137,22 +137,14 @@ bool cmVisualStudioGeneratorOptions::IsManaged() const
 bool cmVisualStudioGeneratorOptions::UsingUnicode() const
 {
   // Look for a _UNICODE definition.
-  for (std::string const& di : this->Defines) {
-    if (di == "_UNICODE") {
-      return true;
-    }
-  }
-  return false;
+  return std::any_of(this->Defines.begin(), this->Defines.end(),
+                     [](std::string const& di) { return di == "_UNICODE"; });
 }
 bool cmVisualStudioGeneratorOptions::UsingSBCS() const
 {
   // Look for a _SBCS definition.
-  for (std::string const& di : this->Defines) {
-    if (di == "_SBCS") {
-      return true;
-    }
-  }
-  return false;
+  return std::any_of(this->Defines.begin(), this->Defines.end(),
+                     [](std::string const& di) { return di == "_SBCS"; });
 }
 
 void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration()