From: David Kalnischkies Date: Wed, 17 Jun 2015 11:30:14 +0000 (+0200) Subject: cleanup Container.erase API to look more like std::containers X-Git-Tag: 1.1.exp9~126 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/c687384b7a53887ea455fd824824429615d94f7b cleanup Container.erase API to look more like std::containers C++11 slightly changes the API again to const_iterator, but we are find with iterators in the C++03 style for now as long as they look and behave equally to the methods of the standard containers. Git-Dch: Ignore --- diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index f3b107699..d7614374e 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -77,7 +77,6 @@ template class pkgCache::Iterator : inline pkgCache *Cache() const {return Owner;} // Mixed stuff - inline void operator =(const Itr &B) {S = B.S; Owner = B.Owner;} inline bool IsGood() const { return S && Owner && ! end();} inline unsigned long Index() const {return S - OwnerPointer();} diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index 4fe1eba87..29f7540ca 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -346,13 +346,10 @@ public: /*{{{*/ bool empty() const { return _cont.empty(); } void clear() { return _cont.clear(); } - //FIXME: on ABI break, replace the first with the second without bool - void erase(iterator position) { _cont.erase((typename Container::iterator)position); } - iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); } - size_t erase(const pkgCache::PkgIterator x) { return _cont.erase(x); } - void erase(iterator first, iterator last) { _cont.erase(first, last); } size_t size() const { return _cont.size(); } - + iterator erase( iterator pos ) { return iterator(_cont.erase(pos)); } + iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first, last)); } + size_t erase(pkgCache::PkgIterator const & P) { size_t oldsize = size(); _cont.erase(std::remove(_cont.begin(), _cont.end(), P), _cont.end()); return oldsize - size(); } const_iterator begin() const { return const_iterator(_cont.begin()); } const_iterator end() const { return const_iterator(_cont.end()); } iterator begin() { return iterator(_cont.begin()); } @@ -578,9 +575,9 @@ private: void insert(const_iterator, const_iterator) { } void clear() { } - iterator& erase(iterator &iter) { return iter; } - size_t erase(const pkgCache::PkgIterator) { return 0; } - void erase(iterator, iterator) { } + iterator erase( iterator pos ); + iterator erase( iterator first, iterator last ); + size_t erase(pkgCache::PkgIterator const & P); }; /*}}}*/ typedef PackageContainer > PackageSet; @@ -780,12 +777,10 @@ public: /*{{{*/ void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); } bool empty() const { return _cont.empty(); } void clear() { return _cont.clear(); } - //FIXME: on ABI break, replace the first with the second without bool - void erase(iterator position) { _cont.erase((typename Container::iterator)position); } - iterator& erase(iterator &position, bool) { return position = _cont.erase((typename Container::iterator)position); } - size_t erase(const pkgCache::VerIterator x) { return _cont.erase(x); } - void erase(iterator first, iterator last) { _cont.erase(first, last); } size_t size() const { return _cont.size(); } + iterator erase( iterator pos ) { return iterator(_cont.erase(pos)); } + iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first, last)); } + size_t erase(pkgCache::VerIterator const & V) { size_t oldsize = size(); _cont.erase(std::remove(_cont.begin(), _cont.end(), V), _cont.end()); return oldsize - size(); } const_iterator begin() const { return const_iterator(_cont.begin()); } const_iterator end() const { return const_iterator(_cont.end()); } @@ -989,6 +984,13 @@ template<> inline void VersionContainer >::in } /*}}}*/ +template<> inline size_t PackageContainer >::erase(pkgCache::PkgIterator const &P) { + return _cont.erase(P); +} +template<> inline size_t VersionContainer >::erase(pkgCache::VerIterator const &V) { + return _cont.erase(V); +} + template<> template inline bool VersionContainer >::sort(Compare Comp) { std::sort(_cont.begin(), _cont.end(), Comp); return true; diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index de1c80309..02c73fc2e 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -238,7 +238,7 @@ static bool DoHold(CommandLine &CmdL) ioprintf(c1out,_("%s was already set on hold.\n"), Pkg.FullName(true).c_str()); else ioprintf(c1out,_("%s was already not hold.\n"), Pkg.FullName(true).c_str()); - Pkg = pkgset.erase(Pkg, true); + Pkg = pkgset.erase(Pkg); } else ++Pkg;