Bläddra i källkod

Use cmAppend to append ranges to std::vector instances

Sebastian Holtermann 6 år sedan
förälder
incheckning
006229278b
59 ändrade filer med 181 tillägg och 246 borttagningar
  1. 2 1
      Source/CTest/cmCTestBZR.cxx
  2. 1 2
      Source/CTest/cmCTestBuildHandler.cxx
  3. 6 10
      Source/CTest/cmCTestCoverageHandler.cxx
  4. 3 6
      Source/CTest/cmCTestCurl.cxx
  5. 2 1
      Source/CTest/cmCTestHG.cxx
  6. 7 9
      Source/CTest/cmCTestMultiProcessHandler.cxx
  7. 2 3
      Source/CTest/cmCTestP4.cxx
  8. 3 4
      Source/CTest/cmCTestSVN.cxx
  9. 7 14
      Source/CTest/cmCTestSubmitHandler.cxx
  10. 2 1
      Source/CTest/cmProcess.cxx
  11. 2 1
      Source/cmAddLibraryCommand.cxx
  12. 1 2
      Source/cmAddTestCommand.cxx
  13. 4 5
      Source/cmCTest.cxx
  14. 2 5
      Source/cmConditionEvaluator.cxx
  15. 4 5
      Source/cmCustomCommand.cxx
  16. 5 7
      Source/cmCustomCommandGenerator.cxx
  17. 2 1
      Source/cmDocumentationSection.h
  18. 2 1
      Source/cmELF.cxx
  19. 1 1
      Source/cmExecuteProcessCommand.cxx
  20. 2 1
      Source/cmExportBuildFileGenerator.h
  21. 10 15
      Source/cmExtraCodeBlocksGenerator.cxx
  22. 2 2
      Source/cmFileAPICodemodel.cxx
  23. 7 8
      Source/cmFileCommand.cxx
  24. 1 2
      Source/cmFindBase.cxx
  25. 2 1
      Source/cmFindCommon.cxx
  26. 1 1
      Source/cmFunctionCommand.cxx
  27. 3 2
      Source/cmGeneratorExpressionParser.cxx
  28. 1 1
      Source/cmGlobalGenerator.h
  29. 1 2
      Source/cmGlobalJOMMakefileGenerator.cxx
  30. 1 2
      Source/cmGlobalNMakeMakefileGenerator.cxx
  31. 2 3
      Source/cmGlobalNinjaGenerator.cxx
  32. 1 4
      Source/cmGlobalUnixMakefileGenerator3.cxx
  33. 2 4
      Source/cmGlobalVisualStudio8Generator.cxx
  34. 1 2
      Source/cmGlobalXCodeGenerator.cxx
  35. 3 3
      Source/cmIDEOptions.cxx
  36. 3 4
      Source/cmIncludeDirectoryCommand.cxx
  37. 2 2
      Source/cmInstallFilesCommand.cxx
  38. 2 1
      Source/cmInstallProgramsCommand.cxx
  39. 2 2
      Source/cmJsonObjects.cxx
  40. 6 7
      Source/cmLocalGenerator.cxx
  41. 2 2
      Source/cmLocalUnixMakefileGenerator3.cxx
  42. 1 1
      Source/cmMacroCommand.cxx
  43. 1 2
      Source/cmMakefile.cxx
  44. 3 3
      Source/cmMakefileExecutableTargetGenerator.cxx
  45. 4 4
      Source/cmMakefileLibraryTargetGenerator.cxx
  46. 10 22
      Source/cmMakefileTargetGenerator.cxx
  47. 1 2
      Source/cmNinjaTargetGenerator.cxx
  48. 2 4
      Source/cmOrderDirectories.cxx
  49. 2 3
      Source/cmQtAutoGen.cxx
  50. 6 9
      Source/cmQtAutoMocUic.cxx
  51. 1 1
      Source/cmQtAutoRcc.cxx
  52. 2 1
      Source/cmSetTargetPropertiesCommand.cxx
  53. 2 1
      Source/cmSetTestsPropertiesCommand.cxx
  54. 1 3
      Source/cmStateDirectory.cxx
  55. 7 7
      Source/cmSystemTools.cxx
  56. 16 22
      Source/cmTarget.cxx
  57. 1 4
      Source/cmake.cxx
  58. 1 1
      Source/cmakemain.cxx
  59. 5 6
      Source/cmcmd.cxx

+ 2 - 1
Source/CTest/cmCTestBZR.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestBZR.h"
 #include "cmCTestBZR.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestVC.h"
 #include "cmCTestVC.h"
 #include "cmProcessTools.h"
 #include "cmProcessTools.h"
@@ -242,7 +243,7 @@ private:
 
 
   void CharacterDataHandler(const char* data, int length) override
   void CharacterDataHandler(const char* data, int length) override
   {
   {
-    this->CData.insert(this->CData.end(), data, data + length);
+    cmAppend(this->CData, data, data + length);
   }
   }
 
 
   void EndElement(const std::string& name) override
   void EndElement(const std::string& name) override

+ 1 - 2
Source/CTest/cmCTestBuildHandler.cxx

@@ -978,8 +978,7 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
     if (it != queue->end()) {
     if (it != queue->end()) {
       // Create a contiguous array for the line
       // Create a contiguous array for the line
       this->CurrentProcessingLine.clear();
       this->CurrentProcessingLine.clear();
-      this->CurrentProcessingLine.insert(this->CurrentProcessingLine.end(),
-                                         queue->begin(), it);
+      cmAppend(this->CurrentProcessingLine, queue->begin(), it);
       this->CurrentProcessingLine.push_back(0);
       this->CurrentProcessingLine.push_back(0);
       const char* line = this->CurrentProcessingLine.data();
       const char* line = this->CurrentProcessingLine.data();
 
 

+ 6 - 10
Source/CTest/cmCTestCoverageHandler.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestCoverageHandler.h"
 #include "cmCTestCoverageHandler.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmDuration.h"
 #include "cmDuration.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratedFileStream.h"
@@ -813,15 +814,11 @@ int cmCTestCoverageHandler::HandleJacocoCoverage(
 
 
   // ...and in the binary directory.
   // ...and in the binary directory.
   cmsys::Glob g2;
   cmsys::Glob g2;
-  std::vector<std::string> binFiles;
   g2.SetRecurse(true);
   g2.SetRecurse(true);
   std::string binaryDir = this->CTest->GetCTestConfiguration("BuildDirectory");
   std::string binaryDir = this->CTest->GetCTestConfiguration("BuildDirectory");
   std::string binCoverageFile = binaryDir + "/*jacoco.xml";
   std::string binCoverageFile = binaryDir + "/*jacoco.xml";
   g2.FindFiles(binCoverageFile);
   g2.FindFiles(binCoverageFile);
-  binFiles = g2.GetFiles();
-  if (!binFiles.empty()) {
-    files.insert(files.end(), binFiles.begin(), binFiles.end());
-  }
+  cmAppend(files, g2.GetFiles());
 
 
   if (!files.empty()) {
   if (!files.empty()) {
     cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
     cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -1465,8 +1462,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
         "   looking for LCOV files in: " << daGlob << std::endl, this->Quiet);
         "   looking for LCOV files in: " << daGlob << std::endl, this->Quiet);
       gl.FindFiles(daGlob);
       gl.FindFiles(daGlob);
       // Keep a list of all LCOV files
       // Keep a list of all LCOV files
-      lcovFiles.insert(lcovFiles.end(), gl.GetFiles().begin(),
-                       gl.GetFiles().end());
+      cmAppend(lcovFiles, gl.GetFiles());
 
 
       for (std::string const& file : lcovFiles) {
       for (std::string const& file : lcovFiles) {
         lcovFile = file;
         lcovFile = file;
@@ -1604,11 +1600,11 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector<std::string>& files)
     std::string daGlob = lm.first;
     std::string daGlob = lm.first;
     daGlob += "/*.da";
     daGlob += "/*.da";
     gl.FindFiles(daGlob);
     gl.FindFiles(daGlob);
-    files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+    cmAppend(files, gl.GetFiles());
     daGlob = lm.first;
     daGlob = lm.first;
     daGlob += "/*.gcda";
     daGlob += "/*.gcda";
     gl.FindFiles(daGlob);
     gl.FindFiles(daGlob);
-    files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+    cmAppend(files, gl.GetFiles());
   }
   }
 }
 }
 
 
@@ -1645,7 +1641,7 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
                "Error while finding files matching " << daGlob << std::endl);
                "Error while finding files matching " << daGlob << std::endl);
     return false;
     return false;
   }
   }
-  files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+  cmAppend(files, gl.GetFiles());
   cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
   cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
                      "Now searching in: " << daGlob << std::endl, this->Quiet);
                      "Now searching in: " << daGlob << std::endl, this->Quiet);
   return true;
   return true;

+ 3 - 6
Source/CTest/cmCTestCurl.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestCurl.h"
 #include "cmCTestCurl.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCurl.h"
 #include "cmCurl.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
@@ -43,19 +44,15 @@ size_t curlWriteMemoryCallback(void* ptr, size_t size, size_t nmemb,
                                void* data)
                                void* data)
 {
 {
   int realsize = static_cast<int>(size * nmemb);
   int realsize = static_cast<int>(size * nmemb);
-
-  std::vector<char>* vec = static_cast<std::vector<char>*>(data);
   const char* chPtr = static_cast<char*>(ptr);
   const char* chPtr = static_cast<char*>(ptr);
-  vec->insert(vec->end(), chPtr, chPtr + realsize);
+  cmAppend(*static_cast<std::vector<char>*>(data), chPtr, chPtr + realsize);
   return realsize;
   return realsize;
 }
 }
 
 
 size_t curlDebugCallback(CURL* /*unused*/, curl_infotype /*unused*/,
 size_t curlDebugCallback(CURL* /*unused*/, curl_infotype /*unused*/,
                          char* chPtr, size_t size, void* data)
                          char* chPtr, size_t size, void* data)
 {
 {
-  std::vector<char>* vec = static_cast<std::vector<char>*>(data);
-  vec->insert(vec->end(), chPtr, chPtr + size);
-
+  cmAppend(*static_cast<std::vector<char>*>(data), chPtr, chPtr + size);
   return size;
   return size;
 }
 }
 }
 }

+ 2 - 1
Source/CTest/cmCTestHG.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestHG.h"
 #include "cmCTestHG.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestVC.h"
 #include "cmCTestVC.h"
 #include "cmProcessTools.h"
 #include "cmProcessTools.h"
