瀏覽代碼

Refactoring: add cm::contains to <cmext/algorithm>

Marc Chevrier 5 年之前
父節點
當前提交
aacd4e4a90
共有 39 個文件被更改,包括 259 次插入186 次删除
  1. 7 4
      Help/dev/source.rst
  2. 2 2
      Source/CPack/WiX/cmCPackWIXGenerator.cxx
  3. 3 2
      Source/CPack/cmCPackNSISGenerator.cxx
  4. 3 2
      Source/CTest/cmCTestCoverageCommand.cxx
  5. 4 3
      Source/CTest/cmCTestMemCheckHandler.cxx
  6. 6 7
      Source/CTest/cmCTestMultiProcessHandler.cxx
  7. 5 3
      Source/CTest/cmCTestSubmitCommand.cxx
  8. 9 8
      Source/CTest/cmCTestTestHandler.cxx
  9. 3 39
      Source/cmAlgorithms.h
  10. 8 8
      Source/cmComputeLinkInformation.cxx
  11. 1 2
      Source/cmConditionEvaluator.cxx
  12. 3 2
      Source/cmExportBuildAndroidMKGenerator.cxx
  13. 3 2
      Source/cmExportBuildFileGenerator.cxx
  14. 2 2
      Source/cmExportCommand.cxx
  15. 2 2
      Source/cmFileCommand.cxx
  16. 5 4
      Source/cmGeneratorExpressionNode.cxx
  17. 18 16
      Source/cmGeneratorTarget.cxx
  18. 6 5
      Source/cmGlobalGenerator.cxx
  19. 3 3
      Source/cmGlobalGhsMultiGenerator.cxx
  20. 2 3
      Source/cmGlobalNinjaGenerator.cxx
  21. 4 5
      Source/cmGlobalXCodeGenerator.cxx
  22. 3 2
      Source/cmLinkItem.h
  23. 3 2
      Source/cmLinkLineDeviceComputer.cxx
  24. 2 1
      Source/cmListCommand.cxx
  25. 6 6
      Source/cmLocalGenerator.cxx
  26. 2 1
      Source/cmLocalVisualStudio7Generator.cxx
  27. 16 17
      Source/cmMakefile.cxx
  28. 1 2
      Source/cmQtAutoGen.cxx
  29. 4 4
      Source/cmQtAutoGenInitializer.cxx
  30. 2 2
      Source/cmServerProtocol.cxx
  31. 3 2
      Source/cmSourceGroupCommand.cxx
  32. 4 4
      Source/cmVisualStudio10TargetGenerator.cxx
  33. 6 3
      Source/cmXCodeObject.h
  34. 3 1
      Source/cmXCodeScheme.cxx
  35. 1 2
      Source/cmake.cxx
  36. 1 2
      Source/cmcmd.cxx
  37. 90 2
      Utilities/std/cmext/algorithm
  38. 11 9
      Utilities/std/cmext/iterator
  39. 2 0
      Utilities/std/cmext/type_traits

+ 7 - 4
Help/dev/source.rst

@@ -108,6 +108,9 @@ These are:
   * ``cm::append``:
     Append elements to a sequential container.
 
+  * ``cm::contains``:
+    Checks if element or key is contained in container.
+
 * ``<cmext/iterator>``:
 
   * ``cm::is_terator``:
@@ -117,12 +120,12 @@ These are:
     Checks if a type is an input iterator type.
 
   * ``cm::is_range``:
-    Checks if a type is a range type: must have methods ``begin()`` and
-    ``end()`` returning an iterator.
+    Checks if a type is a range type: functions ``std::begin()`` and
+    ``std::end()`` apply.
 
   * ``cm::is_input_range``:
-    Checks if a type is an input range type: must have methods ``begin()`` and
-    ``end()`` returning an input iterator.
+    Checks if a type is an input range type: functions ``std::begin()`` and
+    ``std::end()`` apply and return an input iterator.
 
 * ``<cmext/memory>``:
 

+ 2 - 2
Source/CPack/WiX/cmCPackWIXGenerator.cxx

@@ -6,13 +6,13 @@
 
 #include <cm/memory>
 #include <cm/string_view>
+#include <cmext/algorithm>
 
 #include "cmsys/Directory.hxx"
 #include "cmsys/Encoding.hxx"
 #include "cmsys/FStream.hxx"
 #include "cmsys/SystemTools.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmCPackComponentGroup.h"
 #include "cmCPackLog.h"
 #include "cmCryptoHash.h"
