cmAlgorithms: add cmEraseIf function

This commit is contained in:
Daniel Pfeifer
2017-02-10 23:04:32 +01:00
parent ee3295e917
commit c3800e5458
5 changed files with 16 additions and 29 deletions
+6
View File
@@ -101,6 +101,12 @@ FwdIt cmRotate(FwdIt first, FwdIt middle, FwdIt last)
return first;
}
template <typename Container, typename Predicate>
void cmEraseIf(Container& cont, Predicate pred)
{
cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
}
namespace ContainerAlgorithms {
template <typename T>
+1 -2
View File
@@ -238,8 +238,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
// Skip SDKs that do not contain <um/windows.h> 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.
+1 -4
View File
@@ -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<std::string>::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<std::string>::iterator i = includes.begin();
i != includes.end(); ++i) {
+2 -11
View File
@@ -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<std::string>::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<std::string>::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
+6 -12
View File
@@ -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<std::string>::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<std::string>::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");