@@ -202,7 +203,7 @@ private:
 
 
   void CharacterDataHandler(const char* data, int length) override
   void CharacterDataHandler(const char* data, int length) override
   {
   {
-    this->CData.insert(this->CData.end(), data, data + length);
+    cmAppend(this->CData, data, data + length);
   }
   }
 
 
   void EndElement(const std::string& name) override
   void EndElement(const std::string& name) override

+ 7 - 9
Source/CTest/cmCTestMultiProcessHandler.cxx

@@ -3,6 +3,7 @@
 #include "cmCTestMultiProcessHandler.h"
 #include "cmCTestMultiProcessHandler.h"
 
 
 #include "cmAffinity.h"
 #include "cmAffinity.h"
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestRunTest.h"
 #include "cmCTestRunTest.h"
 #include "cmCTestTestHandler.h"
 #include "cmCTestTestHandler.h"
@@ -653,13 +654,10 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
   // Reverse iterate over the different dependency levels (deepest first).
   // Reverse iterate over the different dependency levels (deepest first).
   // Sort tests within each level by COST and append them to the cost list.
   // Sort tests within each level by COST and append them to the cost list.
   for (TestSet const& currentSet : cmReverseRange(priorityStack)) {
   for (TestSet const& currentSet : cmReverseRange(priorityStack)) {
-    TestComparator comp(this);
-
     TestList sortedCopy;
     TestList sortedCopy;
-
-    sortedCopy.insert(sortedCopy.end(), currentSet.begin(), currentSet.end());
-
-    std::stable_sort(sortedCopy.begin(), sortedCopy.end(), comp);
+    cmAppend(sortedCopy, currentSet);
+    std::stable_sort(sortedCopy.begin(), sortedCopy.end(),
+                     TestComparator(this));
 
 
     for (auto const& j : sortedCopy) {
     for (auto const& j : sortedCopy) {
       if (alreadySortedTests.find(j) == alreadySortedTests.end()) {
       if (alreadySortedTests.find(j) == alreadySortedTests.end()) {
@@ -688,8 +686,8 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
     presortedList.push_back(i.first);
     presortedList.push_back(i.first);
   }
   }
 
 
-  TestComparator comp(this);
-  std::stable_sort(presortedList.begin(), presortedList.end(), comp);
+  std::stable_sort(presortedList.begin(), presortedList.end(),
+                   TestComparator(this));
 
 
   TestSet alreadySortedTests;
   TestSet alreadySortedTests;
 
 
@@ -992,7 +990,7 @@ static Json::Value DumpCTestInfo(
     const std::vector<std::string>& args = testRun.GetArguments();
     const std::vector<std::string>& args = testRun.GetArguments();
     if (!args.empty()) {
     if (!args.empty()) {
       commandAndArgs.reserve(args.size() + 1);
       commandAndArgs.reserve(args.size() + 1);
-      commandAndArgs.insert(commandAndArgs.end(), args.begin(), args.end());
+      cmAppend(commandAndArgs, args);
     }
     }
     testInfo["command"] = DumpToJsonArray(commandAndArgs);
     testInfo["command"] = DumpToJsonArray(commandAndArgs);
   }
   }

+ 2 - 3
Source/CTest/cmCTestP4.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestP4.h"
 #include "cmCTestP4.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestVC.h"
 #include "cmCTestVC.h"
 #include "cmProcessTools.h"
 #include "cmProcessTools.h"
@@ -324,9 +325,7 @@ void cmCTestP4::SetP4Options(std::vector<char const*>& CommandOptions)
     // The CTEST_P4_OPTIONS variable adds additional Perforce command line
     // The CTEST_P4_OPTIONS variable adds additional Perforce command line
     // options before the main command
     // options before the main command
     std::string opts = this->CTest->GetCTestConfiguration("P4Options");
     std::string opts = this->CTest->GetCTestConfiguration("P4Options");
-    std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
-
-    P4Options.insert(P4Options.end(), args.begin(), args.end());
+    cmAppend(P4Options, cmSystemTools::ParseArguments(opts));
   }
   }
 
 
   CommandOptions.clear();
   CommandOptions.clear();

+ 3 - 4
Source/CTest/cmCTestSVN.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCTestSVN.h"
 #include "cmCTestSVN.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestVC.h"
 #include "cmCTestVC.h"
 #include "cmProcessTools.h"
 #include "cmProcessTools.h"
@@ -269,9 +270,7 @@ bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters,
 
 
   std::vector<char const*> args;
   std::vector<char const*> args;
   args.push_back(this->CommandLineTool.c_str());
   args.push_back(this->CommandLineTool.c_str());
-
-  args.insert(args.end(), parameters.begin(), parameters.end());
-
+  cmAppend(args, parameters);
   args.push_back("--non-interactive");
   args.push_back("--non-interactive");
 
 
   std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions");
   std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions");
@@ -344,7 +343,7 @@ private:
 
 
   void CharacterDataHandler(const char* data, int length) override
   void CharacterDataHandler(const char* data, int length) override
   {
   {
-    this->CData.insert(this->CData.end(), data, data + length);
+    cmAppend(this->CData, data, data + length);
   }
   }
 
 
   void EndElement(const std::string& name) override
   void EndElement(const std::string& name) override

+ 7 - 14
Source/CTest/cmCTestSubmitHandler.cxx

@@ -63,7 +63,7 @@ private:
 
 
   void CharacterDataHandler(const char* data, int length) override
   void CharacterDataHandler(const char* data, int length) override
   {
   {
-    this->CurrentValue.insert(this->CurrentValue.end(), data, data + length);
+    cmAppend(this->CurrentValue, data, data + length);
   }
   }
 
 
   void EndElement(const std::string& name) override
   void EndElement(const std::string& name) override
@@ -93,12 +93,9 @@ static size_t cmCTestSubmitHandlerWriteMemoryCallback(void* ptr, size_t size,
                                                       size_t nmemb, void* data)
                                                       size_t nmemb, void* data)
 {
 {
   int realsize = static_cast<int>(size * nmemb);
   int realsize = static_cast<int>(size * nmemb);
-
-  cmCTestSubmitHandlerVectorOfChar* vec =
-    static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
   const char* chPtr = static_cast<char*>(ptr);
   const char* chPtr = static_cast<char*>(ptr);
-  vec->insert(vec->end(), chPtr, chPtr + realsize);
-
+  cmAppend(*static_cast<cmCTestSubmitHandlerVectorOfChar*>(data), chPtr,
+           chPtr + realsize);
   return realsize;
   return realsize;
 }
 }
 
 
@@ -107,10 +104,8 @@ static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/,
                                                     char* chPtr, size_t size,
                                                     char* chPtr, size_t size,
                                                     void* data)
                                                     void* data)
 {
 {
-  cmCTestSubmitHandlerVectorOfChar* vec =
-    static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
-  vec->insert(vec->end(), chPtr, chPtr + size);
-
+  cmAppend(*static_cast<cmCTestSubmitHandlerVectorOfChar*>(data), chPtr,
+           chPtr + size);
   return size;
   return size;
 }
 }
 
 
@@ -769,8 +764,7 @@ int cmCTestSubmitHandler::ProcessHandler()
 
 
   if (!this->Files.empty()) {
   if (!this->Files.empty()) {
     // Submit the explicitly selected files:
     // Submit the explicitly selected files:
-    //
-    files.insert(files.end(), this->Files.begin(), this->Files.end());
+    cmAppend(files, this->Files);
   }
   }
 
 
   // Add to the list of files to submit from any selected, existing parts:
   // Add to the list of files to submit from any selected, existing parts:
@@ -816,8 +810,7 @@ int cmCTestSubmitHandler::ProcessHandler()
     }
     }
 
 
     // Submit files from this part.
     // Submit files from this part.
-    std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
-    files.insert(files.end(), pfiles.begin(), pfiles.end());
+    cmAppend(files, this->CTest->GetSubmitFiles(p));
   }
   }
 
 
   // Make sure files are unique, but preserve order.
   // Make sure files are unique, but preserve order.

+ 2 - 1
Source/CTest/cmProcess.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmProcess.h"
 #include "cmProcess.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCTest.h"
 #include "cmCTest.h"
 #include "cmCTestRunTest.h"
 #include "cmCTestRunTest.h"
 #include "cmCTestTestHandler.h"
 #include "cmCTestTestHandler.h"
@@ -215,7 +216,7 @@ void cmProcess::OnRead(ssize_t nread, const uv_buf_t* buf)
   if (nread > 0) {
   if (nread > 0) {
     std::string strdata;
     std::string strdata;
     this->Conv.DecodeText(buf->base, static_cast<size_t>(nread), strdata);
     this->Conv.DecodeText(buf->base, static_cast<size_t>(nread), strdata);
-    this->Output.insert(this->Output.end(), strdata.begin(), strdata.end());
+    cmAppend(this->Output, strdata);
 
 
     while (this->Output.GetLine(line)) {
     while (this->Output.GetLine(line)) {
       this->Runner.CheckOutput(line);
       this->Runner.CheckOutput(line);

+ 2 - 1
Source/cmAddLibraryCommand.cxx

@@ -4,6 +4,7 @@
 
 
 #include <sstream>
 #include <sstream>
 
 
+#include "cmAlgorithms.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
 #include "cmGlobalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
@@ -338,7 +339,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
     return true;
     return true;
   }
   }
 
 
-  srclists.insert(srclists.end(), s, args.end());
+  cmAppend(srclists, s, args.end());
 
 
   this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll);
   this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll);
 
 

+ 1 - 2
Source/cmAddTestCommand.cxx

@@ -27,8 +27,7 @@ bool cmAddTestCommand::InitialPass(std::vector<std::string> const& args,
   }
   }
 
 
   // Collect the command with arguments.
   // Collect the command with arguments.
-  std::vector<std::string> command;
-  command.insert(command.end(), args.begin() + 1, args.end());
+  std::vector<std::string> command(args.begin() + 1, args.end());
 
 
   // Create the test but add a generator only the first time it is
   // Create the test but add a generator only the first time it is
   // seen.  This preserves behavior from before test generators.
   // seen.  This preserves behavior from before test generators.

+ 4 - 5
Source/cmCTest.cxx

@@ -1282,7 +1282,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
   while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
   while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
     processOutput.DecodeText(data, length, strdata);
     processOutput.DecodeText(data, length, strdata);
     if (output) {
     if (output) {
-      tempOutput.insert(tempOutput.end(), data, data + length);
+      cmAppend(tempOutput, data, data + length);
     }
     }
     cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
     cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
                cmCTestLogWrite(strdata.c_str(), strdata.size()));
                cmCTestLogWrite(strdata.c_str(), strdata.size()));
