From 2fc9d1ebca203b4a159dba5e817081155099f6ab Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 17 Sep 2015 13:13:41 +0200 Subject: add cacheset push_back wrapping for std::back_inserter As usual by now, not all containers wrapped by the cacheset containers support all methods, like push_back now, but they fail on use of these unusable methods only. Would be nice to not expose these methods for unsupporting containers at all, but that means either a lot of classes or a lot of std::enable_if magic, which seems like too big work for this small wrapper for now. Git-Dch: Ignore --- cmdline/apt-mark.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 9b51345a3..d9a93fa05 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -180,13 +180,13 @@ static bool DoHold(CommandLine &CmdL) bool const MarkHold = strcasecmp(CmdL.FileList[0],"hold") == 0; - auto part = std::stable_partition(pkgset.begin(), pkgset.end(), + auto const part = std::stable_partition(pkgset.begin(), pkgset.end(), [](pkgCache::PkgIterator const &P) { return P->SelectedState == pkgCache::State::Hold; }); - auto doneBegin = MarkHold ? pkgset.begin() : part; - auto doneEnd = MarkHold ? part : pkgset.end(); - auto changeBegin = MarkHold ? part : pkgset.begin(); - auto changeEnd = MarkHold ? pkgset.end() : part; + auto const doneBegin = MarkHold ? pkgset.begin() : part; + auto const doneEnd = MarkHold ? part : pkgset.end(); + auto const changeBegin = MarkHold ? part : pkgset.begin(); + auto const changeEnd = MarkHold ? pkgset.end() : part; std::for_each(doneBegin, doneEnd, [&MarkHold](pkgCache::PkgIterator const &P) { if (MarkHold == true) @@ -238,12 +238,8 @@ static bool DoHold(CommandLine &CmdL) } APT::PackageList keepoffset; - for (APT::PackageList::iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg) - { - if (Pkg->CurrentVer != 0) - continue; - keepoffset.insert(*Pkg); - } + std::copy_if(changeBegin, changeEnd, std::back_inserter(keepoffset), + [](pkgCache::PkgIterator const &P) { return P->CurrentVer == 0; }); if (keepoffset.empty() == false) { -- cgit v1.2.3