Commit 2dfc5267 authored by wahikihiki's avatar wahikihiki

cmAlgorithms: Add cmContains

Also, use the new function where applicable.
parent c41c7928
Pipeline #144168 passed with stage
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCPackWIXGenerator.h"
#include "cmAlgorithms.h"
#include "cmCPackComponentGroup.h"
#include "cmCPackLog.h"
#include "cmCryptoHash.h"
......@@ -942,9 +943,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitions(
shortcut.workingDirectoryId = directoryId;
shortcuts.insert(cmWIXShortcuts::START_MENU, id, shortcut);
if (!desktopExecutables.empty() &&
std::find(desktopExecutables.begin(), desktopExecutables.end(),
executableName) != desktopExecutables.end()) {
if (cmContains(desktopExecutables, executableName)) {
shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut);
}
}
......
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCPackNSISGenerator.h"
#include "cmAlgorithms.h"
#include "cmCPackComponentGroup.h"
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
......@@ -501,10 +502,7 @@ int cmCPackNSISGenerator::InitializeInternal()
<< ".lnk\"" << std::endl;
// see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
// if so add a desktop link
if (!cpackPackageDesktopLinksVector.empty() &&
std::find(cpackPackageDesktopLinksVector.begin(),
cpackPackageDesktopLinksVector.end(),
execName) != cpackPackageDesktopLinksVector.end()) {
if (cmContains(cpackPackageDesktopLinksVector, execName)) {
str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
str << " CreateShortCut \"$DESKTOP\\" << linkName
<< R"(.lnk" "$INSTDIR\)" << cpackNsisExecutablesDirectory << "\\"
......
......@@ -173,8 +173,7 @@ bool cmCTestMultiProcessHandler::StartTestProcess(int test)
// Find any failed dependencies for this test. We assume the more common
// scenario has no failed tests, so make it the outer loop.
for (std::string const& f : *this->Failed) {
if (this->Properties[test]->RequireSuccessDepends.find(f) !=
this->Properties[test]->RequireSuccessDepends.end()) {
if (cmContains(this->Properties[test]->RequireSuccessDepends, f)) {
testRun->AddFailedDependency(f);
}
}
......@@ -275,7 +274,7 @@ bool cmCTestMultiProcessHandler::StartTest(int test)
{
// Check for locked resources
for (std::string const& i : this->Properties[test]->LockedResources) {
if (this->LockedResources.find(i) != this->LockedResources.end()) {
if (cmContains(this->LockedResources, i)) {
return false;
}
}
......@@ -621,9 +620,7 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
// In parallel test runs add previously failed tests to the front
// of the cost list and queue other tests for further sorting
for (auto const& t : this->Tests) {
if (std::find(this->LastTestsFailed.begin(), this->LastTestsFailed.end(),
this->Properties[t.first]->Name) !=
this->LastTestsFailed.end()) {
if (cmContains(this->LastTestsFailed, this->Properties[t.first]->Name)) {
// If the test failed last time, it should be run first.
this->SortedTests.push_back(t.first);
alreadySortedTests.insert(t.first);
......@@ -662,7 +659,7 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
TestComparator(this));
for (auto const& j : sortedCopy) {
if (alreadySortedTests.find(j) == alreadySortedTests.end()) {
if (!cmContains(alreadySortedTests, j)) {
this->SortedTests.push_back(j);
alreadySortedTests.insert(j);
}
......@@ -694,7 +691,7 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
TestSet alreadySortedTests;
for (int test : presortedList) {
if (alreadySortedTests.find(test) != alreadySortedTests.end()) {
if (cmContains(alreadySortedTests, test)) {
continue;
}
......@@ -702,8 +699,7 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
GetAllTestDependencies(test, dependencies);
for (int testDependency : dependencies) {
if (alreadySortedTests.find(testDependency) ==
alreadySortedTests.end()) {
if (!cmContains(alreadySortedTests, testDependency)) {
alreadySortedTests.insert(testDependency);
this->SortedTests.push_back(testDependency);
}
......
......@@ -20,6 +20,7 @@
#include "cm_memory.hxx"
#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestMultiProcessHandler.h"
#include "cmCommand.h"
......@@ -715,7 +716,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject)
cmCTestTestProperties& p = *result.Properties;
for (std::string const& l : p.Labels) {
// only use labels found in labels
if (labels.find(l) != labels.end()) {
if (cmContains(labels, l)) {
labelTimes[l] +=
result.ExecutionTime.count() * result.Properties->Processors;
++labelCounts[l];
......@@ -857,17 +858,14 @@ void cmCTestTestHandler::ComputeTestList()
if (this->UseUnion) {
// if it is not in the list and not in the regexp then skip
if ((!this->TestsToRun.empty() &&
std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt) ==
this->TestsToRun.end()) &&
if ((!this->TestsToRun.empty() && !cmContains(this->TestsToRun, cnt)) &&
!tp.IsInBasedOnREOptions) {
continue;
}
} else {
// is this test in the list of tests to run? If not then skip it
if ((!this->TestsToRun.empty() &&
std::find(this->TestsToRun.begin(), this->TestsToRun.end(),
inREcnt) == this->TestsToRun.end()) ||
!cmContains(this->TestsToRun, inREcnt)) ||
!tp.IsInBasedOnREOptions) {
continue;
}
......@@ -896,9 +894,7 @@ void cmCTestTestHandler::ComputeTestListForRerunFailed()
cnt++;
// if this test is not in our list of tests to run, then skip it.
if ((!this->TestsToRun.empty() &&
std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt) ==
this->TestsToRun.end())) {
if ((!this->TestsToRun.empty() && !cmContains(TestsToRun, cnt))) {
continue;
}
......@@ -1019,8 +1015,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
sIt != setupRange.second; ++sIt) {
const std::string& setupTestName = sIt->second->Name;
tests[i].RequireSuccessDepends.insert(setupTestName);
if (std::find(tests[i].Depends.begin(), tests[i].Depends.end(),
setupTestName) == tests[i].Depends.end()) {
if (!cmContains(tests[i].Depends, setupTestName)) {
tests[i].Depends.push_back(setupTestName);
}
}
......@@ -1127,8 +1122,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
const std::vector<size_t>& indices = cIt->second;
for (size_t index : indices) {
const std::string& reqTestName = tests[index].Name;
if (std::find(p.Depends.begin(), p.Depends.end(), reqTestName) ==
p.Depends.end()) {
if (!cmContains(p.Depends, reqTestName)) {
p.Depends.push_back(reqTestName);
}
}
......@@ -1141,8 +1135,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
const std::vector<size_t>& indices = cIt->second;
for (size_t index : indices) {
const std::string& setupTestName = tests[index].Name;
if (std::find(p.Depends.begin(), p.Depends.end(), setupTestName) ==
p.Depends.end()) {
if (!cmContains(p.Depends, setupTestName)) {
p.Depends.push_back(setupTestName);
}
}
......
......@@ -14,6 +14,16 @@
#include <utility>
#include <vector>
template <std::size_t N>
struct cmOverloadPriority : cmOverloadPriority<N - 1>
{
};
template <>
struct cmOverloadPriority<0>
{
};
template <typename FwdIt>
FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last)
{
......@@ -30,6 +40,34 @@ void cmEraseIf(Container& cont, Predicate pred)
cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
}
template <typename Range, typename Key>
auto cmContainsImpl(Range const& range, Key const& key, cmOverloadPriority<2>)
-> decltype(range.exists(key))
{
return range.exists(key);
}
template <typename Range, typename Key>
auto cmContainsImpl(Range const& range, Key const& key, cmOverloadPriority<1>)
-> decltype(range.find(key) != range.end())
{
return range.find(key) != range.end();
}
template <typename Range, typename Key>
bool cmContainsImpl(Range const& range, Key const& key, cmOverloadPriority<0>)
{
using std::begin;
using std::end;
return std::find(begin(range), end(range), key) != end(range);
}
template <typename Range, typename Key>
bool cmContains(Range const& range, Key const& key)
{
return cmContainsImpl(range, key, cmOverloadPriority<2>{});
}
namespace ContainerAlgorithms {
template <typename T>
......@@ -176,7 +214,7 @@ ForwardIterator cmRemoveDuplicates(ForwardIterator first, ForwardIterator last)
ForwardIterator result = first;
while (first != last) {
if (uniq.find(first) == uniq.end()) {
if (!cmContains(uniq, first)) {
if (result != first) {
*result = std::move(*first);
}
......
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmComputeLinkInformation.h"
#include "cmAlgorithms.h"
#include "cmComputeLinkDepends.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
......@@ -553,7 +554,7 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
std::vector<std::string> libsVec;
cmExpandList(libs, libsVec);
for (std::string const& i : libsVec) {
if (this->ImplicitLinkLibs.find(i) == this->ImplicitLinkLibs.end()) {
if (!cmContains(this->ImplicitLinkLibs, i)) {
this->AddItem(i, nullptr);
}
}
......@@ -998,8 +999,8 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& item,
// For compatibility with CMake 2.4 include the item's directory in
// the linker search path.
if (this->OldLinkDirMode && !target->IsFrameworkOnApple() &&
this->OldLinkDirMask.find(cmSystemTools::GetFilenamePath(item)) ==
this->OldLinkDirMask.end()) {
!cmContains(this->OldLinkDirMask,
cmSystemTools::GetFilenamePath(item))) {
this->OldLinkDirItems.push_back(item);
}
......@@ -1052,8 +1053,8 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
// For compatibility with CMake 2.4 include the item's directory in
// the linker search path.
if (this->OldLinkDirMode &&
this->OldLinkDirMask.find(cmSystemTools::GetFilenamePath(item)) ==
this->OldLinkDirMask.end()) {
!cmContains(this->OldLinkDirMask,
cmSystemTools::GetFilenamePath(item))) {
this->OldLinkDirItems.push_back(item);
}
......@@ -1072,7 +1073,7 @@ bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
// Check if this item is in an implicit link directory.
std::string dir = cmSystemTools::GetFilenamePath(item);
if (this->ImplicitLinkDirs.find(dir) == this->ImplicitLinkDirs.end()) {
if (!cmContains(this->ImplicitLinkDirs, dir)) {
// Only libraries in implicit link directories are converted to
// pathless items.
return false;
......
......@@ -3,7 +3,6 @@
#include "cmConditionEvaluator.h"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <functional>
#include <sstream>
#include <stdio.h>
......@@ -672,7 +671,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
std::vector<std::string> list;
cmExpandList(def2, list, true);
result = std::find(list.begin(), list.end(), def) != list.end();
result = cmContains(list, def);
}
this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2);
......
......@@ -2,10 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExportBuildAndroidMKGenerator.h"
#include <algorithm>
#include <sstream>
#include <utility>
#include "cmAlgorithms.h"
#include "cmGeneratorTarget.h"
#include "cmLinkItem.h"
#include "cmMakefile.h"
......@@ -167,8 +167,7 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
// Tell the NDK build system if prebuilt static libraries use C++.
if (target->GetType() == cmStateEnums::STATIC_LIBRARY) {
cmLinkImplementation const* li = target->GetLinkImplementation(config);
if (std::find(li->Languages.begin(), li->Languages.end(), "CXX") !=
li->Languages.end()) {
if (cmContains(li->Languages, "CXX")) {
os << "LOCAL_HAS_CPP := true\n";
}
}
......
......@@ -16,7 +16,6 @@
#include "cmTargetExport.h"
#include "cmake.h"
#include <algorithm>
#include <map>
#include <set>
#include <sstream>
......@@ -306,7 +305,7 @@ cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg,
const cmExportBuildFileGenerator* exportSet = exp.second;
std::vector<std::string> targets;
exportSet->GetTargets(targets);
if (std::find(targets.begin(), targets.end(), name) != targets.end()) {
if (cmContains(targets, name)) {
exportFiles.push_back(exp.first);
ns = exportSet->GetNamespace();
}
......
......@@ -5,11 +5,11 @@
#include "cm_static_string_view.hxx"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <map>
#include <sstream>
#include <utility>
#include "cmAlgorithms.h"
#include "cmArgumentParser.h"
#include "cmExportBuildAndroidMKGenerator.h"
#include "cmExportBuildFileGenerator.h"
......@@ -133,9 +133,7 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
}
ExportSet = it->second;
} else if (!arguments.Targets.empty() ||
std::find(keywordsMissingValue.begin(),
keywordsMissingValue.end(),
"TARGETS") != keywordsMissingValue.end()) {
cmContains(keywordsMissingValue, "TARGETS")) {
for (std::string const& currentTarget : arguments.Targets) {
if (this->Makefile->IsAlias(currentTarget)) {
std::ostringstream e;
......
......@@ -306,10 +306,7 @@ static const struct InListNode : public cmGeneratorExpressionNode
break;
}
return std::find(values.cbegin(), values.cend(), parameters.front()) ==
values.cend()
? "0"
: "1";
return cmContains(values, parameters.front()) ? "1" : "0";
}
} inListNode;
......@@ -915,9 +912,8 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
if (const char* mapValue =
context->CurrentTarget->GetProperty(mapProp)) {
cmExpandList(cmSystemTools::UpperCase(mapValue), mappedConfigs);
return std::find(mappedConfigs.begin(), mappedConfigs.end(),
cmSystemTools::UpperCase(parameters.front())) !=
mappedConfigs.end()
return cmContains(mappedConfigs,
cmSystemTools::UpperCase(parameters.front()))
? "1"
: "0";
}
......@@ -1510,8 +1506,7 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
"CMAKE_" + lit.first + "_STANDARD_DEFAULT");
for (std::string const& it : lit.second) {
if (std::find(langAvailable.begin(), langAvailable.end(), it) ==
langAvailable.end()) {
if (!cmContains(langAvailable, it)) {
return "0";
}
if (standardDefault && !*standardDefault) {
......
......@@ -1421,9 +1421,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
cmExpandList(debugProp, debugProperties);
}
bool debugSources = !this->DebugSourcesDone &&
std::find(debugProperties.begin(), debugProperties.end(), "SOURCES") !=
debugProperties.end();
bool debugSources =
!this->DebugSourcesDone && cmContains(debugProperties, "SOURCES");
if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
this->DebugSourcesDone = true;
......@@ -2647,7 +2646,7 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
for (cmSourceFile* sf : sources) {
const std::set<cmGeneratorTarget const*> tgts =
this->GlobalGenerator->GetFilenameTargetDepends(sf);
if (tgts.find(this->GeneratorTarget) != tgts.end()) {
if (cmContains(tgts, this->GeneratorTarget)) {
std::ostringstream e;
e << "Evaluation output file\n \"" << sf->GetFullPath()
<< "\"\ndepends on the sources of a target it is used in. This "
......@@ -3072,8 +3071,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
}
bool debugIncludes = !this->DebugIncludesDone &&
std::find(debugProperties.begin(), debugProperties.end(),
"INCLUDE_DIRECTORIES") != debugProperties.end();
cmContains(debugProperties, "INCLUDE_DIRECTORIES");
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugIncludesDone = true;
......@@ -3183,8 +3181,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
}
bool debugOptions = !this->DebugCompileOptionsDone &&
std::find(debugProperties.begin(), debugProperties.end(),
"COMPILE_OPTIONS") != debugProperties.end();
cmContains(debugProperties, "COMPILE_OPTIONS");
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugCompileOptionsDone = true;
......@@ -3230,8 +3227,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
}
bool debugFeatures = !this->DebugCompileFeaturesDone &&
std::find(debugProperties.begin(), debugProperties.end(),
"COMPILE_FEATURES") != debugProperties.end();
cmContains(debugProperties, "COMPILE_FEATURES");
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugCompileFeaturesDone = true;
......@@ -3279,8 +3275,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
}
bool debugDefines = !this->DebugCompileDefinitionsDone &&
std::find(debugProperties.begin(), debugProperties.end(),
"COMPILE_DEFINITIONS") != debugProperties.end();
cmContains(debugProperties, "COMPILE_DEFINITIONS");
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugCompileDefinitionsDone = true;
......@@ -3353,9 +3348,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
cmExpandList(debugProp, debugProperties);
}
bool debugOptions = !this->DebugLinkOptionsDone &&
std::find(debugProperties.begin(), debugProperties.end(),
"LINK_OPTIONS") != debugProperties.end();
bool debugOptions =
!this->DebugLinkOptionsDone && cmContains(debugProperties, "LINK_OPTIONS");
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugLinkOptionsDone = true;
......@@ -3612,8 +3606,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
}
bool debugDirectories = !this->DebugLinkDirectoriesDone &&
std::find(debugProperties.begin(), debugProperties.end(),
"LINK_DIRECTORIES") != debugProperties.end();
cmContains(debugProperties, "LINK_DIRECTORIES");
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugLinkDirectoriesDone = true;
......@@ -4784,9 +4777,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
const bool explicitlySet =
std::find(headPropKeys.begin(), headPropKeys.end(), p) !=
headPropKeys.end();
const bool explicitlySet = cmContains(headPropKeys, p);
const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
......@@ -4826,8 +4817,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(),
interfaceProperty) != propKeys.end();
const bool ifaceIsSet = cmContains(propKeys, interfaceProperty);
PropertyType ifacePropContent = getTypedProperty<PropertyType>(
theTarget, interfaceProperty, genexInterpreter.get());
......@@ -5112,9 +5102,8 @@ void cmGeneratorTarget::ReportPropertyOrigin(
cmExpandList(debugProp, debugProperties);
}
bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
std::find(debugProperties.begin(), debugProperties.end(), p) !=
debugProperties.end();
bool debugOrigin =
!this->DebugCompatiblePropertiesDone[p] && cmContains(debugProperties, p);
if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
this->DebugCompatiblePropertiesDone[p] = true;
......@@ -6226,8 +6215,7 @@ cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
const std::string& p) const
{
return this->LinkImplicitNullProperties.find(p) !=
this->LinkImplicitNullProperties.end();
return cmContains(this->LinkImplicitNullProperties, p);
}
void cmGeneratorTarget::ComputeLinkImplementationLibraries(
......
......@@ -368,8 +368,7 @@ bool cmGlobalGenerator::IsExportedTargetsFile(
if (it == this->BuildExportSets.end()) {
return false;
}
return this->BuildExportExportSets.find(filename) ==
this->BuildExportExportSets.end();
return !cmContains(this->BuildExportExportSets, filename);
}
// Find the make program for the generator, required for try compiles
......@@ -497,7 +496,7 @@ void cmGlobalGenerator::EnableLanguage(
if (lang == "NONE") {
this->SetLanguageEnabled("NONE", mf);
} else {
if (this->LanguagesReady.find(lang) == this->LanguagesReady.end()) {
if (!cmContains(this->LanguagesReady, lang)) {
std::ostringstream e;
e << "The test project needs language " << lang
<< " which is not enabled.";
......@@ -1097,8 +1096,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
{
// use LanguageToLinkerPreference to detect whether this functions has
// run before
if (this->LanguageToLinkerPreference.find(l) !=
this->LanguageToLinkerPreference.end()) {
if (cmContains(this->LanguageToLinkerPreference, l)) {
return;
}
......@@ -2153,7 +2151,7 @@ void cmGlobalGenerator::AddAlias(const std::string& name,
bool cmGlobalGenerator::IsAlias(const std::string& name) const
{
return this->AliasTargets.find(name) != this->AliasTargets.end();
return cmContains(this->AliasTargets, name);
}
void cmGlobalGenerator::IndexTarget(cmTarget* t)
......@@ -2703,8 +2701,7 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
"clean", "edit_cache", "rebuild_cache",
"ZERO_CHECK" };
return std::find(cm::cbegin(reservedTargets), cm::cend(reservedTargets),
name) != cm::cend(reservedTargets);
return cmContains(reservedTargets, name);
}
void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
......
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalGhsMultiGenerator.h"
#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
......@@ -589,16 +590,14 @@ cmGlobalGhsMultiGenerator::GenerateBuildCommand(
/* if multiple top-projects are found in build directory
* then prefer projectName top-project.
*/
auto p = std::find(files.begin(), files.end(), proj);
if (p == files.end()) {
if (!cmContains(files, proj)) {
proj = files.at(0);
}
}
makeCommand.Add("-top", proj);
if (!targetNames.empty()) {
if (std::find(targetNames.begin(), targetNames.end(), "clean") !=
targetNames.end()) {
if (cmContains(targetNames, "clean")) {
makeCommand.Add("-clean");
} else {
for (const auto& tname : targetNames) {
......
......@@ -571,8 +571,7 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures()
bool cmGlobalNinjaGenerator::CheckLanguages(
std::vector<std::string> const& languages, cmMakefile* mf) const
{
if (std::find(languages.begin(), languages.end(), "Fortran") !=
languages.end()) {
if (cmContains(languages, "Fortran")) {
return this->CheckFortran(mf);
}
return true;
......
......@@ -354,8 +354,7 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
projectArg += "proj";
makeCommand.Add(projectArg);
}
if (std::find(targetNames.begin(), targetNames.end(), "clean") !=
targetNames.end()) {
if (cmContains(targetNames, "clean")) {
makeCommand.Add("clean");
makeCommand.Add("-target", "ALL_BUILD");
} else {
......@@ -903,8 +902,7 @@ void cmGlobalXCodeGenerator::AddXCodeProjBuildRule(
target->GetLocalGenerator()->GetCurrentSourceDirectory();
listfile += "/CMakeLists.txt";
cmSourceFile* srcCMakeLists = target->Makefile->GetOrCreateSource(listfile);
if (std::find(sources.begin(), sources.end(), srcCMakeLists) ==
sources.end()) {
if (!cmContains(sources, srcCMakeLists)) {
sources.push_back(srcCMakeLists);
}
}
......@@ -1417,10 +1415,8 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
{
const std::vector<std::string>& hdrExts =
this->CMakeInstance->GetHeaderExtensions();
return (std::find(hdrExts.begin(), hdrExts.end(), sf->GetExtension()) !=
hdrExts.end());
return cmContains(this->CMakeInstance->GetHeaderExtensions(),
sf->GetExtension());
}
cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase(
......
......@@ -5,12 +5,12 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <algorithm>
#include <map>
#include <ostream>
#include <string>
#include <vector>
#include "cmAlgorithms.h"
#include "cmListFileCache.h"
#include "cmSystemTools.h"
#include "cmTargetLinkLibraryType.h"
......@@ -120,8 +120,7 @@ inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
// Check if any entry in the list matches this configuration.
std::string configUpper = cmSystemTools::UpperCase(config);
if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
debugConfigs.end()) {
if (cmContains(debugConfigs, configUpper)) {
return DEBUG_LibraryType;
}
// The current configuration is not a debug configuration.
......
......@@ -3,12 +3,11 @@
#include "cmLinkLineDeviceComputer.h"
#include <algorithm>
#include <set>
#include <sstream>
#include <utility>
#include <vector>
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
......@@ -187,14 +186,10 @@ bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg,
// Determine if we have any dependencies that require
// us to do a device link step
const std::string cuda_lang("CUDA");
cmGeneratorTarget::LinkClosure const* closure =
target.GetLinkClosure(config);
bool closureHasCUDA =
(std::find(closure->Languages.begin(), closure->Languages.end(),
cuda_lang) != closure->Languages.end());
if (closureHasCUDA) {
if (cmContains(closure->Languages, "CUDA")) {
cmComputeLinkInformation* pcli = target.GetLinkInformation(config);
if (pcli) {
cmLinkLineDeviceComputer deviceLinkComputer(
......
......@@ -121,7 +121,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list,
// expand the variable into a list
cmExpandList(listString, list, true);
// if no empty elements then just return
if (std::find(list.begin(), list.end(), std::string()) == list.end()) {
if (!cmContains(list, std::string())) {
return true;
}
// if we have empty elements we need to check policy CMP0007
......
......@@ -996,8 +996,7 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
// directly. In this case adding -I/usr/include can hide SDK headers so we
// must still exclude it.
if ((lang == "C" || lang == "CXX" || lang == "CUDA") &&
std::find(impDirVec.begin(), impDirVec.end(), "/usr/include") ==
impDirVec.end() &&
!cmContains(impDirVec, "/usr/include") &&