@@ -2194,8 +2194,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
   bool SRArgumentSpecified = false;
   bool SRArgumentSpecified = false;
 
 
   // copy the command line
   // copy the command line
-  this->Impl->InitialCommandLineArguments.insert(
-    this->Impl->InitialCommandLineArguments.end(), args.begin(), args.end());
+  cmAppend(this->Impl->InitialCommandLineArguments, args);
 
 
   // process the command line arguments
   // process the command line arguments
   for (size_t i = 1; i < args.size(); ++i) {
   for (size_t i = 1; i < args.size(); ++i) {
@@ -2958,10 +2957,10 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
     res = cmsysProcess_WaitForData(cp, &data, &length, nullptr);
     res = cmsysProcess_WaitForData(cp, &data, &length, nullptr);
     switch (res) {
     switch (res) {
       case cmsysProcess_Pipe_STDOUT:
       case cmsysProcess_Pipe_STDOUT:
-        tempOutput.insert(tempOutput.end(), data, data + length);
+        cmAppend(tempOutput, data, data + length);
         break;
         break;
       case cmsysProcess_Pipe_STDERR:
       case cmsysProcess_Pipe_STDERR:
-        tempError.insert(tempError.end(), data, data + length);
+        cmAppend(tempError, data, data + length);
         break;
         break;
       default:
       default:
         done = true;
         done = true;

+ 2 - 5
Source/cmConditionEvaluator.cxx

@@ -94,10 +94,7 @@ bool cmConditionEvaluator::IsTrue(
   }
   }
 
 
   // store the reduced args in this vector
   // store the reduced args in this vector
-  cmArgumentList newArgs;
-
-  // copy to the list structure
-  newArgs.insert(newArgs.end(), args.begin(), args.end());
+  cmArgumentList newArgs(args.begin(), args.end());
 
 
   // now loop through the arguments and see if we can reduce any of them
   // now loop through the arguments and see if we can reduce any of them
   // we do this multiple times. Once for each level of precedence
   // we do this multiple times. Once for each level of precedence
@@ -398,7 +395,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
         // copy to the list structure
         // copy to the list structure
         cmArgumentList::iterator argP1 = arg;
         cmArgumentList::iterator argP1 = arg;
         argP1++;
         argP1++;
-        newArgs2.insert(newArgs2.end(), argP1, argClose);
+        cmAppend(newArgs2, argP1, argClose);
         newArgs2.pop_back();
         newArgs2.pop_back();
         // now recursively invoke IsTrue to handle the values inside the
         // now recursively invoke IsTrue to handle the values inside the
         // parenthetical expression
         // parenthetical expression

+ 4 - 5
Source/cmCustomCommand.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCustomCommand.h"
 #include "cmCustomCommand.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 
 
 #include <utility>
 #include <utility>
@@ -54,13 +55,12 @@ const char* cmCustomCommand::GetComment() const
 
 
 void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines)
 void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines)
 {
 {
-  this->CommandLines.insert(this->CommandLines.end(), commandLines.begin(),
-                            commandLines.end());
+  cmAppend(this->CommandLines, commandLines);
 }
 }
 
 
 void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends)
 void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends)
 {
 {
-  this->Depends.insert(this->Depends.end(), depends.begin(), depends.end());
+  cmAppend(this->Depends, depends);
 }
 }
 
 
 bool cmCustomCommand::GetEscapeOldStyle() const
 bool cmCustomCommand::GetEscapeOldStyle() const
@@ -101,8 +101,7 @@ void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
 
 
 void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
 void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
 {
 {
-  this->ImplicitDepends.insert(this->ImplicitDepends.end(), l.begin(),
-                               l.end());
+  cmAppend(this->ImplicitDepends, l);
 }
 }
 
 
 bool cmCustomCommand::GetUsesTerminal() const
 bool cmCustomCommand::GetUsesTerminal() const

+ 5 - 7
Source/cmCustomCommandGenerator.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmCustomCommandGenerator.h"
 #include "cmCustomCommandGenerator.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmCustomCommandLines.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
@@ -33,9 +34,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
         this->GE->Parse(clarg);
         this->GE->Parse(clarg);
       std::string parsed_arg = cge->Evaluate(this->LG, this->Config);
       std::string parsed_arg = cge->Evaluate(this->LG, this->Config);
       if (this->CC.GetCommandExpandLists()) {
       if (this->CC.GetCommandExpandLists()) {
-        std::vector<std::string> ExpandedArg;
-        cmSystemTools::ExpandListArgument(parsed_arg, ExpandedArg);
-        argv.insert(argv.end(), ExpandedArg.begin(), ExpandedArg.end());
+        cmAppend(argv, cmSystemTools::ExpandedListArgument(parsed_arg));
       } else {
       } else {
         argv.push_back(std::move(parsed_arg));
         argv.push_back(std::move(parsed_arg));
       }
       }
@@ -54,15 +53,14 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
   std::vector<std::string> depends = this->CC.GetDepends();
   std::vector<std::string> depends = this->CC.GetDepends();
   for (std::string const& d : depends) {
   for (std::string const& d : depends) {
     std::unique_ptr<cmCompiledGeneratorExpression> cge = this->GE->Parse(d);
     std::unique_ptr<cmCompiledGeneratorExpression> cge = this->GE->Parse(d);
-    std::vector<std::string> result;
-    cmSystemTools::ExpandListArgument(cge->Evaluate(this->LG, this->Config),
-                                      result);
+    std::vector<std::string> result = cmSystemTools::ExpandedListArgument(
+      cge->Evaluate(this->LG, this->Config));
     for (std::string& it : result) {
     for (std::string& it : result) {
       if (cmSystemTools::FileIsFullPath(it)) {
       if (cmSystemTools::FileIsFullPath(it)) {
         it = cmSystemTools::CollapseFullPath(it);
         it = cmSystemTools::CollapseFullPath(it);
       }
       }
     }
     }
-    this->Depends.insert(this->Depends.end(), result.begin(), result.end());
+    cmAppend(this->Depends, result);
   }
   }
 
 
   const std::string& workingdirectory = this->CC.GetWorkingDirectory();
   const std::string& workingdirectory = this->CC.GetWorkingDirectory();

+ 2 - 1
Source/cmDocumentationSection.h

@@ -5,6 +5,7 @@
 
 
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
+#include "cmAlgorithms.h"
 #include "cmDocumentationEntry.h"
 #include "cmDocumentationEntry.h"
 
 
 #include <string>
 #include <string>
@@ -46,7 +47,7 @@ public:
   }
   }
   void Append(const std::vector<cmDocumentationEntry>& entries)
   void Append(const std::vector<cmDocumentationEntry>& entries)
   {
   {
-    this->Entries.insert(this->Entries.end(), entries.begin(), entries.end());
+    cmAppend(this->Entries, entries);
   }
   }
 
 
   /** Append an entry to this section using NULL terminated chars */
   /** Append an entry to this section using NULL terminated chars */

+ 2 - 1
Source/cmELF.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmELF.h"
 #include "cmELF.h"
 
 
+#include "cmAlgorithms.h"
 #include "cm_kwiml.h"
 #include "cm_kwiml.h"
 #include "cmsys/FStream.hxx"
 #include "cmsys/FStream.hxx"
 #include <map>
 #include <map>
@@ -572,7 +573,7 @@ std::vector<char> cmELFInternalImpl<Types>::EncodeDynamicEntries(
     }
     }
 
 
     char* pdyn = reinterpret_cast<char*>(&dyn);
     char* pdyn = reinterpret_cast<char*>(&dyn);
-    result.insert(result.end(), pdyn, pdyn + sizeof(ELF_Dyn));
+    cmAppend(result, pdyn, pdyn + sizeof(ELF_Dyn));
   }
   }
 
 
   return result;
   return result;

+ 1 - 1
Source/cmExecuteProcessCommand.cxx

@@ -393,5 +393,5 @@ void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
     --length;
     --length;
   }
   }
 #endif
 #endif
-  output.insert(output.end(), data, data + length);
+  cmAppend(output, data, data + length);
 }
 }

+ 2 - 1
Source/cmExportBuildFileGenerator.h

@@ -5,6 +5,7 @@
 
 
 #include "cmConfigure.h" // IWYU pragma: keep
 #include "cmConfigure.h" // IWYU pragma: keep
 
 
+#include "cmAlgorithms.h"
 #include "cmExportFileGenerator.h"
 #include "cmExportFileGenerator.h"
 #include "cmStateTypes.h"
 #include "cmStateTypes.h"
 
 
@@ -39,7 +40,7 @@ public:
   void GetTargets(std::vector<std::string>& targets) const;
   void GetTargets(std::vector<std::string>& targets) const;
   void AppendTargets(std::vector<std::string> const& targets)
   void AppendTargets(std::vector<std::string> const& targets)
   {
   {
-    this->Targets.insert(this->Targets.end(), targets.begin(), targets.end());
+    cmAppend(this->Targets, targets);
   }
   }
   void SetExportSet(cmExportSet*);
   void SetExportSet(cmExportSet*);
 
 

+ 10 - 15
Source/cmExtraCodeBlocksGenerator.cxx

@@ -209,9 +209,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
     // Collect all files
     // Collect all files
     std::vector<std::string> listFiles;
     std::vector<std::string> listFiles;
     for (cmLocalGenerator* lg : it.second) {
     for (cmLocalGenerator* lg : it.second) {
-      const std::vector<std::string>& files =
-        lg->GetMakefile()->GetListFiles();
-      listFiles.insert(listFiles.end(), files.begin(), files.end());
+      cmAppend(listFiles, lg->GetMakefile()->GetListFiles());
     }
     }
 
 
     // Convert
     // Convert
