From c3800e54583208ac4a6435884bb8832e72af3183 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Fri, 10 Feb 2017 23:04:32 +0100 Subject: cmAlgorithms: add cmEraseIf function --- Source/cmAlgorithms.h | 6 ++++++ Source/cmGlobalVisualStudio14Generator.cxx | 3 +-- Source/cmLocalUnixMakefileGenerator3.cxx | 5 +---- Source/cmMakefile.cxx | 13 ++----------- Source/cmNinjaNormalTargetGenerator.cxx | 18 ++++++------------ 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 7c683ad..f5469e5 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -101,6 +101,12 @@ FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last) return first; } +template +void cmEraseIf(Container& cont, Predicate pred) +{ + cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); +} + namespace ContainerAlgorithms { template diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 81c305c..d2ac36b 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -238,8 +238,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion() // Skip SDKs that do not contain because that indicates that // only the UCRT MSIs were installed for them. - sdks.erase(std::remove_if(sdks.begin(), sdks.end(), NoWindowsH()), - sdks.end()); + cmEraseIf(sdks, NoWindowsH()); if (!sdks.empty()) { // Only use the filename, which will be the SDK version. diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 41a4caf..4388e75 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1864,10 +1864,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo( std::string binaryDir = this->GetState()->GetBinaryDirectory(); if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) { const char* sourceDir = this->GetState()->GetSourceDirectory(); - std::vector::iterator itr = - std::remove_if(includes.begin(), includes.end(), - ::NotInProjectDir(sourceDir, binaryDir)); - includes.erase(itr, includes.end()); + cmEraseIf(includes, ::NotInProjectDir(sourceDir, binaryDir)); } for (std::vector::iterator i = includes.begin(); i != includes.end(); ++i) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index bfe46ae..618f694 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -653,21 +653,12 @@ void cmMakefile::FinalPass() // we don't want cmake to re-run if a configured file is created and deleted // during processing as that would make it a transient file that can't // influence the build process - - // remove_if will move all items that don't have a valid file name to the - // back of the vector - std::vector::iterator new_output_files_end = std::remove_if( - this->OutputFiles.begin(), this->OutputFiles.end(), file_not_persistent()); - // we just have to erase all items at the back - this->OutputFiles.erase(new_output_files_end, this->OutputFiles.end()); + cmEraseIf(this->OutputFiles, file_not_persistent()); // if a configured file is used as input for another configured file, // and then deleted it will show up in the input list files so we // need to scan those too - std::vector::iterator new_list_files_end = std::remove_if( - this->ListFiles.begin(), this->ListFiles.end(), file_not_persistent()); - - this->ListFiles.erase(new_list_files_end, this->ListFiles.end()); + cmEraseIf(this->ListFiles, file_not_persistent()); } // Generate the output file diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index b172478..9bf0ccd 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -260,12 +260,9 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile) rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i, vars); } - { - // If there is no ranlib the command will be ":". Skip it. - std::vector::iterator newEnd = std::remove_if( - linkCmds.begin(), linkCmds.end(), cmNinjaRemoveNoOpCommands()); - linkCmds.erase(newEnd, linkCmds.end()); - } + + // If there is no ranlib the command will be ":". Skip it. + cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands()); std::string linkCmd = this->GetLocalGenerator()->BuildCommandLine(linkCmds); @@ -388,12 +385,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i, vars); } - { - // If there is no ranlib the command will be ":". Skip it. - std::vector::iterator newEnd = std::remove_if( - linkCmds.begin(), linkCmds.end(), cmNinjaRemoveNoOpCommands()); - linkCmds.erase(newEnd, linkCmds.end()); - } + + // If there is no ranlib the command will be ":". Skip it. + cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands()); linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.push_back("$POST_BUILD"); -- cgit v0.12