-static pkgCache *PrioCache;
-static int PrioComp(const void *A,const void *B)
-{
- pkgCache::VerIterator L(*PrioCache,*(pkgCache::Version **)A);
- pkgCache::VerIterator R(*PrioCache,*(pkgCache::Version **)B);
-
- if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential &&
- (R.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
- return 1;
- if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
- (R.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
- return -1;
-
- if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important &&
- (R.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important)
- return 1;
- if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important &&
- (R.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
- return -1;
-
- if (L->Priority != R->Priority)
- return R->Priority - L->Priority;
- return strcmp(L.ParentPkg().Name(),R.ParentPkg().Name());
-}
+
+struct PrioComp {
+ pkgCache &PrioCache;
+
+ explicit PrioComp(pkgCache &PrioCache) : PrioCache(PrioCache) {
+ }
+
+ bool operator() (pkgCache::Version * const &A, pkgCache::Version * const &B) {
+ return compare(A, B) < 0;
+ }
+
+ int compare(pkgCache::Version * const &A, pkgCache::Version * const &B) {
+ pkgCache::VerIterator L(PrioCache,A);
+ pkgCache::VerIterator R(PrioCache,B);
+
+ if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential &&
+ (R.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
+ return 1;
+ if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
+ (R.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+ return -1;
+
+ if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important &&
+ (R.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important)
+ return 1;
+ if ((L.ParentPkg()->Flags & pkgCache::Flag::Important) != pkgCache::Flag::Important &&
+ (R.ParentPkg()->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+ return -1;
+
+ if (L->Priority != R->Priority)
+ return R->Priority - L->Priority;
+ return strcmp(L.ParentPkg().Name(),R.ParentPkg().Name());
+ }
+};
+