@@ -563,27 +561,24 @@ void cmExtraCodeBlocksGenerator::AppendTarget(
 
 
     // the include directories for this target
     // the include directories for this target
     std::vector<std::string> allIncludeDirs;
     std::vector<std::string> allIncludeDirs;
-
-    std::vector<std::string> includes;
-    lg->GetIncludeDirectories(includes, target, "C", buildType);
-
-    allIncludeDirs.insert(allIncludeDirs.end(), includes.begin(),
-                          includes.end());
+    {
+      std::vector<std::string> includes;
+      lg->GetIncludeDirectories(includes, target, "C", buildType);
+      cmAppend(allIncludeDirs, includes);
+    }
 
 
     std::string systemIncludeDirs = makefile->GetSafeDefinition(
     std::string systemIncludeDirs = makefile->GetSafeDefinition(
       "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
       "CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
     if (!systemIncludeDirs.empty()) {
     if (!systemIncludeDirs.empty()) {
-      std::vector<std::string> dirs;
-      cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
-      allIncludeDirs.insert(allIncludeDirs.end(), dirs.begin(), dirs.end());
+      cmAppend(allIncludeDirs,
+               cmSystemTools::ExpandedListArgument(systemIncludeDirs));
     }
     }
 
 
     systemIncludeDirs = makefile->GetSafeDefinition(
     systemIncludeDirs = makefile->GetSafeDefinition(
       "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
       "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
     if (!systemIncludeDirs.empty()) {
     if (!systemIncludeDirs.empty()) {
-      std::vector<std::string> dirs;
-      cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
-      allIncludeDirs.insert(allIncludeDirs.end(), dirs.begin(), dirs.end());
+      cmAppend(allIncludeDirs,
+               cmSystemTools::ExpandedListArgument(systemIncludeDirs));
     }
     }
 
 
     std::vector<std::string>::const_iterator end =
     std::vector<std::string>::const_iterator end =

+ 2 - 2
Source/cmFileAPICodemodel.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmFileAPICodemodel.h"
 #include "cmFileAPICodemodel.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmCryptoHash.h"
 #include "cmCryptoHash.h"
 #include "cmFileAPI.h"
 #include "cmFileAPI.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
@@ -477,8 +478,7 @@ Json::Value CodemodelConfig::DumpTargets()
   cmGlobalGenerator* gg =
   cmGlobalGenerator* gg =
     this->FileAPI.GetCMakeInstance()->GetGlobalGenerator();
     this->FileAPI.GetCMakeInstance()->GetGlobalGenerator();
   for (cmLocalGenerator const* lg : gg->GetLocalGenerators()) {
   for (cmLocalGenerator const* lg : gg->GetLocalGenerators()) {
-    std::vector<cmGeneratorTarget*> const& list = lg->GetGeneratorTargets();
-    targetList.insert(targetList.end(), list.begin(), list.end());
+    cmAppend(targetList, lg->GetGeneratorTargets());
   }
   }
   std::sort(targetList.begin(), targetList.end(),
   std::sort(targetList.begin(), targetList.end(),
             [](cmGeneratorTarget* l, cmGeneratorTarget* r) {
             [](cmGeneratorTarget* l, cmGeneratorTarget* r) {

+ 7 - 8
Source/cmFileCommand.cxx

@@ -890,7 +890,7 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
       }
       }
 
 
       std::vector<std::string>& foundFiles = g.GetFiles();
       std::vector<std::string>& foundFiles = g.GetFiles();
-      files.insert(files.end(), foundFiles.begin(), foundFiles.end());
+      cmAppend(files, foundFiles);
 
 
       if (configureDepends) {
       if (configureDepends) {
         std::sort(foundFiles.begin(), foundFiles.end());
         std::sort(foundFiles.begin(), foundFiles.end());
@@ -1476,23 +1476,22 @@ size_t cmWriteToMemoryCallback(void* ptr, size_t size, size_t nmemb,
                                void* data)
                                void* data)
 {
 {
   int realsize = static_cast<int>(size * nmemb);
   int realsize = static_cast<int>(size * nmemb);
-  cmFileCommandVectorOfChar* vec =
-    static_cast<cmFileCommandVectorOfChar*>(data);
   const char* chPtr = static_cast<char*>(ptr);
   const char* chPtr = static_cast<char*>(ptr);
-  vec->insert(vec->end(), chPtr, chPtr + realsize);
+  cmAppend(*static_cast<cmFileCommandVectorOfChar*>(data), chPtr,
+           chPtr + realsize);
   return realsize;
   return realsize;
 }
 }
 
 
 size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr,
 size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr,
                                       size_t size, void* data)
                                       size_t size, void* data)
 {
 {
-  cmFileCommandVectorOfChar* vec =
-    static_cast<cmFileCommandVectorOfChar*>(data);
+  cmFileCommandVectorOfChar& vec =
+    *static_cast<cmFileCommandVectorOfChar*>(data);
   switch (type) {
   switch (type) {
     case CURLINFO_TEXT:
     case CURLINFO_TEXT:
     case CURLINFO_HEADER_IN:
     case CURLINFO_HEADER_IN:
     case CURLINFO_HEADER_OUT:
     case CURLINFO_HEADER_OUT:
-      vec->insert(vec->end(), chPtr, chPtr + size);
+      cmAppend(vec, chPtr, chPtr + size);
       break;
       break;
     case CURLINFO_DATA_IN:
     case CURLINFO_DATA_IN:
     case CURLINFO_DATA_OUT:
     case CURLINFO_DATA_OUT:
@@ -1502,7 +1501,7 @@ size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr,
       int n = sprintf(buf, "[%" KWIML_INT_PRIu64 " bytes data]\n",
       int n = sprintf(buf, "[%" KWIML_INT_PRIu64 " bytes data]\n",
                       static_cast<KWIML_INT_uint64_t>(size));
                       static_cast<KWIML_INT_uint64_t>(size));
       if (n > 0) {
       if (n > 0) {
-        vec->insert(vec->end(), buf, buf + n);
+        cmAppend(vec, buf, buf + n);
       }
       }
     } break;
     } break;
     default:
     default:

+ 1 - 2
Source/cmFindBase.cxx

@@ -146,8 +146,7 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
     std::vector<std::string> shortArgs = this->Names;
     std::vector<std::string> shortArgs = this->Names;
     this->Names.clear(); // clear out any values in Names
     this->Names.clear(); // clear out any values in Names
     this->Names.push_back(shortArgs[0]);
     this->Names.push_back(shortArgs[0]);
-    this->UserGuessArgs.insert(this->UserGuessArgs.end(),
-                               shortArgs.begin() + 1, shortArgs.end());
+    cmAppend(this->UserGuessArgs, shortArgs.begin() + 1, shortArgs.end());
   }
   }
   this->ExpandPaths();
   this->ExpandPaths();
 
 

+ 2 - 1
Source/cmFindCommon.cxx

@@ -6,6 +6,7 @@
 #include <string.h>
 #include <string.h>
 #include <utility>
 #include <utility>
 
 
+#include "cmAlgorithms.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
@@ -221,7 +222,7 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
   // If searching both rooted and unrooted paths add the original
   // If searching both rooted and unrooted paths add the original
   // paths again.
   // paths again.
   if (this->FindRootPathMode == RootPathModeBoth) {
   if (this->FindRootPathMode == RootPathModeBoth) {
-    paths.insert(paths.end(), unrootedPaths.begin(), unrootedPaths.end());
+    cmAppend(paths, unrootedPaths);
   }
   }
 }
 }
 
 

+ 1 - 1
Source/cmFunctionCommand.cxx

@@ -177,7 +177,7 @@ bool cmFunctionCommand::InitialPass(std::vector<std::string> const& args,
 
 
   // create a function blocker
   // create a function blocker
   cmFunctionFunctionBlocker* f = new cmFunctionFunctionBlocker();
   cmFunctionFunctionBlocker* f = new cmFunctionFunctionBlocker();
-  f->Args.insert(f->Args.end(), args.begin(), args.end());
+  cmAppend(f->Args, args);
   this->Makefile->AddFunctionBlocker(f);
   this->Makefile->AddFunctionBlocker(f);
   return true;
   return true;
 }
 }

+ 3 - 2
Source/cmGeneratorExpressionParser.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmGeneratorExpressionParser.h"
 #include "cmGeneratorExpressionParser.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmGeneratorExpressionEvaluator.h"
 #include "cmGeneratorExpressionEvaluator.h"
 
 
 #include <assert.h>
 #include <assert.h>
@@ -52,9 +53,9 @@ static void extendResult(
     textContent->Extend(
     textContent->Extend(
       static_cast<TextContent*>(contents.front())->GetLength());
       static_cast<TextContent*>(contents.front())->GetLength());
     delete contents.front();
     delete contents.front();
-    result.insert(result.end(), contents.begin() + 1, contents.end());
+    cmAppend(result, contents.begin() + 1, contents.end());
   } else {
   } else {
-    result.insert(result.end(), contents.begin(), contents.end());
+    cmAppend(result, contents);
   }
   }
 }
 }
 
 

+ 1 - 1
Source/cmGlobalGenerator.h

@@ -67,7 +67,7 @@ struct GeneratedMakeCommand
   void Add(std::vector<std::string>::const_iterator start,
   void Add(std::vector<std::string>::const_iterator start,
            std::vector<std::string>::const_iterator end)
            std::vector<std::string>::const_iterator end)
   {
   {
-    PrimaryCommand.insert(PrimaryCommand.end(), start, end);
+    cmAppend(PrimaryCommand, start, end);
   }
   }
 
 
   std::string Printable() const { return cmJoin(PrimaryCommand, " "); }
   std::string Printable() const { return cmJoin(PrimaryCommand, " "); }

+ 1 - 2
Source/cmGlobalJOMMakefileGenerator.cxx

@@ -66,8 +66,7 @@ cmGlobalJOMMakefileGenerator::GenerateBuildCommand(
   // Since we have full control over the invocation of JOM, let us
   // Since we have full control over the invocation of JOM, let us
   // make it quiet.
   // make it quiet.
   jomMakeOptions.push_back(this->MakeSilentFlag);
   jomMakeOptions.push_back(this->MakeSilentFlag);
-  jomMakeOptions.insert(jomMakeOptions.end(), makeOptions.begin(),
-                        makeOptions.end());
+  cmAppend(jomMakeOptions, makeOptions);
 
 
   // JOM does parallel builds by default, the -j is only needed if a specific
   // JOM does parallel builds by default, the -j is only needed if a specific
   // number is given
   // number is given

+ 1 - 2
Source/cmGlobalNMakeMakefileGenerator.cxx

@@ -66,8 +66,7 @@ cmGlobalNMakeMakefileGenerator::GenerateBuildCommand(
   // Since we have full control over the invocation of nmake, let us
   // Since we have full control over the invocation of nmake, let us
   // make it quiet.
   // make it quiet.
   nmakeMakeOptions.push_back(this->MakeSilentFlag);
   nmakeMakeOptions.push_back(this->MakeSilentFlag);
-  nmakeMakeOptions.insert(nmakeMakeOptions.end(), makeOptions.begin(),
-                          makeOptions.end());
+  cmAppend(nmakeMakeOptions, makeOptions);
 
 
   return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
   return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
     makeProgram, projectName, projectDir, targetNames, config, fast,
     makeProgram, projectName, projectDir, targetNames, config, fast,

+ 2 - 3
Source/cmGlobalNinjaGenerator.cxx

@@ -1016,7 +1016,7 @@ void cmGlobalNinjaGenerator::AppendTargetDepends(
       this->AppendTargetOutputs(targetDep, outs, depends);
       this->AppendTargetOutputs(targetDep, outs, depends);
     }
     }
     std::sort(outs.begin(), outs.end());
     std::sort(outs.begin(), outs.end());
-    outputs.insert(outputs.end(), outs.begin(), outs.end());
+    cmAppend(outputs, outs);
   }
   }
 }
 }
 
 