@@ -954,7 +954,7 @@ void cmCPackWIXGenerator::AddDirectoryAndFileDefinitions(
           shortcut.workingDirectoryId = directoryId;
           shortcuts.insert(cmWIXShortcuts::START_MENU, id, shortcut);
 
-          if (cmContains(desktopExecutables, executableName)) {
+          if (cm::contains(desktopExecutables, executableName)) {
             shortcuts.insert(cmWIXShortcuts::DESKTOP, id, shortcut);
           }
         }

+ 3 - 2
Source/CPack/cmCPackNSISGenerator.cxx

@@ -9,10 +9,11 @@
 #include <sstream>
 #include <utility>
 
+#include <cmext/algorithm>
+
 #include "cmsys/Directory.hxx"
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmCPackComponentGroup.h"
 #include "cmCPackGenerator.h"
 #include "cmCPackLog.h"
@@ -529,7 +530,7 @@ int cmCPackNSISGenerator::InitializeInternal()
                 << ".lnk\"" << std::endl;
       // see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
       // if so add a desktop link
-      if (cmContains(cpackPackageDesktopLinksVector, execName)) {
+      if (cm::contains(cpackPackageDesktopLinksVector, execName)) {
         str << "  StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
         str << "    CreateShortCut \"$DESKTOP\\" << linkName
             << R"(.lnk" "$INSTDIR\)" << cpackNsisExecutablesDirectory << "\\"

+ 3 - 2
Source/CTest/cmCTestCoverageCommand.cxx

@@ -4,9 +4,10 @@
 
 #include <set>
 
+#include <cmext/algorithm>
+
 #include "cm_static_string_view.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTestCoverageHandler.h"
 
@@ -22,7 +23,7 @@ void cmCTestCoverageCommand::CheckArguments(
   std::vector<std::string> const& keywords)
 {
   this->LabelsMentioned =
-    !this->Labels.empty() || cmContains(keywords, "LABELS");
+    !this->Labels.empty() || cm::contains(keywords, "LABELS");
 }
 
 cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()

+ 4 - 3
Source/CTest/cmCTestMemCheckHandler.cxx

@@ -10,11 +10,12 @@
 #include <sstream>
 #include <utility>
 
+#include <cmext/algorithm>
+
 #include "cmsys/FStream.hxx"
 #include "cmsys/Glob.hxx"
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmDuration.h"
 #include "cmSystemTools.h"
@@ -594,11 +595,11 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
       std::string tempDrMemoryDir =
         this->CTest->GetBinaryDir() + "/Testing/Temporary/DrMemory";
 
-      if (!cmContains(this->MemoryTesterOptions, "-quiet")) {
+      if (!cm::contains(this->MemoryTesterOptions, "-quiet")) {
         this->MemoryTesterOptions.emplace_back("-quiet");
       }
 
-      if (!cmContains(this->MemoryTesterOptions, "-batch")) {
+      if (!cm::contains(this->MemoryTesterOptions, "-batch")) {
         this->MemoryTesterOptions.emplace_back("-batch");
       }
 

+ 6 - 7
Source/CTest/cmCTestMultiProcessHandler.cxx

@@ -29,7 +29,6 @@
 #include "cm_uv.h"
 
 #include "cmAffinity.h"
-#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTestBinPacker.h"
 #include "cmCTestRunTest.h"
@@ -188,7 +187,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 (cmContains(this->Properties[test]->RequireSuccessDepends, f)) {
+    if (cm::contains(this->Properties[test]->RequireSuccessDepends, f)) {
       testRun->AddFailedDependency(f);
     }
   }
@@ -445,7 +444,7 @@ bool cmCTestMultiProcessHandler::StartTest(int test)
 {
   // Check for locked resources
   for (std::string const& i : this->Properties[test]->LockedResources) {
-    if (cmContains(this->LockedResources, i)) {
+    if (cm::contains(this->LockedResources, i)) {
       return false;
     }
   }
@@ -802,7 +801,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 (cmContains(this->LastTestsFailed, this->Properties[t.first]->Name)) {
+    if (cm::contains(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);
@@ -841,7 +840,7 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
                      TestComparator(this));
 
     for (auto const& j : sortedCopy) {
-      if (!cmContains(alreadySortedTests, j)) {
+      if (!cm::contains(alreadySortedTests, j)) {
         this->SortedTests.push_back(j);
         alreadySortedTests.insert(j);
       }
@@ -873,7 +872,7 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
   TestSet alreadySortedTests;
 
   for (int test : presortedList) {
-    if (cmContains(alreadySortedTests, test)) {
+    if (cm::contains(alreadySortedTests, test)) {
       continue;
     }
 
@@ -881,7 +880,7 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
     GetAllTestDependencies(test, dependencies);
 
     for (int testDependency : dependencies) {
-      if (!cmContains(alreadySortedTests, testDependency)) {
+      if (!cm::contains(alreadySortedTests, testDependency)) {
         alreadySortedTests.insert(testDependency);
         this->SortedTests.push_back(testDependency);
       }

+ 5 - 3
Source/CTest/cmCTestSubmitCommand.cxx

@@ -8,10 +8,10 @@
 
 #include <cm/memory>
 #include <cm/vector>
+#include <cmext/algorithm>
 
 #include "cm_static_string_view.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTestSubmitHandler.h"
 #include "cmCommand.h"
@@ -172,8 +172,10 @@ void cmCTestSubmitCommand::BindArguments()
 void cmCTestSubmitCommand::CheckArguments(
   std::vector<std::string> const& keywords)
 {
-  this->PartsMentioned = !this->Parts.empty() || cmContains(keywords, "PARTS");
-  this->FilesMentioned = !this->Files.empty() || cmContains(keywords, "FILES");
+  this->PartsMentioned =
+    !this->Parts.empty() || cm::contains(keywords, "PARTS");
+  this->FilesMentioned =
+    !this->Files.empty() || cm::contains(keywords, "FILES");
 
   cm::erase_if(this->Parts, [this](std::string const& arg) -> bool {
     cmCTest::Part p = this->CTest->GetPartFromName(arg.c_str());

+ 9 - 8
Source/CTest/cmCTestTestHandler.cxx

@@ -19,6 +19,7 @@
 
 #include <cm/memory>
 #include <cm/string_view>
+#include <cmext/algorithm>
 
 #include "cmsys/FStream.hxx"
 #include <cmsys/Base64.h>
@@ -28,7 +29,6 @@
 #include "cm_static_string_view.hxx"
 #include "cm_utf8.h"
 
-#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTestMultiProcessHandler.h"
 #include "cmCTestResourceGroupsLexerHelper.h"
@@ -711,7 +711,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject)
     cmCTestTestProperties& p = *result.Properties;
     for (std::string const& l : p.Labels) {
       // only use labels found in labels
-      if (cmContains(labels, l)) {
+      if (cm::contains(labels, l)) {
         labelTimes[l] +=
           result.ExecutionTime.count() * result.Properties->Processors;
         ++labelCounts[l];
@@ -853,14 +853,15 @@ void cmCTestTestHandler::ComputeTestList()
 
     if (this->UseUnion) {
       // if it is not in the list and not in the regexp then skip
-      if ((!this->TestsToRun.empty() && !cmContains(this->TestsToRun, cnt)) &&
+      if ((!this->TestsToRun.empty() &&
+           !cm::contains(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() &&
-           !cmContains(this->TestsToRun, inREcnt)) ||
+           !cm::contains(this->TestsToRun, inREcnt)) ||
           !tp.IsInBasedOnREOptions) {
         continue;
       }
@@ -889,7 +890,7 @@ void cmCTestTestHandler::ComputeTestListForRerunFailed()
     cnt++;
 
     // if this test is not in our list of tests to run, then skip it.
-    if (!this->TestsToRun.empty() && !cmContains(this->TestsToRun, cnt)) {
+    if (!this->TestsToRun.empty() && !cm::contains(this->TestsToRun, cnt)) {
       continue;
     }
 
@@ -1008,7 +1009,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
       for (auto sIt = setupRange.first; sIt != setupRange.second; ++sIt) {
         const std::string& setupTestName = sIt->second->Name;
         tests[i].RequireSuccessDepends.insert(setupTestName);
-        if (!cmContains(tests[i].Depends, setupTestName)) {
+        if (!cm::contains(tests[i].Depends, setupTestName)) {
           tests[i].Depends.push_back(setupTestName);
         }
       }
@@ -1112,7 +1113,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 (!cmContains(p.Depends, reqTestName)) {
+          if (!cm::contains(p.Depends, reqTestName)) {
             p.Depends.push_back(reqTestName);
           }
         }
@@ -1125,7 +1126,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 (!cmContains(p.Depends, setupTestName)) {
+          if (!cm::contains(p.Depends, setupTestName)) {
             p.Depends.push_back(setupTestName);
           }
         }

+ 3 - 39
Source/cmAlgorithms.h

@@ -13,20 +13,12 @@
 #include <utility>
 #include <vector>
 
+#include <cmext/algorithm>
+
 #include "cm_kwiml.h"
 
 #include "cmRange.h"
 
-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)
 {
@@ -37,34 +29,6 @@ FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last)
   return first;
 }
 
-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 FwdIt>
@@ -158,7 +122,7 @@ ForwardIterator cmRemoveDuplicates(ForwardIterator first, ForwardIterator last)
 
   ForwardIterator result = first;
   while (first != last) {
-    if (!cmContains(uniq, first)) {
+    if (!cm::contains(uniq, first)) {
       if (result != first) {
         *result = std::move(*first);
       }

+ 8 - 8
Source/cmComputeLinkInformation.cxx

@@ -9,8 +9,8 @@
 #include <utility>
 
 #include <cm/memory>
+#include <cmext/algorithm>
 
-#include "cmAlgorithms.h"
 #include "cmComputeLinkDepends.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
@@ -610,7 +610,7 @@ void cmComputeLinkInformation::AddRuntimeLinkLibrary(std::string const& lang)
             runtimeLibrary)) {
         std::vector<std::string> libsVec = cmExpandedList(runtimeLinkOptions);
         for (std::string const& i : libsVec) {
-          if (!cmContains(this->ImplicitLinkLibs, i)) {
+          if (!cm::contains(this->ImplicitLinkLibs, i)) {
             this->AddItem(i, nullptr);
           }
         }
@@ -627,7 +627,7 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
   if (const char* libs = this->Makefile->GetDefinition(libVar)) {
     std::vector<std::string> libsVec = cmExpandedList(libs);
     for (std::string const& i : libsVec) {
-      if (!cmContains(this->ImplicitLinkLibs, i)) {
+      if (!cm::contains(this->ImplicitLinkLibs, i)) {
         this->AddItem(i, nullptr);
       }
     }
@@ -1064,8 +1064,8 @@ void cmComputeLinkInformation::AddTargetItem(BT<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() &&
-      !cmContains(this->OldLinkDirMask,
-                  cmSystemTools::GetFilenamePath(item.Value))) {
+      !cm::contains(this->OldLinkDirMask,
+                    cmSystemTools::GetFilenamePath(item.Value))) {
     this->OldLinkDirItems.push_back(item.Value);
   }
 
@@ -1118,8 +1118,8 @@ void cmComputeLinkInformation::AddFullItem(BT<std::string> const& item)
   // For compatibility with CMake 2.4 include the item's directory in
   // the linker search path.
   if (this->OldLinkDirMode &&
-      !cmContains(this->OldLinkDirMask,
-                  cmSystemTools::GetFilenamePath(item.Value))) {
+      !cm::contains(this->OldLinkDirMask,
+                    cmSystemTools::GetFilenamePath(item.Value))) {
     this->OldLinkDirItems.push_back(item.Value);
   }
 
@@ -1138,7 +1138,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 (!cmContains(this->ImplicitLinkDirs, dir)) {
+  if (!cm::contains(this->ImplicitLinkDirs, dir)) {
     // Only libraries in implicit link directories are converted to
     // pathless items.
     return false;

+ 1 - 2
Source/cmConditionEvaluator.cxx

@@ -13,7 +13,6 @@
 
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
 #include "cmState.h"
@@ -673,7 +672,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
           if (def2) {
             std::vector<std::string> list = cmExpandedList(def2, true);
 
-            result = cmContains(list, def);
+            result = cm::contains(list, def);
           }
 
           this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2);

+ 3 - 2
Source/cmExportBuildAndroidMKGenerator.cxx

@@ -5,7 +5,8 @@
 #include <sstream>
 #include <utility>
 
-#include "cmAlgorithms.h"
+#include <cmext/algorithm>
+
 #include "cmGeneratorTarget.h"
 #include "cmLinkItem.h"
 #include "cmMakefile.h"
@@ -165,7 +166,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 (cmContains(li->Languages, "CXX")) {
+    if (cm::contains(li->Languages, "CXX")) {
       os << "LOCAL_HAS_CPP := true\n";
     }
   }

+ 3 - 2
Source/cmExportBuildFileGenerator.cxx

@@ -8,7 +8,8 @@
 #include <sstream>
 #include <utility>
 
-#include "cmAlgorithms.h"
+#include <cmext/algorithm>
+
 #include "cmExportSet.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
@@ -307,7 +308,7 @@ cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg,
     const auto& exportSet = exp.second;
     std::vector<std::string> targets;
     exportSet->GetTargets(targets);
-    if (cmContains(targets, name)) {
+    if (cm::contains(targets, name)) {
       exportFiles.push_back(exp.first);
       ns = exportSet->GetNamespace();
     }

+ 2 - 2
Source/cmExportCommand.cxx

@@ -7,12 +7,12 @@
 #include <utility>
 
 #include <cm/memory>
+#include <cmext/algorithm>
 
 #include "cmsys/RegularExpression.hxx"
 
 #include "cm_static_string_view.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmArgumentParser.h"
 #include "cmExecutionStatus.h"
 #include "cmExportBuildAndroidMKGenerator.h"
@@ -147,7 +147,7 @@ bool cmExportCommand(std::vector<std::string> const& args,
     }
     exportSet = &it->second;
   } else if (!arguments.Targets.empty() ||
-             cmContains(keywordsMissingValue, "TARGETS")) {
+             cm::contains(keywordsMissingValue, "TARGETS")) {
     for (std::string const& currentTarget : arguments.Targets) {
       if (mf.IsAlias(currentTarget)) {
         std::ostringstream e;

+ 2 - 2
Source/cmFileCommand.cxx

@@ -2980,7 +2980,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
   };
 
   if (!parsedArgs.Format.empty() &&
-      !cmContains(knownFormats, parsedArgs.Format)) {
+      !cm::contains(knownFormats, parsedArgs.Format)) {
     status.SetError(
       cmStrCat("archive format ", parsedArgs.Format, " not supported"));
     cmSystemTools::SetFatalErrorOccured();
@@ -2989,7 +2989,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
 
   const char* zipFileFormats[] = { "7zip", "zip" };
   if (!parsedArgs.Type.empty() &&
-      cmContains(zipFileFormats, parsedArgs.Format)) {
+      cm::contains(zipFileFormats, parsedArgs.Format)) {
     status.SetError(cmStrCat("archive format ", parsedArgs.Format,
                              " does not support TYPE arguments"));
     cmSystemTools::SetFatalErrorOccured();

+ 5 - 4
Source/cmGeneratorExpressionNode.cxx

@@ -15,6 +15,7 @@
 
 #include <cm/iterator>
 #include <cm/string_view>
+#include <cmext/algorithm>
 
 #include "cmsys/RegularExpression.hxx"
 #include "cmsys/String.h"
@@ -313,7 +314,7 @@ static const struct InListNode : public cmGeneratorExpressionNode
         break;
     }
 
-    return cmContains(values, parameters.front()) ? "1" : "0";
+    return cm::contains(values, parameters.front()) ? "1" : "0";
   }
 } inListNode;
 
@@ -921,8 +922,8 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
         if (const char* mapValue =
               context->CurrentTarget->GetProperty(mapProp)) {
           cmExpandList(cmSystemTools::UpperCase(mapValue), mappedConfigs);
-          return cmContains(mappedConfigs,
-                            cmSystemTools::UpperCase(parameters.front()))
+          return cm::contains(mappedConfigs,
+                              cmSystemTools::UpperCase(parameters.front()))
             ? "1"
             : "0";
         }
@@ -1659,7 +1660,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 (!cmContains(langAvailable, it)) {
+        if (!cm::contains(langAvailable, it)) {
           return "0";
         }
         if (standardDefault && !*standardDefault) {

+ 18 - 16
Source/cmGeneratorTarget.cxx

@@ -1309,7 +1309,8 @@ std::string AddSwiftInterfaceIncludeDirectories(
         target->GetLinkInterfaceLibraries(config, root, true)) {
     for (const cmLinkItem& library : interface->Libraries) {
       if (const cmGeneratorTarget* dependency = library.Target) {
-        if (cmContains(dependency->GetAllConfigCompileLanguages(), "Swift")) {
+        if (cm::contains(dependency->GetAllConfigCompileLanguages(),
+                         "Swift")) {
           std::string value =
             dependency->GetSafeProperty("Swift_MODULE_DIRECTORY");
           if (value.empty()) {
@@ -1339,7 +1340,8 @@ void AddSwiftImplicitIncludeDirectories(
 
     for (const cmLinkImplItem& library : libraries->Libraries) {
       if (const cmGeneratorTarget* dependency = library.Target) {
-        if (cmContains(dependency->GetAllConfigCompileLanguages(), "Swift")) {
+        if (cm::contains(dependency->GetAllConfigCompileLanguages(),
+                         "Swift")) {
           EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
 
           if (const char* val =
@@ -1522,7 +1524,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
   }
 
   bool debugSources =
-    !this->DebugSourcesDone && cmContains(debugProperties, "SOURCES");
+    !this->DebugSourcesDone && cm::contains(debugProperties, "SOURCES");
 
   if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
     this->DebugSourcesDone = true;
@@ -2806,7 +2808,7 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
       for (cmSourceFile* sf : sources) {
         const std::set<cmGeneratorTarget const*> tgts =
           this->GlobalGenerator->GetFilenameTargetDepends(sf);
-        if (cmContains(tgts, this->GeneratorTarget)) {
+        if (cm::contains(tgts, this->GeneratorTarget)) {
           std::ostringstream e;
           e << "Evaluation output file\n  \"" << sf->ResolveFullPath()
             << "\"\ndepends on the sources of a target it is used in.  This "
@@ -3339,7 +3341,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
   }
 
   bool debugIncludes = !this->DebugIncludesDone &&
-    cmContains(debugProperties, "INCLUDE_DIRECTORIES");
+    cm::contains(debugProperties, "INCLUDE_DIRECTORIES");
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugIncludesDone = true;
@@ -3454,7 +3456,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
   }
 
   bool debugOptions = !this->DebugCompileOptionsDone &&
-    cmContains(debugProperties, "COMPILE_OPTIONS");
+    cm::contains(debugProperties, "COMPILE_OPTIONS");
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugCompileOptionsDone = true;
@@ -3500,7 +3502,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
   }
 
   bool debugFeatures = !this->DebugCompileFeaturesDone &&
-    cmContains(debugProperties, "COMPILE_FEATURES");
+    cm::contains(debugProperties, "COMPILE_FEATURES");
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugCompileFeaturesDone = true;
@@ -3548,7 +3550,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
   }
 
   bool debugDefines = !this->DebugCompileDefinitionsDone &&
-    cmContains(debugProperties, "COMPILE_DEFINITIONS");
+    cm::contains(debugProperties, "COMPILE_DEFINITIONS");
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugCompileDefinitionsDone = true;
@@ -3979,8 +3981,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
     cmExpandList(debugProp, debugProperties);
   }
 
-  bool debugOptions =
-    !this->DebugLinkOptionsDone && cmContains(debugProperties, "LINK_OPTIONS");
+  bool debugOptions = !this->DebugLinkOptionsDone &&
+    cm::contains(debugProperties, "LINK_OPTIONS");
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugLinkOptionsDone = true;
@@ -4236,7 +4238,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
   }
 
   bool debugDirectories = !this->DebugLinkDirectoriesDone &&
-    cmContains(debugProperties, "LINK_DIRECTORIES");
+    cm::contains(debugProperties, "LINK_DIRECTORIES");
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugLinkDirectoriesDone = true;
@@ -5397,7 +5399,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
   PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
 
   std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
-  const bool explicitlySet = cmContains(headPropKeys, p);
+  const bool explicitlySet = cm::contains(headPropKeys, p);
 
   const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
   assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
@@ -5437,7 +5439,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
 
     std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
 
-    const bool ifaceIsSet = cmContains(propKeys, interfaceProperty);
+    const bool ifaceIsSet = cm::contains(propKeys, interfaceProperty);
     PropertyType ifacePropContent = getTypedProperty<PropertyType>(
       theTarget, interfaceProperty, genexInterpreter.get());
 
@@ -5728,8 +5730,8 @@ void cmGeneratorTarget::ReportPropertyOrigin(
     cmExpandList(debugProp, debugProperties);
   }
 
-  bool debugOrigin =
-    !this->DebugCompatiblePropertiesDone[p] && cmContains(debugProperties, p);
+  bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
+    cm::contains(debugProperties, p);
 
   if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
     this->DebugCompatiblePropertiesDone[p] = true;
@@ -6895,7 +6897,7 @@ cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
 bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
   const std::string& p) const
 {
-  return cmContains(this->LinkImplicitNullProperties, p);
+  return cm::contains(this->LinkImplicitNullProperties, p);
 }
 
 void cmGeneratorTarget::ComputeLinkImplementationLibraries(

+ 6 - 5
Source/cmGlobalGenerator.cxx

@@ -14,6 +14,7 @@
 #include <utility>
 
 #include <cm/memory>
+#include <cmext/algorithm>
 
 #include "cmsys/Directory.hxx"
 #include "cmsys/FStream.hxx"
@@ -403,7 +404,7 @@ bool cmGlobalGenerator::IsExportedTargetsFile(
   if (it == this->BuildExportSets.end()) {
     return false;
   }
-  return !cmContains(this->BuildExportExportSets, filename);
+  return !cm::contains(this->BuildExportExportSets, filename);
 }
 
 // Find the make program for the generator, required for try compiles
@@ -529,7 +530,7 @@ void cmGlobalGenerator::EnableLanguage(
       if (lang == "NONE") {
         this->SetLanguageEnabled("NONE", mf);
       } else {
-        if (!cmContains(this->LanguagesReady, lang)) {
+        if (!cm::contains(this->LanguagesReady, lang)) {
           std::ostringstream e;
           e << "The test project needs language " << lang
             << " which is not enabled.";
@@ -1094,7 +1095,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
 {
   // use LanguageToLinkerPreference to detect whether this functions has
   // run before
-  if (cmContains(this->LanguageToLinkerPreference, l)) {
+  if (cm::contains(this->LanguageToLinkerPreference, l)) {
     return;
   }
 
@@ -2227,7 +2228,7 @@ void cmGlobalGenerator::AddAlias(const std::string& name,
 
 bool cmGlobalGenerator::IsAlias(const std::string& name) const
 {
-  return cmContains(this->AliasTargets, name);
+  return cm::contains(this->AliasTargets, name);
 }
 
 void cmGlobalGenerator::IndexTarget(cmTarget* t)
@@ -2792,7 +2793,7 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
                                     "clean",     "edit_cache", "rebuild_cache",
                                     "ZERO_CHECK" };
 
-  return cmContains(reservedTargets, name);
+  return cm::contains(reservedTargets, name);
 }
 
 void cmGlobalGenerator::SetExternalMakefileProjectGenerator(

+ 3 - 3
Source/cmGlobalGhsMultiGenerator.cxx

@@ -10,8 +10,8 @@
 
 #include <cm/memory>
 #include <cm/string>
+#include <cmext/algorithm>
 
-#include "cmAlgorithms.h"
 #include "cmDocumentationEntry.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorTarget.h"
@@ -585,14 +585,14 @@ cmGlobalGhsMultiGenerator::GenerateBuildCommand(
     /* if multiple top-projects are found in build directory
      * then prefer projectName top-project.
      */
-    if (!cmContains(files, proj)) {
+    if (!cm::contains(files, proj)) {
       proj = files.at(0);
     }
   }
 
   makeCommand.Add("-top", proj);
   if (!targetNames.empty()) {
-    if (cmContains(targetNames, "clean")) {
+    if (cm::contains(targetNames, "clean")) {
       makeCommand.Add("-clean");
     } else {
       for (const auto& tname : targetNames) {

+ 2 - 3
Source/cmGlobalNinjaGenerator.cxx

@@ -18,7 +18,6 @@
 #include "cm_jsoncpp_value.h"
 #include "cm_jsoncpp_writer.h"
 
-#include "cmAlgorithms.h"
 #include "cmDocumentationEntry.h"
 #include "cmFortranParser.h"
 #include "cmGeneratedFileStream.h"
@@ -685,10 +684,10 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures()
 bool cmGlobalNinjaGenerator::CheckLanguages(
   std::vector<std::string> const& languages, cmMakefile* mf) const
 {
-  if (cmContains(languages, "Fortran")) {
+  if (cm::contains(languages, "Fortran")) {
     return this->CheckFortran(mf);
   }
-  if (cmContains(languages, "Swift")) {
+  if (cm::contains(languages, "Swift")) {
     const std::string architectures =
       mf->GetSafeDefinition("CMAKE_OSX_ARCHITECTURES");
     if (architectures.find_first_of(';') != std::string::npos) {

+ 4 - 5
Source/cmGlobalXCodeGenerator.cxx

@@ -15,7 +15,6 @@
 
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandGenerator.h"
@@ -363,7 +362,7 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
     std::string projectArg = cmStrCat(projectName, ".xcodeproj");
     makeCommand.Add(projectArg);
   }
-  if (cmContains(targetNames, "clean")) {
+  if (cm::contains(targetNames, "clean")) {
     makeCommand.Add("clean");
     makeCommand.Add("-target", "ALL_BUILD");
   } else {
@@ -911,7 +910,7 @@ void cmGlobalXCodeGenerator::AddXCodeProjBuildRule(
              "/CMakeLists.txt");
   cmSourceFile* srcCMakeLists = target->Makefile->GetOrCreateSource(
     listfile, false, cmSourceFileLocationKind::Known);
-  if (!cmContains(sources, srcCMakeLists)) {
+  if (!cm::contains(sources, srcCMakeLists)) {
     sources.push_back(srcCMakeLists);
   }
 }
@@ -1427,8 +1426,8 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
 
 bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
 {
-  return cmContains(this->CMakeInstance->GetHeaderExtensions(),
-                    sf->GetExtension());
+  return cm::contains(this->CMakeInstance->GetHeaderExtensions(),
+                      sf->GetExtension());
 }
 
 cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase(

+ 3 - 2
Source/cmLinkItem.h

@@ -10,7 +10,8 @@
 #include <string>
 #include <vector>
 
-#include "cmAlgorithms.h"
+#include <cmext/algorithm>
+
 #include "cmListFileCache.h"
 #include "cmSystemTools.h"
 #include "cmTargetLinkLibraryType.h"
@@ -127,7 +128,7 @@ inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
 
   // Check if any entry in the list matches this configuration.
   std::string configUpper = cmSystemTools::UpperCase(config);
-  if (cmContains(debugConfigs, configUpper)) {
+  if (cm::contains(debugConfigs, configUpper)) {
     return DEBUG_LibraryType;
   }
   // The current configuration is not a debug configuration.

+ 3 - 2
Source/cmLinkLineDeviceComputer.cxx

@@ -6,7 +6,8 @@
 #include <set>
 #include <utility>
 
-#include "cmAlgorithms.h"
+#include <cmext/algorithm>
+
 #include "cmComputeLinkInformation.h"
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
@@ -188,7 +189,7 @@ bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg,
   cmGeneratorTarget::LinkClosure const* closure =
     target.GetLinkClosure(config);
 
-  if (cmContains(closure->Languages, "CUDA")) {
+  if (cm::contains(closure->Languages, "CUDA")) {
     if (const char* separableCompilation =
           target.GetProperty("CUDA_SEPARABLE_COMPILATION")) {
       if (cmIsOn(separableCompilation)) {

+ 2 - 1
Source/cmListCommand.cxx

@@ -16,6 +16,7 @@
 #include <vector>
 
 #include <cm/memory>
+#include <cmext/algorithm>
 
 #include "cmsys/RegularExpression.hxx"
 
@@ -66,7 +67,7 @@ bool GetList(std::vector<std::string>& list, const std::string& var,
   // expand the variable into a list
   cmExpandList(listString, list, true);
   // if no empty elements then just return
-  if (!cmContains(list, std::string())) {
+  if (!cm::contains(list, std::string())) {
     return true;
   }
   // if we have empty elements we need to check policy CMP0007

+ 6 - 6
Source/cmLocalGenerator.cxx

@@ -20,7 +20,6 @@
 
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandGenerator.h"
@@ -1255,7 +1254,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") &&
-        !cmContains(impDirVec, "/usr/include") &&
+        !cm::contains(impDirVec, "/usr/include") &&
         std::find_if(impDirVec.begin(), impDirVec.end(),
                      [](std::string const& d) {
                        return cmHasLiteralSuffix(d, "/usr/include");
@@ -1276,13 +1275,14 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
                       &lang](std::string const& dir) {
     return (
       // Do not exclude directories that are not in an excluded set.
-      ((!cmContains(implicitSet, this->GlobalGenerator->GetRealPath(dir))) &&
-       (!cmContains(implicitExclude, dir)))
+      ((!cm::contains(implicitSet, this->GlobalGenerator->GetRealPath(dir))) &&
+       (!cm::contains(implicitExclude, dir)))
       // Do not exclude entries of the CPATH environment variable even though
       // they are implicitly searched by the compiler.  They are meant to be
       // user-specified directories that can be re-ordered or converted to
       // -isystem without breaking real compiler builtin headers.
-      || ((lang == "C" || lang == "CXX") && cmContains(this->EnvCPATH, dir)));
+      ||
+      ((lang == "C" || lang == "CXX") && cm::contains(this->EnvCPATH, dir)));
   };
 
   // Get the target-specific include directories.
@@ -1329,7 +1329,7 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
   if (!stripImplicitDirs) {
     // Append implicit directories that were requested by the user only
     for (BT<std::string> const& udr : userDirs) {
-      if (cmContains(implicitSet, cmSystemTools::GetRealPath(udr.Value))) {
+      if (cm::contains(implicitSet, cmSystemTools::GetRealPath(udr.Value))) {
         emitBT(udr);
       }
     }

+ 2 - 1
Source/cmLocalVisualStudio7Generator.cxx

@@ -3,6 +3,7 @@
 #include "cmLocalVisualStudio7Generator.h"
 
 #include <cm/memory>
+#include <cmext/algorithm>
 
 #include <windows.h>
 
@@ -1522,7 +1523,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
     // If HEADER_FILE_ONLY is set, we must suppress this generation in
     // the project file
     fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") ||
-      !cmContains(acs.Configs, ci) ||
+      !cm::contains(acs.Configs, ci) ||
       (gt->GetPropertyAsBool("UNITY_BUILD") &&
        sf.GetProperty("UNITY_SOURCE_FILE") &&
        !sf.GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION"));

+ 16 - 17
Source/cmMakefile.cxx

@@ -27,7 +27,6 @@
 #include "cm_static_string_view.hxx"
 #include "cm_sys_stat.h"
 
-#include "cmAlgorithms.h"
 #include "cmCommandArgumentParserHelper.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
@@ -1645,7 +1644,7 @@ void cmMakefile::Configure()
         allowedCommands.insert("message");
         isProblem = false;
         for (cmListFileFunction const& func : listFile.Functions) {
-          if (!cmContains(allowedCommands, func.Name.Lower)) {
+          if (!cm::contains(allowedCommands, func.Name.Lower)) {
             isProblem = true;
             break;
           }
@@ -4294,7 +4293,7 @@ cmTarget* cmMakefile::FindTargetToUse(const std::string& name,
 
 bool cmMakefile::IsAlias(const std::string& name) const
 {
-  if (cmContains(this->AliasTargets, name)) {
+  if (cm::contains(this->AliasTargets, name)) {
     return true;
   }
   return this->GetGlobalGenerator()->IsAlias(name);
@@ -4664,7 +4663,7 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
   }
 
   std::vector<std::string> availableFeatures = cmExpandedList(features);
-  if (!cmContains(availableFeatures, feature)) {
+  if (!cm::contains(availableFeatures, feature)) {
     std::ostringstream e;
     e << "The compiler feature \"" << feature << "\" is not known to " << lang
       << " compiler\n\""
@@ -4961,27 +4960,27 @@ void cmMakefile::CheckNeededCxxLanguage(const std::string& feature,
   if (const char* propCxx98 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "98_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCxx98);
-    needCxx98 = cmContains(props, feature);
+    needCxx98 = cm::contains(props, feature);
   }
   if (const char* propCxx11 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "11_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCxx11);
-    needCxx11 = cmContains(props, feature);
+    needCxx11 = cm::contains(props, feature);
   }
   if (const char* propCxx14 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "14_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCxx14);
-    needCxx14 = cmContains(props, feature);
+    needCxx14 = cm::contains(props, feature);
   }
   if (const char* propCxx17 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "17_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCxx17);
-    needCxx17 = cmContains(props, feature);
+    needCxx17 = cm::contains(props, feature);
   }
   if (const char* propCxx20 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "20_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCxx20);
-    needCxx20 = cmContains(props, feature);
+    needCxx20 = cm::contains(props, feature);
   }
 }
 
@@ -5120,27 +5119,27 @@ void cmMakefile::CheckNeededCudaLanguage(const std::string& feature,
   if (const char* propCuda03 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "03_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCuda03);
-    needCuda03 = cmContains(props, feature);
+    needCuda03 = cm::contains(props, feature);
   }
   if (const char* propCuda11 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "11_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCuda11);
-    needCuda11 = cmContains(props, feature);
+    needCuda11 = cm::contains(props, feature);
   }
   if (const char* propCuda14 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "14_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCuda14);
-    needCuda14 = cmContains(props, feature);
+    needCuda14 = cm::contains(props, feature);
   }
   if (const char* propCuda17 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "17_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCuda17);
-    needCuda17 = cmContains(props, feature);
+    needCuda17 = cm::contains(props, feature);
   }
   if (const char* propCuda20 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "20_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propCuda20);
-    needCuda20 = cmContains(props, feature);
+    needCuda20 = cm::contains(props, feature);
   }
 }
 
@@ -5214,17 +5213,17 @@ void cmMakefile::CheckNeededCLanguage(const std::string& feature,
   if (const char* propC90 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "90_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propC90);
-    needC90 = cmContains(props, feature);
+    needC90 = cm::contains(props, feature);
   }
   if (const char* propC99 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "99_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propC99);
-    needC99 = cmContains(props, feature);
+    needC99 = cm::contains(props, feature);
   }
   if (const char* propC11 =
         this->GetDefinition(cmStrCat("CMAKE_", lang, "11_COMPILE_FEATURES"))) {
     std::vector<std::string> props = cmExpandedList(propC11);
-    needC11 = cmContains(props, feature);
+    needC11 = cm::contains(props, feature);
   }
 }
 

+ 1 - 2
Source/cmQtAutoGen.cxx

@@ -13,7 +13,6 @@
 #include "cmsys/FStream.hxx"
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmAlgorithms.h"
 #include "cmDuration.h"
 #include "cmProcessOutput.h"
 #include "cmStringAlgorithms.h"
@@ -55,7 +54,7 @@ void MergeOptions(std::vector<std::string>& baseOpts,
           }
         }
         // Test if this is a value option and change the existing value
-        if (!optName.empty() && cmContains(valueOpts, optName)) {
+        if (!optName.empty() && cm::contains(valueOpts, optName)) {
           const auto existItNext(existIt + 1);
           const auto fitNext(fit + 1);
           if ((existItNext != baseOpts.end()) && (fitNext != fitEnd)) {

+ 4 - 4
Source/cmQtAutoGenInitializer.cxx

@@ -16,13 +16,13 @@
 #include <cm/algorithm>
 #include <cm/iterator>
 #include <cm/memory>
+#include <cmext/algorithm>
 
 #include "cmsys/SystemInformation.hxx"
 
 #include "cm_jsoncpp_value.h"
 #include "cm_jsoncpp_writer.h"
 
-#include "cmAlgorithms.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmGeneratedFileStream.h"
@@ -850,7 +850,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
               this->Makefile->GetSource(fullPath, locationKind);
             if (sf != nullptr) {
               // Check if we know about this header already
-              if (cmContains(this->AutogenTarget.Headers, sf)) {
+              if (cm::contains(this->AutogenTarget.Headers, sf)) {
                 continue;
               }
               // We only accept not-GENERATED files that do exist.
@@ -898,14 +898,14 @@ bool cmQtAutoGenInitializer::InitScanFiles()
         cmSystemTools::LowerCase(sf->GetExtension());
 
       if (cm->IsHeaderExtension(extLower)) {
-        if (!cmContains(this->AutogenTarget.Headers, sf.get())) {
+        if (!cm::contains(this->AutogenTarget.Headers, sf.get())) {
           auto muf = makeMUFile(sf.get(), fullPath, false);
           if (muf->SkipMoc || muf->SkipUic) {
             addMUHeader(std::move(muf), extLower);
           }
         }
       } else if (cm->IsSourceExtension(extLower)) {
-        if (!cmContains(this->AutogenTarget.Sources, sf.get())) {
+        if (!cm::contains(this->AutogenTarget.Sources, sf.get())) {
           auto muf = makeMUFile(sf.get(), fullPath, false);
           if (muf->SkipMoc || muf->SkipUic) {
             addMUSource(std::move(muf));

+ 2 - 2
Source/cmServerProtocol.cxx

@@ -10,10 +10,10 @@
 #include <vector>
 
 #include <cm/memory>
+#include <cmext/algorithm>
 
 #include "cm_uv.h"
 
-#include "cmAlgorithms.h"
 #include "cmExternalMakefileProjectGenerator.h"
 #include "cmFileMonitor.h"
 #include "cmGlobalGenerator.h"
@@ -433,7 +433,7 @@ cmServerResponse cmServerProtocol1::ProcessCache(
     keys = allKeys;
   } else {
     for (auto const& i : keys) {
-      if (!cmContains(allKeys, i)) {
+      if (!cm::contains(allKeys, i)) {
         return request.ReportError("Key \"" + i + "\" not found in cache.");
       }
     }

+ 3 - 2
Source/cmSourceGroupCommand.cxx

@@ -7,7 +7,8 @@
 #include <set>
 #include <utility>
 
-#include "cmAlgorithms.h"
+#include <cmext/algorithm>
+
 #include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmSourceGroup.h"
@@ -136,7 +137,7 @@ ExpectedOptions getExpectedOptions()
 bool isExpectedOption(const std::string& argument,
                       const ExpectedOptions& expectedOptions)
 {
-  return cmContains(expectedOptions, argument);
+  return cm::contains(expectedOptions, argument);
 }
 
 void parseArguments(const std::vector<std::string>& args,

+ 4 - 4
Source/cmVisualStudio10TargetGenerator.cxx

@@ -8,10 +8,10 @@
 #include <cm/memory>
 #include <cm/string_view>
 #include <cm/vector>
+#include <cmext/algorithm>
 
 #include "windows.h"
 
-#include "cmAlgorithms.h"
 #include "cmComputeLinkInformation.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandGenerator.h"
@@ -2718,7 +2718,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
   std::string langForClCompile;
   if (this->ProjectType == csproj) {
     langForClCompile = "CSharp";
-  } else if (cmContains(clLangs, linkLanguage)) {
+  } else if (cm::contains(clLangs, linkLanguage)) {
     langForClCompile = linkLanguage;
   } else {
     std::set<std::string> languages;
@@ -3651,7 +3651,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
   std::vector<std::string> libVec;
   std::vector<std::string> vsTargetVec;
   this->AddLibraries(cli, libVec, vsTargetVec, config);
-  if (cmContains(linkClosure->Languages, "CUDA") &&
+  if (cm::contains(linkClosure->Languages, "CUDA") &&
       this->CudaOptions[config] != nullptr) {
     this->CudaOptions[config]->FixCudaRuntime(this->GeneratorTarget);
   }
@@ -3925,7 +3925,7 @@ void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
 {
   for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) {
     if (cmSystemTools::ComparePath(targetsFile, i.File)) {
-      if (!cmContains(i.Configs, config)) {
+      if (!cm::contains(i.Configs, config)) {
         i.Configs.push_back(config);
       }
       return;

+ 6 - 3
Source/cmXCodeObject.h

@@ -12,7 +12,7 @@
 #include <utility>
 #include <vector>
 
-#include "cmAlgorithms.h"
+#include <cmext/algorithm>
 
 class cmGeneratorTarget;
 
@@ -82,10 +82,13 @@ public:
   void SetObject(cmXCodeObject* value) { this->Object = value; }
   cmXCodeObject* GetObject() { return this->Object; }
   void AddObject(cmXCodeObject* value) { this->List.push_back(value); }
-  bool HasObject(cmXCodeObject* o) const { return cmContains(this->List, o); }
+  bool HasObject(cmXCodeObject* o) const
+  {
+    return cm::contains(this->List, o);
+  }
   void AddUniqueObject(cmXCodeObject* value)
   {
-    if (!cmContains(this->List, value)) {
+    if (!cm::contains(this->List, value)) {
       this->List.push_back(value);
     }
   }

+ 3 - 1
Source/cmXCodeScheme.cxx

@@ -7,6 +7,8 @@
 #include <sstream>
 #include <utility>
 
+#include <cmext/algorithm>
+
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
@@ -427,7 +429,7 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name)
   // Try to find the desired configuration by name,
   // and if it's not found return first from the list
   //
-  if (!cmContains(this->ConfigList, name) && !this->ConfigList.empty()) {
+  if (!cm::contains(this->ConfigList, name) && !this->ConfigList.empty()) {
     return this->ConfigList[0];
   }
 

+ 1 - 2
Source/cmake.cxx

@@ -27,7 +27,6 @@
 #include "cm_static_string_view.hxx"
 #include "cm_sys_stat.h"
 
-#include "cmAlgorithms.h"
 #include "cmCommands.h"
 #include "cmDocumentation.h"
 #include "cmDocumentationEntry.h"
@@ -2863,7 +2862,7 @@ void cmake::WatchUnusedCli(const std::string& var)
 {
 #ifndef CMAKE_BOOTSTRAP
   this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
-  if (!cmContains(this->UsedCliVariables, var)) {
+  if (!cm::contains(this->UsedCliVariables, var)) {
     this->UsedCliVariables[var] = false;
   }
 #endif

+ 1 - 2
Source/cmcmd.cxx

@@ -8,7 +8,6 @@
 
 #include "cm_uv.h"
 
-#include "cmAlgorithms.h"
 #include "cmDuration.h"
 #include "cmGlobalGenerator.h"
 #include "cmLocalGenerator.h"
@@ -1220,7 +1219,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
             }
           } else if (cmHasLiteralPrefix(arg, "--format=")) {
             format = arg.substr(9);
-            if (!cmContains(knownFormats, format)) {
+            if (!cm::contains(knownFormats, format)) {
               cmSystemTools::Error("Unknown -E tar --format= argument: " +
                                    format);
               return 1;

+ 90 - 2
Utilities/std/cmext/algorithm

@@ -13,12 +13,11 @@
 
 #include <cm/type_traits>
 #include <cmext/iterator>
+#include <cmext/type_traits>
 
 #if defined(__SUNPRO_CC) && defined(__sparc)
 #  include <list>
 #  include <vector>
-#else
-#  include <cmext/type_traits>
 #endif
 
 namespace cm {
@@ -158,6 +157,95 @@ void append(T& v, U const& r)
 #  endif
 #endif
 
+#if defined(__SUNPRO_CC)
+template <typename Iterator, typename Key>
+auto contains(Iterator first, Iterator last, Key const& key,
+              detail::overload_selector<1>) -> decltype(first->first == key)
+#else
+template <typename Iterator, typename Key,
+          cm::enable_if_t<
+            cm::is_input_iterator<Iterator>::value &&
+              std::is_convertible<Key,
+                                  typename std::iterator_traits<
+                                    Iterator>::value_type::first_type>::value,
+            int> = 0>
+bool contains(Iterator first, Iterator last, Key const& key)
+#endif
+{
+  return std::find_if(
+           first, last,
+           [&key](
+             typename std::iterator_traits<Iterator>::value_type const& item) {
+             return item.first == key;
+           }) != last;
+}
+
+#if defined(__SUNPRO_CC)
+template <typename Iterator, typename Key>
+bool contains(Iterator first, Iterator last, Key const& key,
+              detail::overload_selector<0>)
+#else
+template <
+  typename Iterator, typename Key,
+  cm::enable_if_t<
+    cm::is_input_iterator<Iterator>::value &&
+      std::is_convertible<
+        Key, typename std::iterator_traits<Iterator>::value_type>::value,
+    int> = 0>
+bool contains(Iterator first, Iterator last, Key const& key)
+#endif
+{
+  return std::find(first, last, key) != last;
+}
+
+#if defined(__SUNPRO_CC)
+template <typename Iterator, typename Key>
+bool contains(Iterator first, Iterator last, Key const& key)
+{
+  return contains(first, last, key, detail::overload_selector<1>{});
+}
+#endif
+
+#if defined(__SUNPRO_CC)
+template <typename Range, typename Key>
+auto contains(Range const& range, Key const& key, detail::overload_selector<1>)
+  -> decltype(range.find(key) != range.end())
+#else
+template <
+  typename Range, typename Key,
+  cm::enable_if_t<cm::is_associative_container<Range>::value ||
+                    cm::is_unordered_associative_container<Range>::value,
+                  int> = 0>
+bool contains(Range const& range, Key const& key)
+#endif
+{
+  return range.find(key) != range.end();
+}
+
+#if defined(__SUNPRO_CC)
+template <typename Range, typename Key>
+bool contains(Range const& range, Key const& key, detail::overload_selector<0>)
+#else
+template <
+  typename Range, typename Key,
+  cm::enable_if_t<cm::is_input_range<Range>::value &&
+                    !(cm::is_associative_container<Range>::value ||
+                      cm::is_unordered_associative_container<Range>::value),
+                  int> = 0>
+bool contains(Range const& range, Key const& key)
+#endif
+{
+  return std::find(std::begin(range), std::end(range), key) != std::end(range);
+}
+
+#if defined(__SUNPRO_CC)
+template <typename Range, typename Key>
+bool contains(Range const& range, Key const& key)
+{
+  return contains(range, key, detail::overload_selector<1>{});
+}
+#endif
+
 } // namespace cm
 
 #endif

+ 11 - 9
Utilities/std/cmext/iterator

@@ -23,25 +23,27 @@ using is_input_iterator =
   std::is_base_of<std::input_iterator_tag,
                   typename std::iterator_traits<I>::iterator_category>;
 
-// checks if a type is a range type: must have a difference_type type
+// checks if a type is a range type: std::begin() and std::end() are supported
 template <typename Range>
 using is_range = cm::bool_constant<
-  cm::is_iterator<decltype(std::declval<const Range>().begin())>::value &&
-  cm::is_iterator<decltype(std::declval<const Range>().end())>::value>;
+  cm::is_iterator<decltype(std::begin(std::declval<const Range>()))>::value &&
+  cm::is_iterator<decltype(std::end(std::declval<const Range>()))>::value>;
 
-// checks if a type is an input range type: must have methods begin() and end()
+// checks if a type is an input range type: std::begin() and std::end() are
 // returning an input iterator
 template <typename Range>
 using is_input_range =
 #if defined(_MSC_VER) && _MSC_VER < 1920
   // MS C++ is not able to evaluate complex type introspection,
   // so use a simplified version
-  cm::is_input_iterator<typename Range::const_iterator>;
+  cm::bool_constant<std::is_class<Range>::value ||
+                    std::is_pointer<Range>::value ||
+                    std::is_array<Range>::value>;
 #else
-  cm::bool_constant<
-    cm::is_input_iterator<decltype(
-      std::declval<const Range>().begin())>::value &&
-    cm::is_input_iterator<decltype(std::declval<const Range>().end())>::value>;
+  cm::bool_constant<cm::is_input_iterator<decltype(
+                      std::begin(std::declval<const Range>()))>::value &&
+                    cm::is_input_iterator<decltype(
+                      std::end(std::declval<const Range>()))>::value>;
 #endif
 
 } // namespace cm

+ 2 - 0
Utilities/std/cmext/type_traits

@@ -6,6 +6,8 @@
 #ifndef cmext_type_traits
 #define cmext_type_traits
 
+#include <memory>
+
 #include <cm/type_traits>
 
 namespace cm {