@@ -1025,8 +1025,7 @@ void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
 {
 {
   cmNinjaOuts outs;
   cmNinjaOuts outs;
   this->AppendTargetDependsClosure(target, outs, true);
   this->AppendTargetDependsClosure(target, outs, true);
-
-  outputs.insert(outputs.end(), outs.begin(), outs.end());
+  cmAppend(outputs, outs);
 }
 }
 
 
 void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
 void cmGlobalNinjaGenerator::AppendTargetDependsClosure(

+ 1 - 4
Source/cmGlobalUnixMakefileGenerator3.cxx

@@ -282,11 +282,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
   // for each cmMakefile get its list of dependencies
   // for each cmMakefile get its list of dependencies
   std::vector<std::string> lfiles;
   std::vector<std::string> lfiles;
   for (cmLocalGenerator* localGen : this->LocalGenerators) {
   for (cmLocalGenerator* localGen : this->LocalGenerators) {
-    lg = static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
-
     // Get the list of files contributing to this generation step.
     // Get the list of files contributing to this generation step.
-    lfiles.insert(lfiles.end(), lg->GetMakefile()->GetListFiles().begin(),
-                  lg->GetMakefile()->GetListFiles().end());
+    cmAppend(lfiles, localGen->GetMakefile()->GetListFiles());
   }
   }
 
 
   cmake* cm = this->GetCMakeInstance();
   cmake* cm = this->GetCMakeInstance();

+ 2 - 4
Source/cmGlobalVisualStudio8Generator.cxx

@@ -141,10 +141,8 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
     // Collect the input files used to generate all targets in this
     // Collect the input files used to generate all targets in this
     // project.
     // project.
     std::vector<std::string> listFiles;
     std::vector<std::string> listFiles;
-    for (unsigned int j = 0; j < generators.size(); ++j) {
-      cmMakefile* lmf = generators[j]->GetMakefile();
-      listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
-                       lmf->GetListFiles().end());
+    for (cmLocalGenerator* gen : generators) {
+      cmAppend(listFiles, gen->GetMakefile()->GetListFiles());
     }
     }
 
 
     // Add a custom prebuild target to run the VerifyGlobs script.
     // Add a custom prebuild target to run the VerifyGlobs script.

+ 1 - 2
Source/cmGlobalXCodeGenerator.cxx

@@ -583,8 +583,7 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
 {
 {
   std::vector<std::string> lfiles;
   std::vector<std::string> lfiles;
   for (auto gen : gens) {
   for (auto gen : gens) {
-    std::vector<std::string> const& lf = gen->GetMakefile()->GetListFiles();
-    lfiles.insert(lfiles.end(), lf.begin(), lf.end());
+    cmAppend(lfiles, gen->GetMakefile()->GetListFiles());
   }
   }
 
 
   // sort the array
   // sort the array

+ 3 - 3
Source/cmIDEOptions.cxx

@@ -6,6 +6,7 @@
 #include <iterator>
 #include <iterator>
 #include <string.h>
 #include <string.h>
 
 
+#include "cmAlgorithms.h"
 #include "cmIDEFlagTable.h"
 #include "cmIDEFlagTable.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
@@ -170,7 +171,7 @@ void cmIDEOptions::AddDefines(std::string const& defines)
 }
 }
 void cmIDEOptions::AddDefines(const std::vector<std::string>& defines)
 void cmIDEOptions::AddDefines(const std::vector<std::string>& defines)
 {
 {
-  this->Defines.insert(this->Defines.end(), defines.begin(), defines.end());
+  cmAppend(this->Defines, defines);
 }
 }
 
 
 std::vector<std::string> const& cmIDEOptions::GetDefines() const
 std::vector<std::string> const& cmIDEOptions::GetDefines() const
@@ -192,8 +193,7 @@ void cmIDEOptions::AddIncludes(std::string const& includes)
 }
 }
 void cmIDEOptions::AddIncludes(const std::vector<std::string>& includes)
 void cmIDEOptions::AddIncludes(const std::vector<std::string>& includes)
 {
 {
-  this->Includes.insert(this->Includes.end(), includes.begin(),
-                        includes.end());
+  cmAppend(this->Includes, includes);
 }
 }
 
 
 std::vector<std::string> const& cmIDEOptions::GetIncludes() const
 std::vector<std::string> const& cmIDEOptions::GetIncludes() const

+ 3 - 4
Source/cmIncludeDirectoryCommand.cxx

@@ -6,6 +6,7 @@
 #include <set>
 #include <set>
 #include <utility>
 #include <utility>
 
 
+#include "cmAlgorithms.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
@@ -52,11 +53,9 @@ bool cmIncludeDirectoryCommand::InitialPass(
     this->GetIncludes(*i, includes);
     this->GetIncludes(*i, includes);
 
 
     if (before) {
     if (before) {
-      beforeIncludes.insert(beforeIncludes.end(), includes.begin(),
-                            includes.end());
+      cmAppend(beforeIncludes, includes);
     } else {
     } else {
-      afterIncludes.insert(afterIncludes.end(), includes.begin(),
-                           includes.end());
+      cmAppend(afterIncludes, includes);
     }
     }
     if (system) {
     if (system) {
       systemIncludes.insert(includes.begin(), includes.end());
       systemIncludes.insert(includes.begin(), includes.end());

+ 2 - 2
Source/cmInstallFilesCommand.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmInstallFilesCommand.h"
 #include "cmInstallFilesCommand.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
 #include "cmGlobalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmInstallFilesGenerator.h"
 #include "cmInstallFilesGenerator.h"
@@ -35,8 +36,7 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
     this->CreateInstallGenerator();
     this->CreateInstallGenerator();
   } else {
   } else {
     this->IsFilesForm = false;
     this->IsFilesForm = false;
-    this->FinalArgs.insert(this->FinalArgs.end(), args.begin() + 1,
-                           args.end());
+    cmAppend(this->FinalArgs, args.begin() + 1, args.end());
   }
   }
 
 
   this->Makefile->GetGlobalGenerator()->AddInstallComponent(
   this->Makefile->GetGlobalGenerator()->AddInstallComponent(

+ 2 - 1
Source/cmInstallProgramsCommand.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmInstallProgramsCommand.h"
 #include "cmInstallProgramsCommand.h"
 
 
+#include "cmAlgorithms.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
 #include "cmGlobalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmInstallFilesGenerator.h"
 #include "cmInstallFilesGenerator.h"
@@ -25,7 +26,7 @@ bool cmInstallProgramsCommand::InitialPass(
 
 
   this->Destination = args[0];
   this->Destination = args[0];
 
 
-  this->FinalArgs.insert(this->FinalArgs.end(), args.begin() + 1, args.end());
+  cmAppend(this->FinalArgs, args.begin() + 1, args.end());
 
 
   this->Makefile->GetGlobalGenerator()->AddInstallComponent(
   this->Makefile->GetGlobalGenerator()->AddInstallComponent(
     this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
     this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));

+ 2 - 2
Source/cmJsonObjects.cxx

@@ -2,6 +2,7 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmJsonObjects.h" // IWYU pragma: keep
 #include "cmJsonObjects.h" // IWYU pragma: keep
 
 
+#include "cmAlgorithms.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorTarget.h"
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
 #include "cmGlobalGenerator.h"
@@ -601,8 +602,7 @@ static Json::Value DumpTargetsList(
 
 
   std::vector<cmGeneratorTarget*> targetList;
   std::vector<cmGeneratorTarget*> targetList;
   for (auto const& lgIt : generators) {
   for (auto const& lgIt : generators) {
-    const auto& list = lgIt->GetGeneratorTargets();
-    targetList.insert(targetList.end(), list.begin(), list.end());
+    cmAppend(targetList, lgIt->GetGeneratorTargets());
   }
   }
   std::sort(targetList.begin(), targetList.end());
   std::sort(targetList.begin(), targetList.end());
 
 

+ 6 - 7
Source/cmLocalGenerator.cxx

@@ -351,9 +351,8 @@ void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config)
 void cmLocalGenerator::ProcessEvaluationFiles(
 void cmLocalGenerator::ProcessEvaluationFiles(
   std::vector<std::string>& generatedFiles)
   std::vector<std::string>& generatedFiles)
 {
 {
-  std::vector<cmGeneratorExpressionEvaluationFile*> ef =
-    this->Makefile->GetEvaluationFiles();
-  for (cmGeneratorExpressionEvaluationFile* geef : ef) {
+  for (cmGeneratorExpressionEvaluationFile* geef :
+       this->Makefile->GetEvaluationFiles()) {
     geef->Generate(this);
     geef->Generate(this);
     if (cmSystemTools::GetFatalErrorOccured()) {
     if (cmSystemTools::GetFatalErrorOccured()) {
       return;
       return;
@@ -372,10 +371,10 @@ void cmLocalGenerator::ProcessEvaluationFiles(
       return;
       return;
     }
     }
 
 
-    generatedFiles.insert(generatedFiles.end(), files.begin(), files.end());
-    std::vector<std::string>::iterator newIt =
-      generatedFiles.end() - files.size();
-    std::inplace_merge(generatedFiles.begin(), newIt, generatedFiles.end());
+    cmAppend(generatedFiles, files);
+    std::inplace_merge(generatedFiles.begin(),
+                       generatedFiles.end() - files.size(),
+                       generatedFiles.end());
   }
   }
 }
 }
 
 

+ 2 - 2
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -862,7 +862,7 @@ void cmLocalUnixMakefileGenerator3::AppendRuleDepends(
   // Add a dependency on the rule file itself unless an option to skip
   // Add a dependency on the rule file itself unless an option to skip
   // it is specifically enabled by the user or project.
   // it is specifically enabled by the user or project.
   if (!this->Makefile->IsOn("CMAKE_SKIP_RULE_DEPENDENCY")) {
   if (!this->Makefile->IsOn("CMAKE_SKIP_RULE_DEPENDENCY")) {
-    depends.insert(depends.end(), ruleFiles.begin(), ruleFiles.end());
+    cmAppend(depends, ruleFiles);
   }
   }
 }
 }
 
 
@@ -1037,7 +1037,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
   this->CreateCDCommand(commands1, dir, relative);
   this->CreateCDCommand(commands1, dir, relative);
 
 
   // push back the custom commands
   // push back the custom commands
-  commands.insert(commands.end(), commands1.begin(), commands1.end());
+  cmAppend(commands, commands1);
 }
 }
 
 
 void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
 void cmLocalUnixMakefileGenerator3::AppendCleanCommand(

+ 1 - 1
Source/cmMacroCommand.cxx

@@ -212,7 +212,7 @@ bool cmMacroCommand::InitialPass(std::vector<std::string> const& args,
 
 
   // create a function blocker
   // create a function blocker
   cmMacroFunctionBlocker* f = new cmMacroFunctionBlocker();
   cmMacroFunctionBlocker* f = new cmMacroFunctionBlocker();
-  f->Args.insert(f->Args.end(), args.begin(), args.end());
+  cmAppend(f->Args, args);
   this->Makefile->AddFunctionBlocker(f);
   this->Makefile->AddFunctionBlocker(f);
   return true;
   return true;
 }
 }

+ 1 - 2
Source/cmMakefile.cxx

@@ -2534,8 +2534,7 @@ const std::string& cmMakefile::GetSafeDefinition(const std::string& name) const
 std::vector<std::string> cmMakefile::GetDefinitions() const
 std::vector<std::string> cmMakefile::GetDefinitions() const
 {
 {
   std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
   std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
-  std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
-  res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
+  cmAppend(res, this->GetState()->GetCacheEntryKeys());
   std::sort(res.begin(), res.end());
   std::sort(res.begin(), res.end());
   return res;
   return res;
 }
 }

+ 3 - 3
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -268,7 +268,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
   this->LocalGenerator->CreateCDCommand(
   this->LocalGenerator->CreateCDCommand(
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     this->LocalGenerator->GetBinaryDirectory());
     this->LocalGenerator->GetBinaryDirectory());
-  commands.insert(commands.end(), commands1.begin(), commands1.end());
+  cmAppend(commands, commands1);
   commands1.clear();
   commands1.clear();
 
 
   // Write the build rule.
   // Write the build rule.
@@ -638,7 +638,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
   this->LocalGenerator->CreateCDCommand(
   this->LocalGenerator->CreateCDCommand(
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     this->LocalGenerator->GetBinaryDirectory());
     this->LocalGenerator->GetBinaryDirectory());
-  commands.insert(commands.end(), commands1.begin(), commands1.end());
+  cmAppend(commands, commands1);
   commands1.clear();
   commands1.clear();
 
 
   // Add a rule to create necessary symlinks for the library.
   // Add a rule to create necessary symlinks for the library.
@@ -651,7 +651,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
     this->LocalGenerator->CreateCDCommand(
     this->LocalGenerator->CreateCDCommand(
       commands1, this->Makefile->GetCurrentBinaryDirectory(),
       commands1, this->Makefile->GetCurrentBinaryDirectory(),
       this->LocalGenerator->GetBinaryDirectory());
       this->LocalGenerator->GetBinaryDirectory());
-    commands.insert(commands.end(), commands1.begin(), commands1.end());
+    cmAppend(commands, commands1);
     commands1.clear();
     commands1.clear();
   }
   }
 
 

+ 4 - 4
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -399,7 +399,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
   this->LocalGenerator->CreateCDCommand(
   this->LocalGenerator->CreateCDCommand(
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     this->LocalGenerator->GetBinaryDirectory());
     this->LocalGenerator->GetBinaryDirectory());
-  commands.insert(commands.end(), commands1.begin(), commands1.end());
+  cmAppend(commands, commands1);
   commands1.clear();
   commands1.clear();
 
 
   // Compute the list of outputs.
   // Compute the list of outputs.
@@ -575,7 +575,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
     this->LocalGenerator->CreateCDCommand(
     this->LocalGenerator->CreateCDCommand(
       commands1, this->Makefile->GetCurrentBinaryDirectory(),
       commands1, this->Makefile->GetCurrentBinaryDirectory(),
       this->LocalGenerator->GetBinaryDirectory());
       this->LocalGenerator->GetBinaryDirectory());
-    commands.insert(commands.end(), commands1.begin(), commands1.end());
+    cmAppend(commands, commands1);
     commands1.clear();
     commands1.clear();
   }
   }
 
 
@@ -915,7 +915,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
   this->LocalGenerator->CreateCDCommand(
   this->LocalGenerator->CreateCDCommand(
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     commands1, this->Makefile->GetCurrentBinaryDirectory(),
     this->LocalGenerator->GetBinaryDirectory());
     this->LocalGenerator->GetBinaryDirectory());
-  commands.insert(commands.end(), commands1.begin(), commands1.end());
+  cmAppend(commands, commands1);
   commands1.clear();
   commands1.clear();
 
 
   // Add a rule to create necessary symlinks for the library.
   // Add a rule to create necessary symlinks for the library.
@@ -932,7 +932,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
     this->LocalGenerator->CreateCDCommand(
     this->LocalGenerator->CreateCDCommand(
       commands1, this->Makefile->GetCurrentBinaryDirectory(),
       commands1, this->Makefile->GetCurrentBinaryDirectory(),
       this->LocalGenerator->GetBinaryDirectory());
       this->LocalGenerator->GetBinaryDirectory());
-    commands.insert(commands.end(), commands1.begin(), commands1.end());
+    cmAppend(commands, commands1);
     commands1.clear();
     commands1.clear();
   }
   }
 
 

+ 10 - 22
Source/cmMakefileTargetGenerator.cxx

@@ -219,14 +219,9 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
     std::vector<cmCustomCommand> buildEventCommands =
     std::vector<cmCustomCommand> buildEventCommands =
       this->GeneratorTarget->GetPreBuildCommands();
       this->GeneratorTarget->GetPreBuildCommands();
 
 
-    buildEventCommands.insert(
-      buildEventCommands.end(),
-      this->GeneratorTarget->GetPreLinkCommands().begin(),
-      this->GeneratorTarget->GetPreLinkCommands().end());
-    buildEventCommands.insert(
-      buildEventCommands.end(),
-      this->GeneratorTarget->GetPostBuildCommands().begin(),
-      this->GeneratorTarget->GetPostBuildCommands().end());
+    cmAppend(buildEventCommands, this->GeneratorTarget->GetPreLinkCommands());
+    cmAppend(buildEventCommands,
+             this->GeneratorTarget->GetPostBuildCommands());
 
 
     for (const auto& be : buildEventCommands) {
     for (const auto& be : buildEventCommands) {
       const std::vector<std::string>& byproducts = be.GetByproducts();
       const std::vector<std::string>& byproducts = be.GetByproducts();
@@ -819,8 +814,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
     this->LocalGenerator->CreateCDCommand(
     this->LocalGenerator->CreateCDCommand(
       compileCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
       compileCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
       this->LocalGenerator->GetBinaryDirectory());
       this->LocalGenerator->GetBinaryDirectory());
-    commands.insert(commands.end(), compileCommands.begin(),
-                    compileCommands.end());
+    cmAppend(commands, compileCommands);
   }
   }
 
 
   // Check for extra outputs created by the compilation.
   // Check for extra outputs created by the compilation.
@@ -882,8 +876,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
           preprocessCommands,
           preprocessCommands,
           this->LocalGenerator->GetCurrentBinaryDirectory(),
           this->LocalGenerator->GetCurrentBinaryDirectory(),
           this->LocalGenerator->GetBinaryDirectory());
           this->LocalGenerator->GetBinaryDirectory());
-        commands.insert(commands.end(), preprocessCommands.begin(),
-                        preprocessCommands.end());
+        cmAppend(commands, preprocessCommands);
       } else {
       } else {
         std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
         std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
         cmd += preprocessRuleVar;
         cmd += preprocessRuleVar;
@@ -929,8 +922,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
         this->LocalGenerator->CreateCDCommand(
         this->LocalGenerator->CreateCDCommand(
           assemblyCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
           assemblyCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
           this->LocalGenerator->GetBinaryDirectory());
           this->LocalGenerator->GetBinaryDirectory());
-        commands.insert(commands.end(), assemblyCommands.begin(),
-                        assemblyCommands.end());
+        cmAppend(commands, assemblyCommands);
       } else {
       } else {
         std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
         std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
         cmd += assemblyRuleVar;
         cmd += assemblyRuleVar;
@@ -1177,8 +1169,7 @@ void cmMakefileTargetGenerator::DriveCustomCommands(
     if (cmCustomCommand* cc = source->GetCustomCommand()) {
     if (cmCustomCommand* cc = source->GetCustomCommand()) {
       cmCustomCommandGenerator ccg(*cc, this->ConfigName,
       cmCustomCommandGenerator ccg(*cc, this->ConfigName,
                                    this->LocalGenerator);
                                    this->LocalGenerator);
-      const std::vector<std::string>& outputs = ccg.GetOutputs();
-      depends.insert(depends.end(), outputs.begin(), outputs.end());
+      cmAppend(depends, ccg.GetOutputs());
     }
     }
   }
   }
 }
 }
@@ -1402,8 +1393,7 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
     }
     }
 
 
     // Make sure the extra files are built.
     // Make sure the extra files are built.
-    depends.insert(depends.end(), this->ExtraFiles.begin(),
-                   this->ExtraFiles.end());
+    cmAppend(depends, this->ExtraFiles);
   }
   }
 
 
   // Write the driver rule.
   // Write the driver rule.
@@ -1425,8 +1415,7 @@ void cmMakefileTargetGenerator::AppendTargetDepends(
   const std::string& cfg = this->LocalGenerator->GetConfigName();
   const std::string& cfg = this->LocalGenerator->GetConfigName();
   if (cmComputeLinkInformation* cli =
   if (cmComputeLinkInformation* cli =
         this->GeneratorTarget->GetLinkInformation(cfg)) {
         this->GeneratorTarget->GetLinkInformation(cfg)) {
-    std::vector<std::string> const& libDeps = cli->GetDepends();
-    depends.insert(depends.end(), libDeps.begin(), libDeps.end());
+    cmAppend(depends, cli->GetDepends());
   }
   }
 }
 }
 
 
@@ -1443,8 +1432,7 @@ void cmMakefileTargetGenerator::AppendObjectDepends(
   }
   }
 
 
   // Add dependencies on the external object files.
   // Add dependencies on the external object files.
-  depends.insert(depends.end(), this->ExternalObjects.begin(),
-                 this->ExternalObjects.end());
+  cmAppend(depends, this->ExternalObjects);
 
 
   // Add a dependency on the rule file itself.
   // Add a dependency on the rule file itself.
   this->LocalGenerator->AppendRuleDepend(depends,
   this->LocalGenerator->AppendRuleDepend(depends,

+ 1 - 2
Source/cmNinjaTargetGenerator.cxx

@@ -841,8 +841,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements()
     this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering);
     this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering);
 
 
   // Add order-only dependencies on other files associated with the target.
   // Add order-only dependencies on other files associated with the target.
-  orderOnlyDeps.insert(orderOnlyDeps.end(), this->ExtraFiles.begin(),
-                       this->ExtraFiles.end());
+  cmAppend(orderOnlyDeps, this->ExtraFiles);
 
 
   // Add order-only dependencies on custom command outputs.
   // Add order-only dependencies on custom command outputs.
   for (cmCustomCommand const* cc : this->CustomCommands) {
   for (cmCustomCommand const* cc : this->CustomCommands) {

+ 2 - 4
Source/cmOrderDirectories.cxx

@@ -329,15 +329,13 @@ void cmOrderDirectories::AddLinkLibrary(std::string const& fullPath)
 void cmOrderDirectories::AddUserDirectories(
 void cmOrderDirectories::AddUserDirectories(
   std::vector<std::string> const& extra)
   std::vector<std::string> const& extra)
 {
 {
-  this->UserDirectories.insert(this->UserDirectories.end(), extra.begin(),
-                               extra.end());
+  cmAppend(this->UserDirectories, extra);
 }
 }
 
 
 void cmOrderDirectories::AddLanguageDirectories(
 void cmOrderDirectories::AddLanguageDirectories(
   std::vector<std::string> const& dirs)
   std::vector<std::string> const& dirs)
 {
 {
-  this->LanguageDirectories.insert(this->LanguageDirectories.end(),
-                                   dirs.begin(), dirs.end());
+  cmAppend(this->LanguageDirectories, dirs);
 }
 }
 
 
 void cmOrderDirectories::SetImplicitDirectories(
 void cmOrderDirectories::SetImplicitDirectories(

+ 2 - 3
Source/cmQtAutoGen.cxx

@@ -68,7 +68,7 @@ void MergeOptions(std::vector<std::string>& baseOpts,
     }
     }
   }
   }
   // Append options
   // Append options
-  baseOpts.insert(baseOpts.end(), extraOpts.begin(), extraOpts.end());
+  cmAppend(baseOpts, extraOpts);
 }
 }
 
 
 // - Class definitions
 // - Class definitions
@@ -347,8 +347,7 @@ bool cmQtAutoGen::RccLister::list(std::string const& qrcFile,
     {
     {
       std::vector<std::string> cmd;
       std::vector<std::string> cmd;
       cmd.emplace_back(this->RccExcutable_);
       cmd.emplace_back(this->RccExcutable_);
-      cmd.insert(cmd.end(), this->ListOptions_.begin(),
-                 this->ListOptions_.end());
+      cmAppend(cmd, this->ListOptions_);
       cmd.emplace_back(cmSystemTools::GetFilenameName(qrcFile));
       cmd.emplace_back(cmSystemTools::GetFilenameName(qrcFile));
 
 
       // Log command
       // Log command

+ 6 - 9
Source/cmQtAutoMocUic.cxx

@@ -293,11 +293,10 @@ void cmQtAutoMocUic::JobMocPredefsT::Process()
       // Compose command
       // Compose command
       std::vector<std::string> cmd = MocConst().PredefsCmd;
       std::vector<std::string> cmd = MocConst().PredefsCmd;
       // Add includes
       // Add includes
-      cmd.insert(cmd.end(), MocConst().Includes.begin(),
-                 MocConst().Includes.end());
+      cmAppend(cmd, MocConst().Includes);
       // Add definitions
       // Add definitions
       for (std::string const& def : MocConst().Definitions) {
       for (std::string const& def : MocConst().Definitions) {
-        cmd.push_back("-D" + def);
+        cmd.emplace_back("-D" + def);
       }
       }
       // Execute command
       // Execute command
       if (!RunProcess(GenT::MOC, result, cmd, reason.get())) {
       if (!RunProcess(GenT::MOC, result, cmd, reason.get())) {
@@ -1398,8 +1397,7 @@ void cmQtAutoMocUic::JobMocT::Process()
   std::vector<std::string> cmd;
   std::vector<std::string> cmd;
   cmd.push_back(MocConst().Executable);
   cmd.push_back(MocConst().Executable);
   // Add options
   // Add options
-  cmd.insert(cmd.end(), MocConst().AllOptions.begin(),
-             MocConst().AllOptions.end());
+  cmAppend(cmd, MocConst().AllOptions);
   // Add predefs include
   // Add predefs include
   if (!MocConst().PredefsFileAbs.empty()) {
   if (!MocConst().PredefsFileAbs.empty()) {
     cmd.emplace_back("--include");
     cmd.emplace_back("--include");
@@ -1452,7 +1450,7 @@ void cmQtAutoMocUic::JobUicT::Process()
       UicMergeOptions(allOpts, optionIt->second,
       UicMergeOptions(allOpts, optionIt->second,
                       (BaseConst().QtVersionMajor == 5));
                       (BaseConst().QtVersionMajor == 5));
     }
     }
-    cmd.insert(cmd.end(), allOpts.begin(), allOpts.end());
+    cmAppend(cmd, allOpts);
   }
   }
   cmd.emplace_back("-o");
   cmd.emplace_back("-o");
   cmd.emplace_back(outputFile);
   cmd.emplace_back(outputFile);
@@ -1881,9 +1879,8 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
     // Sort include directories on demand
     // Sort include directories on demand
     if (BaseConst().IncludeProjectDirsBefore) {
     if (BaseConst().IncludeProjectDirsBefore) {
       // Move strings to temporary list
       // Move strings to temporary list
-      std::list<std::string> includes;
-      includes.insert(includes.end(), MocConst().IncludePaths.begin(),
-                      MocConst().IncludePaths.end());
+      std::list<std::string> includes(MocConst().IncludePaths.begin(),
+                                      MocConst().IncludePaths.end());
       MocConst_.IncludePaths.clear();
       MocConst_.IncludePaths.clear();
       MocConst_.IncludePaths.reserve(includes.size());
       MocConst_.IncludePaths.reserve(includes.size());
       // Append project directories only
       // Append project directories only

+ 1 - 1
Source/cmQtAutoRcc.cxx

@@ -431,7 +431,7 @@ bool cmQtAutoRcc::GenerateRcc()
   // Compose rcc command
   // Compose rcc command
   std::vector<std::string> cmd;
   std::vector<std::string> cmd;
   cmd.push_back(RccExecutable_);
   cmd.push_back(RccExecutable_);
-  cmd.insert(cmd.end(), Options_.begin(), Options_.end());
+  cmAppend(cmd, Options_);
   cmd.emplace_back("-o");
   cmd.emplace_back("-o");
   cmd.push_back(RccFileOutput_);
   cmd.push_back(RccFileOutput_);
   cmd.push_back(QrcFile_);
   cmd.push_back(QrcFile_);

+ 2 - 1
Source/cmSetTargetPropertiesCommand.cxx

@@ -4,6 +4,7 @@
 
 
 #include <iterator>
 #include <iterator>
 
 
+#include "cmAlgorithms.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmTarget.h"
 #include "cmTarget.h"
 
 
@@ -30,7 +31,7 @@ bool cmSetTargetPropertiesCommand::InitialPass(
         this->SetError("called with incorrect number of arguments.");
         this->SetError("called with incorrect number of arguments.");
         return false;
         return false;
       }
       }
-      propertyPairs.insert(propertyPairs.end(), j, args.end());
+      cmAppend(propertyPairs, j, args.end());
       break;
       break;
     }
     }
     numFiles++;
     numFiles++;

+ 2 - 1
Source/cmSetTestsPropertiesCommand.cxx

@@ -4,6 +4,7 @@
 
 
 #include <iterator>
 #include <iterator>
 
 
+#include "cmAlgorithms.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmTest.h"
 #include "cmTest.h"
 
 
@@ -30,7 +31,7 @@ bool cmSetTestsPropertiesCommand::InitialPass(
         this->SetError("called with incorrect number of arguments.");
         this->SetError("called with incorrect number of arguments.");
         return false;
         return false;
       }
       }
-      propertyPairs.insert(propertyPairs.end(), j, args.end());
+      cmAppend(propertyPairs, j, args.end());
       break;
       break;
     }
     }
     numFiles++;
     numFiles++;

+ 1 - 3
Source/cmStateDirectory.cxx

@@ -621,9 +621,7 @@ const char* cmStateDirectory::GetProperty(const std::string& prop,
   }
   }
   if (prop == "VARIABLES") {
   if (prop == "VARIABLES") {
     std::vector<std::string> res = this->Snapshot_.ClosureKeys();
     std::vector<std::string> res = this->Snapshot_.ClosureKeys();
-    std::vector<std::string> cacheKeys =
-      this->Snapshot_.State->GetCacheEntryKeys();
-    res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
+    cmAppend(res, this->Snapshot_.State->GetCacheEntryKeys());
     std::sort(res.begin(), res.end());
     std::sort(res.begin(), res.end());
     output = cmJoin(res, ";");
     output = cmJoin(res, ";");
     return output.c_str();
     return output.c_str();

+ 7 - 7
Source/cmSystemTools.cxx

@@ -501,7 +501,7 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
 #else
 #else
         cmSystemTools::ParseUnixCommandLine(line.c_str(), args2);
         cmSystemTools::ParseUnixCommandLine(line.c_str(), args2);
 #endif
 #endif
-        arg_full.insert(arg_full.end(), args2.begin(), args2.end());
+        cmAppend(arg_full, args2);
       }
       }
     } else {
     } else {
       arg_full.push_back(arg);
       arg_full.push_back(arg);
@@ -726,7 +726,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
           cmSystemTools::Stdout(strdata);
           cmSystemTools::Stdout(strdata);
         }
         }
         if (captureStdOut) {
         if (captureStdOut) {
-          tempStdOut.insert(tempStdOut.end(), data, data + length);
+          cmAppend(tempStdOut, data, data + length);
         }
         }
       } else if (pipe == cmsysProcess_Pipe_STDERR) {
       } else if (pipe == cmsysProcess_Pipe_STDERR) {
         if (outputflag != OUTPUT_NONE) {
         if (outputflag != OUTPUT_NONE) {
@@ -734,7 +734,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
           cmSystemTools::Stderr(strdata);
           cmSystemTools::Stderr(strdata);
         }
         }
         if (captureStdErr) {
         if (captureStdErr) {
-          tempStdErr.insert(tempStdErr.end(), data, data + length);
+          cmAppend(tempStdErr, data, data + length);
         }
         }
       }
       }
     }
     }
@@ -1917,26 +1917,26 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
       processOutput.DecodeText(data, length, strdata, 1);
       processOutput.DecodeText(data, length, strdata, 1);
       // Append to the stdout buffer.
       // Append to the stdout buffer.
       std::vector<char>::size_type size = out.size();
       std::vector<char>::size_type size = out.size();
-      out.insert(out.end(), strdata.begin(), strdata.end());
+      cmAppend(out, strdata);
       outiter = out.begin() + size;
       outiter = out.begin() + size;
     } else if (pipe == cmsysProcess_Pipe_STDERR) {
     } else if (pipe == cmsysProcess_Pipe_STDERR) {
       processOutput.DecodeText(data, length, strdata, 2);
       processOutput.DecodeText(data, length, strdata, 2);
       // Append to the stderr buffer.
       // Append to the stderr buffer.
       std::vector<char>::size_type size = err.size();
       std::vector<char>::size_type size = err.size();
-      err.insert(err.end(), strdata.begin(), strdata.end());
+      cmAppend(err, strdata);
       erriter = err.begin() + size;
       erriter = err.begin() + size;
     } else if (pipe == cmsysProcess_Pipe_None) {
     } else if (pipe == cmsysProcess_Pipe_None) {
       // Both stdout and stderr pipes have broken.  Return leftover data.
       // Both stdout and stderr pipes have broken.  Return leftover data.
       processOutput.DecodeText(std::string(), strdata, 1);
       processOutput.DecodeText(std::string(), strdata, 1);
       if (!strdata.empty()) {
       if (!strdata.empty()) {
         std::vector<char>::size_type size = out.size();
         std::vector<char>::size_type size = out.size();
-        out.insert(out.end(), strdata.begin(), strdata.end());
+        cmAppend(out, strdata);
         outiter = out.begin() + size;
         outiter = out.begin() + size;
       }
       }
       processOutput.DecodeText(std::string(), strdata, 2);
       processOutput.DecodeText(std::string(), strdata, 2);
       if (!strdata.empty()) {
       if (!strdata.empty()) {
         std::vector<char>::size_type size = err.size();
         std::vector<char>::size_type size = err.size();
-        err.insert(err.end(), strdata.begin(), strdata.end());
+        cmAppend(err, strdata);
         erriter = err.begin() + size;
         erriter = err.begin() + size;
       }
       }
       if (!out.empty()) {
       if (!out.empty()) {

+ 16 - 22
Source/cmTarget.cxx

@@ -34,13 +34,6 @@
 #include "cmTargetPropertyComputer.h"
 #include "cmTargetPropertyComputer.h"
 #include "cmake.h"
 #include "cmake.h"
 
 
-//! Append all elements from the second container to the first container
-template <class C, class R>
-static inline void CApp(C& container, R const& range)
-{
-  container.insert(container.end(), range.begin(), range.end());
-}
-
 template <>
 template <>
 const char* cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
 const char* cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
   cmTarget const* tgt)
   cmTarget const* tgt)
@@ -406,29 +399,30 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
   if (!this->IsImported()) {
   if (!this->IsImported()) {
     // Initialize the INCLUDE_DIRECTORIES property based on the current value
     // Initialize the INCLUDE_DIRECTORIES property based on the current value
     // of the same directory property:
     // of the same directory property:
-    CApp(impl->IncludeDirectoriesEntries,
-         impl->Makefile->GetIncludeDirectoriesEntries());
-    CApp(impl->IncludeDirectoriesBacktraces,
-         impl->Makefile->GetIncludeDirectoriesBacktraces());
+    cmAppend(impl->IncludeDirectoriesEntries,
+             impl->Makefile->GetIncludeDirectoriesEntries());
+    cmAppend(impl->IncludeDirectoriesBacktraces,
+             impl->Makefile->GetIncludeDirectoriesBacktraces());
 
 
     {
     {
       auto const& sysInc = impl->Makefile->GetSystemIncludeDirectories();
       auto const& sysInc = impl->Makefile->GetSystemIncludeDirectories();
       impl->SystemIncludeDirectories.insert(sysInc.begin(), sysInc.end());
       impl->SystemIncludeDirectories.insert(sysInc.begin(), sysInc.end());
     }
     }
 
 
-    CApp(impl->CompileOptionsEntries,
-         impl->Makefile->GetCompileOptionsEntries());
-    CApp(impl->CompileOptionsBacktraces,
-         impl->Makefile->GetCompileOptionsBacktraces());
+    cmAppend(impl->CompileOptionsEntries,
+             impl->Makefile->GetCompileOptionsEntries());
+    cmAppend(impl->CompileOptionsBacktraces,
+             impl->Makefile->GetCompileOptionsBacktraces());
 
 
-    CApp(impl->LinkOptionsEntries, impl->Makefile->GetLinkOptionsEntries());
-    CApp(impl->LinkOptionsBacktraces,
-         impl->Makefile->GetLinkOptionsBacktraces());
+    cmAppend(impl->LinkOptionsEntries,
+             impl->Makefile->GetLinkOptionsEntries());
+    cmAppend(impl->LinkOptionsBacktraces,
+             impl->Makefile->GetLinkOptionsBacktraces());
 
 
-    CApp(impl->LinkDirectoriesEntries,
-         impl->Makefile->GetLinkDirectoriesEntries());
-    CApp(impl->LinkDirectoriesBacktraces,
-         impl->Makefile->GetLinkDirectoriesBacktraces());
+    cmAppend(impl->LinkDirectoriesEntries,
+             impl->Makefile->GetLinkDirectoriesEntries());
+    cmAppend(impl->LinkDirectoriesBacktraces,
+             impl->Makefile->GetLinkDirectoriesBacktraces());
   }
   }
 
 
   if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
   if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&

+ 1 - 4
Source/cmake.cxx

@@ -1045,10 +1045,7 @@ void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
     std::vector<std::string> names = gen->GetGeneratorNames();
     std::vector<std::string> names = gen->GetGeneratorNames();
 
 
     if (includeNamesWithPlatform) {
     if (includeNamesWithPlatform) {
-      std::vector<std::string> namesWithPlatform =
-        gen->GetGeneratorNamesWithPlatform();
-      names.insert(names.end(), namesWithPlatform.begin(),
-                   namesWithPlatform.end());
+      cmAppend(names, gen->GetGeneratorNamesWithPlatform());
     }
     }
 
 
     for (std::string const& name : names) {
     for (std::string const& name : names) {

+ 1 - 1
Source/cmakemain.cxx

@@ -122,7 +122,7 @@ static int do_command(int ac, char const* const* av)
   std::vector<std::string> args;
   std::vector<std::string> args;
   args.reserve(ac - 1);
   args.reserve(ac - 1);
   args.emplace_back(av[0]);
   args.emplace_back(av[0]);
-  args.insert(args.end(), av + 2, av + ac);
+  cmAppend(args, av + 2, av + ac);
   return cmcmd::ExecuteCMakeCommand(args);
   return cmcmd::ExecuteCMakeCommand(args);
 }
 }
 
 

+ 5 - 6
Source/cmcmd.cxx

@@ -173,7 +173,7 @@ static int HandleIWYU(const std::string& runCmd,
   // and adding all the arguments we give to the compiler.
   // and adding all the arguments we give to the compiler.
   std::vector<std::string> iwyu_cmd;
   std::vector<std::string> iwyu_cmd;
   cmSystemTools::ExpandListArgument(runCmd, iwyu_cmd, true);
   cmSystemTools::ExpandListArgument(runCmd, iwyu_cmd, true);
-  iwyu_cmd.insert(iwyu_cmd.end(), orig_cmd.begin() + 1, orig_cmd.end());
+  cmAppend(iwyu_cmd, orig_cmd.begin() + 1, orig_cmd.end());
   // Run the iwyu command line.  Capture its stderr and hide its stdout.
   // Run the iwyu command line.  Capture its stderr and hide its stdout.
   // Ignore its return code because the tool always returns non-zero.
   // Ignore its return code because the tool always returns non-zero.
   std::string stdErr;
   std::string stdErr;
@@ -201,11 +201,11 @@ static int HandleTidy(const std::string& runCmd, const std::string& sourceFile,
   // automatically skip over the compiler itself and extract the
   // automatically skip over the compiler itself and extract the
   // options.
   // options.
   int ret;
   int ret;
-  std::vector<std::string> tidy_cmd;
-  cmSystemTools::ExpandListArgument(runCmd, tidy_cmd, true);
+  std::vector<std::string> tidy_cmd =
+    cmSystemTools::ExpandedListArgument(runCmd, true);
   tidy_cmd.push_back(sourceFile);
   tidy_cmd.push_back(sourceFile);
   tidy_cmd.emplace_back("--");
   tidy_cmd.emplace_back("--");
-  tidy_cmd.insert(tidy_cmd.end(), orig_cmd.begin(), orig_cmd.end());
+  cmAppend(tidy_cmd, orig_cmd);
 
 
   // Run the tidy command line.  Capture its stdout and hide its stderr.
   // Run the tidy command line.  Capture its stdout and hide its stderr.
   std::string stdOut;
   std::string stdOut;
@@ -1919,8 +1919,7 @@ int cmVSLink::RunMT(std::string const& out, bool notify)
   if (this->LinkGeneratesManifest) {
   if (this->LinkGeneratesManifest) {
     mtCommand.push_back(this->LinkerManifestFile);
     mtCommand.push_back(this->LinkerManifestFile);
   }
   }
-  mtCommand.insert(mtCommand.end(), this->UserManifests.begin(),
-                   this->UserManifests.end());
+  cmAppend(mtCommand, this->UserManifests);
   mtCommand.push_back(out);
   mtCommand.push_back(out);
   if (notify) {
   if (notify) {
     // Add an undocumented option that enables a special return
     // Add an undocumented option that enables a special return