This file is indexed.

/usr/include/apt-pkg/cacheset.h is in libapt-pkg-dev 1.6.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
/** \file cacheset.h
   Wrappers around std::set to have set::iterators which behave
   similar to the Iterators of the cache structures.

   Provides also a few helper methods which work with these sets */
									/*}}}*/
#ifndef APT_CACHESET_H
#define APT_CACHESET_H
// Include Files							/*{{{*/
#include <fstream>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <forward_list>
#include <initializer_list>
#include <unordered_set>
#endif
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <string>
#include <vector>

#include <stddef.h>

#include <apt-pkg/error.h>
#include <apt-pkg/macros.h>
#include <apt-pkg/pkgcache.h>

#ifndef APT_8_CLEANER_HEADERS
#include <apt-pkg/cachefile.h>
#endif
#ifndef APT_10_CLEANER_HEADERS
#include <iostream>
#endif
									/*}}}*/

class pkgCacheFile;

namespace APT {
class PackageContainerInterface;
class VersionContainerInterface;

class CacheSetHelper {							/*{{{*/
/** \class APT::CacheSetHelper
    Simple base class with a lot of virtual methods which can be overridden
    to alter the behavior or the output of the CacheSets.

    This helper is passed around by the static methods in the CacheSets and
    used every time they hit an error condition or something could be
    printed out.
*/
public:									/*{{{*/
	CacheSetHelper(bool const ShowError = true,
		GlobalError::MsgType ErrorType = GlobalError::ERROR);
	virtual ~CacheSetHelper();

	enum PkgSelector { UNKNOWN, REGEX, TASK, FNMATCH, PACKAGENAME, STRING };

	virtual bool PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);

	virtual bool PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline);

	struct PkgModifier {
		enum Position { NONE, PREFIX, POSTFIX };
		unsigned short ID;
		const char * const Alias;
		Position Pos;
		PkgModifier (unsigned short const &id, const char * const alias, Position const &pos) : ID(id), Alias(alias), Pos(pos) {}
	};
	virtual bool PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
					    pkgCacheFile &Cache, const char * cmdline,
					    std::list<PkgModifier> const &mods);

	APT_DEPRECATED_MSG("use .PackageFrom(PACKAGENAME, …) instead") pkgCache::PkgIterator PackageFromName(pkgCacheFile &Cache, std::string const &pattern);

	/** \brief be notified about the package being selected via pattern
	 *
	 * Main use is probably to show a message to the user what happened
	 *
	 * \param pkg is the package which was selected
	 * \param select is the selection method which choose the package
	 * \param pattern is the string used by the selection method to pick the package
	 */
	virtual void showPackageSelection(pkgCache::PkgIterator const &pkg, PkgSelector const select, std::string const &pattern);
	// use the method above instead, react only on the type you need and let the base handle the rest if need be
	// this allows us to add new selection methods without breaking the ABI constantly with new virtual methods
	APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showTaskSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
	APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showRegExSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);
	APT_DEPRECATED_MSG("override .showPackageSelection and select with switch") virtual void showFnmatchSelection(pkgCache::PkgIterator const &pkg, std::string const &pattern);

	/** \brief be notified if a package can't be found via pattern
	 *
	 * Can be used to show a message as well as to try something else to make it match
	 *
	 * \param select is the method tried for selection
	 * \param pci is the container the package should be inserted in
	 * \param Cache is the package universe available
	 * \param pattern is the string not matching anything
	 */
	virtual void canNotFindPackage(enum PkgSelector const select, PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
	// same as above for showPackageSelection
	APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	APT_DEPRECATED_MSG("override .canNotFindPackage and select with switch") virtual void canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str);

	/** \brief specifies which version(s) we want to refer to */
	enum VerSelector {
		/** by release string */
		RELEASE,
		/** by version number string */
		VERSIONNUMBER,
		/** All versions */
		ALL,
		/** Candidate and installed version */
		CANDANDINST,
		/** Candidate version */
		CANDIDATE,
		/** Installed version */
		INSTALLED,
		/** Candidate or if non installed version */
		CANDINST,
		/** Installed or if non candidate version */
		INSTCAND,
		/** Newest version */
		NEWEST
	};

	/** \brief be notified about the version being selected via pattern
	 *
	 * Main use is probably to show a message to the user what happened
	 * Note that at the moment this method is only called for RELEASE
	 * and VERSION selections, not for the others.
	 *
	 * \param Pkg is the package which was selected for
	 * \param Ver is the version selected
	 * \param select is the selection method which choose the version
	 * \param pattern is the string used by the selection method to pick the version
	 */
	virtual void showVersionSelection(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver,
	      enum VerSelector const select, std::string const &pattern);
	APT_DEPRECATED_MSG("use .showVersionSelection instead, similar to .showPackageSelection") virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
				 std::string const &ver, bool const verIsRel);

	/** \brief be notified if a version can't be found for a package
	 *
	 * Main use is probably to show a message to the user what happened
	 *
	 * \param select is the method tried for selection
	 * \param vci is the container the version should be inserted in
	 * \param Cache is the package universe available
	 * \param Pkg is the package we wanted a version from
	 */
	virtual void canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
	APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
	APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
				pkgCache::PkgIterator const &Pkg);
	APT_DEPRECATED_MSG("override .canNotFindVersion and select via switch") virtual void canNotFindCandInstVer(VersionContainerInterface * const vci,
				pkgCacheFile &Cache,
				pkgCache::PkgIterator const &Pkg);

	// the difference between canNotFind and canNotGet is that the later is more low-level
	// and called from other places: In this case looking into the code is the only real answer…
	virtual pkgCache::VerIterator canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg);
	APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache,
				pkgCache::PkgIterator const &Pkg);
	APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache,
				pkgCache::PkgIterator const &Pkg);
	APT_DEPRECATED_MSG("override .canNotGetVersion and select via switch") virtual pkgCache::VerIterator canNotFindInstalledVer(pkgCacheFile &Cache,
				pkgCache::PkgIterator const &Pkg);

	virtual pkgCache::PkgIterator canNotFindPkgName(pkgCacheFile &Cache, std::string const &str);

	bool showErrors() const { return ShowError; }
	bool showErrors(bool const newValue) { if (ShowError == newValue) return ShowError; else return ((ShowError = newValue) == false); }
	GlobalError::MsgType errorType() const { return ErrorType; }
	GlobalError::MsgType errorType(GlobalError::MsgType const &newValue)
	{
		if (ErrorType == newValue) return ErrorType;
		else {
			GlobalError::MsgType const &oldValue = ErrorType;
			ErrorType = newValue;
			return oldValue;
		}
	}

									/*}}}*/
protected:
	bool ShowError;
	GlobalError::MsgType ErrorType;

	pkgCache::VerIterator canNotGetInstCandVer(pkgCacheFile &Cache,
		pkgCache::PkgIterator const &Pkg);
	pkgCache::VerIterator canNotGetCandInstVer(pkgCacheFile &Cache,
		pkgCache::PkgIterator const &Pkg);

	bool PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	bool PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	bool PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	bool PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern);
	bool PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern);
private:
	void * const d;
};									/*}}}*/
// Iterator templates for our Containers				/*{{{*/
template<typename Interface, typename Master, typename iterator_type, typename container_iterator, typename container_value> class Container_iterator_base :
   public std::iterator<typename std::iterator_traits<container_iterator>::iterator_category, container_value>,
   public Interface::template iterator_base<iterator_type>
{
protected:
	container_iterator _iter;
public:
	explicit Container_iterator_base(container_iterator i) : _iter(i) {}
	inline container_value operator*(void) const { return static_cast<iterator_type const*>(this)->getType(); };
	operator container_iterator(void) const { return _iter; }
	inline iterator_type& operator++() { ++_iter; return static_cast<iterator_type&>(*this); }
	inline iterator_type operator++(int) { iterator_type tmp(*this); operator++(); return tmp; }
	inline iterator_type operator+(typename container_iterator::difference_type const &n) { return iterator_type(_iter + n); }
	inline iterator_type operator+=(typename container_iterator::difference_type const &n) { _iter += n; return static_cast<iterator_type&>(*this); }
	inline iterator_type& operator--() { --_iter;; return static_cast<iterator_type&>(*this); }
	inline iterator_type operator--(int) { iterator_type tmp(*this); operator--(); return tmp; }
	inline iterator_type operator-(typename container_iterator::difference_type const &n) { return iterator_type(_iter - n); }
	inline typename container_iterator::difference_type operator-(iterator_type const &b) { return (_iter - b._iter); }
	inline iterator_type operator-=(typename container_iterator::difference_type const &n) { _iter -= n; return static_cast<iterator_type&>(*this); }
	inline bool operator!=(iterator_type const &i) const { return _iter != i._iter; }
	inline bool operator==(iterator_type const &i) const { return _iter == i._iter; }
	inline bool operator<(iterator_type const &i) const { return _iter < i._iter; }
	inline bool operator>(iterator_type const &i) const { return _iter > i._iter; }
	inline bool operator<=(iterator_type const &i) const { return _iter <= i._iter; }
	inline bool operator>=(iterator_type const &i) const { return _iter >= i._iter; }
	inline typename container_iterator::reference operator[](typename container_iterator::difference_type const &n) const { return _iter[n]; }

	friend std::ostream& operator<<(std::ostream& out, iterator_type i) { return operator<<(out, *i); }
	friend Master;
};
template<class Interface, class Container, class Master> class Container_const_iterator :
   public Container_iterator_base<Interface, Master, Container_const_iterator<Interface, Container, Master>, typename Container::const_iterator, typename Container::value_type>
{
	typedef Container_const_iterator<Interface, Container, Master> iterator_type;
	typedef typename Container::const_iterator container_iterator;
public:
	explicit Container_const_iterator(container_iterator i) :
	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}

	inline typename Container::value_type getType(void) const { return *this->_iter; }
};
template<class Interface, class Container, class Master> class Container_iterator :
   public Container_iterator_base<Interface, Master, Container_iterator<Interface, Container, Master>, typename Container::iterator, typename Container::value_type>
{
	typedef Container_iterator<Interface, Container, Master> iterator_type;
	typedef typename Container::iterator container_iterator;
public:
	explicit Container_iterator(container_iterator i) :
	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}

	operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); }
	inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); }
	inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
	inline typename Container::iterator::reference operator*(void) const { return *this->_iter; }

	inline typename Container::value_type getType(void) const { return *this->_iter; }
};
template<class Interface, class Container, class Master> class Container_const_reverse_iterator :
   public Container_iterator_base<Interface, Master, Container_const_reverse_iterator<Interface, Container, Master>, typename Container::const_reverse_iterator, typename Container::value_type>
{
	typedef Container_const_reverse_iterator<Interface, Container, Master> iterator_type;
	typedef typename Container::const_reverse_iterator container_iterator;
public:
	explicit Container_const_reverse_iterator(container_iterator i) :
	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}

	inline typename Container::value_type getType(void) const { return *this->_iter; }
};
template<class Interface, class Container, class Master> class Container_reverse_iterator :
   public Container_iterator_base<Interface, Master, Container_reverse_iterator<Interface, Container, Master>, typename Container::reverse_iterator, typename Container::value_type>
{
	typedef Container_reverse_iterator<Interface, Container, Master> iterator_type;
	typedef typename Container::reverse_iterator container_iterator;
public:
	explicit Container_reverse_iterator(container_iterator i) :
	   Container_iterator_base<Interface, Master, iterator_type, container_iterator, typename Container::value_type>(i) {}

	operator typename Master::const_iterator() { return typename Master::const_iterator(this->_iter); }
	inline iterator_type& operator=(iterator_type const &i) { this->_iter = i._iter; return static_cast<iterator_type&>(*this); }
	inline iterator_type& operator=(container_iterator const &i) { this->_iter = i; return static_cast<iterator_type&>(*this); }
	inline typename Container::reverse_iterator::reference operator*(void) const { return *this->_iter; }

	inline typename Container::value_type getType(void) const { return *this->_iter; }
};
									/*}}}*/
class PackageContainerInterface {					/*{{{*/
/** \class PackageContainerInterface

 * Interface ensuring that all operations can be executed on the yet to
 * define concrete PackageContainer - access to all methods is possible,
 * but in general the wrappers provided by the PackageContainer template
 * are nicer to use.

 * This class mostly protects use from the need to write all implementation
 * of the methods working on containers in the template */
public:
	template<class Itr> class iterator_base {			/*{{{*/
		pkgCache::PkgIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
	public:
		operator pkgCache::PkgIterator(void) const { return getType(); }

		inline const char *Name() const {return getType().Name(); }
		inline std::string FullName(bool const Pretty) const { return getType().FullName(Pretty); }
		inline std::string FullName() const { return getType().FullName(); }
		APT_DEPRECATED_MSG("Use the .Section method of VerIterator instead") inline const char *Section() const {
		   APT_IGNORE_DEPRECATED_PUSH
		      return getType().Section();
		   APT_IGNORE_DEPRECATED_POP
		}
		inline bool Purge() const {return getType().Purge(); }
		inline const char *Arch() const {return getType().Arch(); }
		inline pkgCache::GrpIterator Group() const { return getType().Group(); }
		inline pkgCache::VerIterator VersionList() const { return getType().VersionList(); }
		inline pkgCache::VerIterator CurrentVer() const { return getType().CurrentVer(); }
		inline pkgCache::DepIterator RevDependsList() const { return getType().RevDependsList(); }
		inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
		inline pkgCache::PkgIterator::OkState State() const { return getType().State(); }
		APT_DEPRECATED_MSG("This method does not respect apt_preferences! Use pkgDepCache::GetCandidateVersion(Pkg)") inline const char *CandVersion() const { return getType().CandVersion(); }
		inline const char *CurVersion() const { return getType().CurVersion(); }
		inline pkgCache *Cache() const { return getType().Cache(); }
		inline unsigned long Index() const {return getType().Index();}
		// we have only valid iterators here
		inline bool end() const { return false; }

		inline pkgCache::Package const * operator->() const {return &*getType();}
	};
									/*}}}*/

	virtual bool insert(pkgCache::PkgIterator const &P) = 0;
	virtual bool empty() const = 0;
	virtual void clear() = 0;
	virtual size_t size() const = 0;

	enum APT_DEPRECATED_MSG("Use CacheSetHelper::PkgSelector instead") Constructor { UNKNOWN = CacheSetHelper::UNKNOWN,
		REGEX = CacheSetHelper::REGEX,
		TASK = CacheSetHelper::TASK,
		FNMATCH = CacheSetHelper::FNMATCH };
APT_IGNORE_DEPRECATED_PUSH
	void setConstructor(Constructor const by) { ConstructedBy = (CacheSetHelper::PkgSelector)by; }
APT_IGNORE_DEPRECATED_POP

	void setConstructor(CacheSetHelper::PkgSelector const by) { ConstructedBy = by; }
	CacheSetHelper::PkgSelector getConstructor() const { return ConstructedBy; }
	PackageContainerInterface();
	explicit PackageContainerInterface(CacheSetHelper::PkgSelector const by);
	PackageContainerInterface& operator=(PackageContainerInterface const &other);
	virtual ~PackageContainerInterface();

	APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::TASK, …) instead") static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
	   return helper.PackageFrom(CacheSetHelper::TASK, pci, Cache, pattern); }
	APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::REGEX, …) instead") static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
	   return helper.PackageFrom(CacheSetHelper::REGEX, pci, Cache, pattern); }
	APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::FNMATCH, …) instead") static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
	   return helper.PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, pattern); }
	APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::PACKAGENAME, …) instead") static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
	   return helper.PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, pattern); }
	APT_DEPRECATED_MSG("Use helper.PackageFrom(CacheSetHelper::STRING, …) instead") static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
	   return helper.PackageFrom(CacheSetHelper::STRING, pci, Cache, pattern); }
	APT_DEPRECATED_MSG("Use helper.PackageFromCommandLine instead") static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
	   return helper.PackageFromCommandLine(pci, Cache, cmdline); }

	APT_DEPRECATED_MSG("enum moved to CacheSetHelper::PkgModifier") typedef CacheSetHelper::PkgModifier Modifier;

APT_IGNORE_DEPRECATED_PUSH
	APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
	   return helper.PackageFromName(Cache, pattern); }
	APT_DEPRECATED_MSG("Use helper.PackageFromModifierCommandLine instead") static bool FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
	      pkgCacheFile &Cache, const char * cmdline,
	      std::list<Modifier> const &mods, CacheSetHelper &helper) {
	   return helper.PackageFromModifierCommandLine(modID, pci, Cache, cmdline, mods); }
APT_IGNORE_DEPRECATED_POP

private:
	CacheSetHelper::PkgSelector ConstructedBy;
	void * const d;
};
									/*}}}*/
template<class Container> class PackageContainer : public PackageContainerInterface {/*{{{*/
/** \class APT::PackageContainer

    Simple wrapper around a container class like std::set to provide a similar
    interface to a set of packages as to the complete set of all packages in the
    pkgCache. */
	Container _cont;
public:									/*{{{*/
	/** \brief smell like a pkgCache::PkgIterator */
	typedef Container_const_iterator<PackageContainerInterface, Container, PackageContainer> const_iterator;
	typedef Container_iterator<PackageContainerInterface, Container, PackageContainer> iterator;
	typedef Container_const_reverse_iterator<PackageContainerInterface, Container, PackageContainer> const_reverse_iterator;
	typedef Container_reverse_iterator<PackageContainerInterface, Container, PackageContainer> reverse_iterator;
	typedef typename Container::value_type value_type;
	typedef typename Container::pointer pointer;
	typedef typename Container::const_pointer const_pointer;
	typedef typename Container::reference reference;
	typedef typename Container::const_reference const_reference;
	typedef typename Container::difference_type difference_type;
	typedef typename Container::size_type size_type;
	typedef typename Container::allocator_type allocator_type;

	bool insert(pkgCache::PkgIterator const &P) APT_OVERRIDE { if (P.end() == true) return false; _cont.insert(P); return true; }
	template<class Cont> void insert(PackageContainer<Cont> const &pkgcont) { _cont.insert((typename Cont::const_iterator)pkgcont.begin(), (typename Cont::const_iterator)pkgcont.end()); }
	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }

	bool empty() const APT_OVERRIDE { return _cont.empty(); }
	void clear() APT_OVERRIDE { return _cont.clear(); }
	size_t size() const APT_OVERRIDE { return _cont.size(); }
#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
	iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
	iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
#else
	iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
	iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
#endif
	const_iterator begin() const { return const_iterator(_cont.begin()); }
	const_iterator end() const { return const_iterator(_cont.end()); }
	const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
	const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
#if __cplusplus >= 201103L
	const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
	const_iterator cend() const { return const_iterator(_cont.cend()); }
	const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
	const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
#endif
	iterator begin() { return iterator(_cont.begin()); }
	iterator end() { return iterator(_cont.end()); }
	reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
	reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
	const_iterator find(pkgCache::PkgIterator const &P) const { return const_iterator(_cont.find(P)); }

	PackageContainer() : PackageContainerInterface(CacheSetHelper::UNKNOWN) {}
	explicit PackageContainer(CacheSetHelper::PkgSelector const &by) : PackageContainerInterface(by) {}
APT_IGNORE_DEPRECATED_PUSH
	APT_DEPRECATED_MSG("Construct with a CacheSetHelper::PkgSelector instead") explicit PackageContainer(Constructor const &by) : PackageContainerInterface((CacheSetHelper::PkgSelector)by) {}
APT_IGNORE_DEPRECATED_POP
	template<typename Itr> PackageContainer(Itr first, Itr last) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(first, last) {}
#if __cplusplus >= 201103L
	PackageContainer(std::initializer_list<value_type> list) : PackageContainerInterface(CacheSetHelper::UNKNOWN), _cont(list) {}
	void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); }
	template<typename... Args> void emplace_back(Args&&... args) { _cont.emplace_back(std::forward<Args>(args)...); }
#endif
	void push_back(const value_type& P) { _cont.push_back(P); }

	/** \brief sort all included versions with given comparer

	    Some containers are sorted by default, some are not and can't be,
	    but a few like std::vector can be sorted if need be, so this can be
	    specialized in later on. The default is that this will fail though.
	    Specifically, already sorted containers like std::set will return
	    false as well as there is no easy way to check that the given comparer
	    would sort in the same way the set is currently sorted

	    \return \b true if the set was sorted, \b false if not. */
	template<class Compare> bool sort(Compare /*Comp*/) { return false; }

	/** \brief returns all packages in the cache who belong to the given task

	    A simple helper responsible for search for all members of a task
	    in the cache. Optional it prints a notice about the
	    packages chosen cause of the given task.
	    \param Cache the packages are in
	    \param pattern name of the task
	    \param helper responsible for error and message handling */
	static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
		PackageContainer cont(CacheSetHelper::TASK);
		helper.PackageFrom(CacheSetHelper::TASK, &cont, Cache, pattern);
		return cont;
	}
	static PackageContainer FromTask(pkgCacheFile &Cache, std::string const &pattern) {
		CacheSetHelper helper;
		return FromTask(Cache, pattern, helper);
	}

	/** \brief returns all packages in the cache whose name matchs a given pattern

	    A simple helper responsible for executing a regular expression on all
	    package names in the cache. Optional it prints a notice about the
	    packages chosen cause of the given package.
	    \param Cache the packages are in
	    \param pattern regular expression for package names
	    \param helper responsible for error and message handling */
	static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
		PackageContainer cont(CacheSetHelper::REGEX);
		helper.PackageFrom(CacheSetHelper::REGEX, &cont, Cache, pattern);
		return cont;
	}

	static PackageContainer FromRegEx(pkgCacheFile &Cache, std::string const &pattern) {
		CacheSetHelper helper;
		return FromRegEx(Cache, pattern, helper);
	}

	static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
		PackageContainer cont(CacheSetHelper::FNMATCH);
		helper.PackageFrom(CacheSetHelper::FNMATCH, &cont, Cache, pattern);
		return cont;
	}
	static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) {
		CacheSetHelper helper;
		return FromFnmatch(Cache, pattern, helper);
	}

APT_IGNORE_DEPRECATED_PUSH
	/** \brief returns a package specified by a string

	    \param Cache the package is in
	    \param pattern String the package name should be extracted from
	    \param helper responsible for error and message handling */
	APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
		return helper.PackageFromName(Cache, pattern);
	}
	APT_DEPRECATED_MSG("Use helper.PackageFromName instead") static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern) {
		CacheSetHelper helper;
		return FromName(Cache, pattern, helper);
	}
APT_IGNORE_DEPRECATED_POP

	/** \brief returns all packages specified by a string

	    \param Cache the packages are in
	    \param pattern String the package name(s) should be extracted from
	    \param helper responsible for error and message handling */
	static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper) {
		PackageContainer cont;
		helper.PackageFrom(CacheSetHelper::PACKAGENAME, &cont, Cache, pattern);
		return cont;
	}
	static PackageContainer FromString(pkgCacheFile &Cache, std::string const &pattern) {
		CacheSetHelper helper;
		return FromString(Cache, pattern, helper);
	}

	/** \brief returns all packages specified on the commandline

	    Get all package names from the commandline and executes regex's if needed.
	    No special package command is supported, just plain names.
	    \param Cache the packages are in
	    \param cmdline Command line the package names should be extracted from
	    \param helper responsible for error and message handling */
	static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
		PackageContainer cont;
		helper.PackageFromCommandLine(&cont, Cache, cmdline);
		return cont;
	}
	static PackageContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
		CacheSetHelper helper;
		return FromCommandLine(Cache, cmdline, helper);
	}

	/** \brief group packages by a action modifiers

	    At some point it is needed to get from the same commandline
	    different package sets grouped by a modifier. Take
		apt-get install apt awesome-
	    as an example.
	    \param Cache the packages are in
	    \param cmdline Command line the package names should be extracted from
	    \param mods list of modifiers the method should accept
	    \param fallback the default modifier group for a package
	    \param helper responsible for error and message handling */
	static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
										 pkgCacheFile &Cache,
										 const char **cmdline,
										 std::list<CacheSetHelper::PkgModifier> const &mods,
										 unsigned short const &fallback,
										 CacheSetHelper &helper) {
		std::map<unsigned short, PackageContainer> pkgsets;
		for (const char **I = cmdline; *I != 0; ++I) {
			unsigned short modID = fallback;
			PackageContainer pkgset;
			helper.PackageFromModifierCommandLine(modID, &pkgset, Cache, *I, mods);
			pkgsets[modID].insert(pkgset);
		}
		return pkgsets;
	}
	static std::map<unsigned short, PackageContainer> GroupedFromCommandLine(
										 pkgCacheFile &Cache,
										 const char **cmdline,
										 std::list<CacheSetHelper::PkgModifier> const &mods,
										 unsigned short const &fallback) {
		CacheSetHelper helper;
		return GroupedFromCommandLine(Cache, cmdline,
				mods, fallback, helper);
	}
									/*}}}*/
};									/*}}}*/
// various specialisations for PackageContainer				/*{{{*/
template<> template<class Cont> void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
		_cont.push_back(*p);
}
#if __cplusplus >= 201103L
template<> template<class Cont> void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
		_cont.push_front(*p);
}
#endif
template<> template<class Cont> void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
		_cont.push_back(*p);
}
template<> template<class Cont> void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(PackageContainer<Cont> const &pkgcont) {
	for (typename PackageContainer<Cont>::const_iterator p = pkgcont.begin(); p != pkgcont.end(); ++p)
		_cont.push_back(*p);
}
// these are 'inline' as otherwise the linker has problems with seeing these untemplated
// specializations again and again - but we need to see them, so that library users can use them
template<> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
	if (P.end() == true)
		return false;
	_cont.push_back(P);
	return true;
}
#if __cplusplus >= 201103L
template<> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
	if (P.end() == true)
		return false;
	_cont.push_front(P);
	return true;
}
#endif
template<> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
	if (P.end() == true)
		return false;
	_cont.push_back(P);
	return true;
}
template<> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(pkgCache::PkgIterator const &P) {
	if (P.end() == true)
		return false;
	_cont.push_back(P);
	return true;
}
template<> inline void PackageContainer<std::list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator p = begin; p != end; ++p)
		_cont.push_back(*p);
}
#if __cplusplus >= 201103L
template<> inline void PackageContainer<std::forward_list<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator p = begin; p != end; ++p)
		_cont.push_front(*p);
}
#endif
template<> inline void PackageContainer<std::deque<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator p = begin; p != end; ++p)
		_cont.push_back(*p);
}
template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator p = begin; p != end; ++p)
		_cont.push_back(*p);
}
#if APT_GCC_VERSION < 0x409
template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
	_cont.erase(i._iter);
	return end();
}
template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator first, iterator last) {
	_cont.erase(first, last);
	return end();
}
#endif
template<> template<class Compare> inline bool PackageContainer<std::vector<pkgCache::PkgIterator> >::sort(Compare Comp) {
	std::sort(_cont.begin(), _cont.end(), Comp);
	return true;
}
template<> template<class Compare> inline bool PackageContainer<std::list<pkgCache::PkgIterator> >::sort(Compare Comp) {
	_cont.sort(Comp);
	return true;
}
#if __cplusplus >= 201103L
template<> template<class Compare> inline bool PackageContainer<std::forward_list<pkgCache::PkgIterator> >::sort(Compare Comp) {
	_cont.sort(Comp);
	return true;
}
#endif
template<> template<class Compare> inline bool PackageContainer<std::deque<pkgCache::PkgIterator> >::sort(Compare Comp) {
	std::sort(_cont.begin(), _cont.end(), Comp);
	return true;
}
									/*}}}*/

// class PackageUniverse - pkgCache as PackageContainerInterface	/*{{{*/
/** \class PackageUniverse

    Wraps around our usual pkgCache, so that it can be stuffed into methods
    expecting a PackageContainer.

    The wrapping is read-only in practice modeled by making erase and co
    private methods. */
class APT_PUBLIC PackageUniverse : public PackageContainerInterface {
	pkgCache * const _cont;
	void * const d;
public:
	class const_iterator : public APT::Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>
	{
	public:
	   explicit const_iterator(pkgCache::PkgIterator i):
	      Container_iterator_base<APT::PackageContainerInterface, PackageUniverse, PackageUniverse::const_iterator, pkgCache::PkgIterator, pkgCache::PkgIterator>(i) {}

	   inline pkgCache::PkgIterator getType(void) const { return _iter; }
	};
	typedef const_iterator iterator;
	typedef pkgCache::PkgIterator value_type;
	typedef typename pkgCache::PkgIterator* pointer;
	typedef typename pkgCache::PkgIterator const* const_pointer;
	typedef const pkgCache::PkgIterator& const_reference;
	typedef const_reference reference;
	typedef const_iterator::difference_type difference_type;
	typedef std::make_unsigned<const_iterator::difference_type>::type size_type;


	bool empty() const APT_OVERRIDE { return false; }
	size_t size() const APT_OVERRIDE { return _cont->Head().PackageCount; }

	const_iterator begin() const { return const_iterator(_cont->PkgBegin()); }
	const_iterator end() const { return const_iterator(_cont->PkgEnd()); }
	const_iterator cbegin() const { return const_iterator(_cont->PkgBegin()); }
	const_iterator cend() const { return const_iterator(_cont->PkgEnd()); }
	iterator begin() { return iterator(_cont->PkgBegin()); }
	iterator end() { return iterator(_cont->PkgEnd()); }

	pkgCache * data() const { return _cont; }

	explicit PackageUniverse(pkgCache * const Owner);
	explicit PackageUniverse(pkgCacheFile * const Owner);
	virtual ~PackageUniverse();

private:
	APT_HIDDEN bool insert(pkgCache::PkgIterator const &) APT_OVERRIDE { return true; }
	template<class Cont> APT_HIDDEN void insert(PackageContainer<Cont> const &) { }
	APT_HIDDEN void insert(const_iterator, const_iterator) { }

	APT_HIDDEN void clear() APT_OVERRIDE { }
	APT_HIDDEN iterator erase( const_iterator pos );
	APT_HIDDEN iterator erase( const_iterator first, const_iterator last );
};
									/*}}}*/
typedef PackageContainer<std::set<pkgCache::PkgIterator> > PackageSet;
#if __cplusplus >= 201103L
typedef PackageContainer<std::unordered_set<pkgCache::PkgIterator> > PackageUnorderedSet;
typedef PackageContainer<std::forward_list<pkgCache::PkgIterator> > PackageForwardList;
#endif
typedef PackageContainer<std::list<pkgCache::PkgIterator> > PackageList;
typedef PackageContainer<std::deque<pkgCache::PkgIterator> > PackageDeque;
typedef PackageContainer<std::vector<pkgCache::PkgIterator> > PackageVector;

class VersionContainerInterface {					/*{{{*/
/** \class APT::VersionContainerInterface

    Same as APT::PackageContainerInterface, just for Versions */
public:
	/** \brief smell like a pkgCache::VerIterator */
	template<class Itr> class iterator_base {			/*{{{*/
	   pkgCache::VerIterator getType() const { return static_cast<Itr const*>(this)->getType(); };
	public:
		operator pkgCache::VerIterator(void) { return getType(); }

		inline pkgCache *Cache() const { return getType().Cache(); }
		inline unsigned long Index() const {return getType().Index();}
		inline int CompareVer(const pkgCache::VerIterator &B) const { return getType().CompareVer(B); }
		inline const char *VerStr() const { return getType().VerStr(); }
		inline const char *Section() const { return getType().Section(); }
		inline const char *Arch() const { return getType().Arch(); }
		inline pkgCache::PkgIterator ParentPkg() const { return getType().ParentPkg(); }
		inline pkgCache::DescIterator DescriptionList() const { return getType().DescriptionList(); }
		inline pkgCache::DescIterator TranslatedDescription() const { return getType().TranslatedDescription(); }
		inline pkgCache::DepIterator DependsList() const { return getType().DependsList(); }
		inline pkgCache::PrvIterator ProvidesList() const { return getType().ProvidesList(); }
		inline pkgCache::VerFileIterator FileList() const { return getType().FileList(); }
		inline bool Downloadable() const { return getType().Downloadable(); }
		inline const char *PriorityType() const { return getType().PriorityType(); }
		inline std::string RelStr() const { return getType().RelStr(); }
		inline bool Automatic() const { return getType().Automatic(); }
		inline pkgCache::VerFileIterator NewestFile() const { return getType().NewestFile(); }
		// we have only valid iterators here
		inline bool end() const { return false; }

		inline pkgCache::Version const * operator->() const { return &*getType(); }
	};
									/*}}}*/

	virtual bool insert(pkgCache::VerIterator const &V) = 0;
	virtual bool empty() const = 0;
	virtual void clear() = 0;
	virtual size_t size() const = 0;

	/** \brief specifies which version(s) will be returned if non is given */
	enum APT_DEPRECATED_MSG("enum moved to CacheSetHelper::VerSelector instead") Version {
		ALL = CacheSetHelper::ALL,
		CANDANDINST = CacheSetHelper::CANDANDINST,
		CANDIDATE = CacheSetHelper::CANDIDATE,
		INSTALLED = CacheSetHelper::INSTALLED,
		CANDINST = CacheSetHelper::CANDINST,
		INSTCAND = CacheSetHelper::INSTCAND,
		NEWEST = CacheSetHelper::NEWEST
	};

	struct Modifier {
		unsigned short const ID;
		const char * const Alias;
		enum Position { NONE, PREFIX, POSTFIX } const Pos;
		enum CacheSetHelper::VerSelector const SelectVersion;
		Modifier (unsigned short const &id, const char * const alias, Position const &pos,
			  enum CacheSetHelper::VerSelector const select) : ID(id), Alias(alias), Pos(pos),
			 SelectVersion(select) {}
APT_IGNORE_DEPRECATED_PUSH
		APT_DEPRECATED_MSG("Construct with a CacheSetHelper::VerSelector instead") Modifier(unsigned short const &id, const char * const alias, Position const &pos,
			  Version const &select) : ID(id), Alias(alias), Pos(pos),
			 SelectVersion((CacheSetHelper::VerSelector)select) {}
APT_IGNORE_DEPRECATED_POP
	};

	static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
				    const char **cmdline, CacheSetHelper::VerSelector const fallback,
				    CacheSetHelper &helper);
APT_IGNORE_DEPRECATED_PUSH
	APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromCommandLine(VersionContainerInterface * const vci, pkgCacheFile &Cache,
				    const char **cmdline, Version const &fallback,
				    CacheSetHelper &helper) {
	   return FromCommandLine(vci, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
	}
APT_IGNORE_DEPRECATED_POP

	static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
			       std::string pkg, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
			       bool const onlyFromName = false);
APT_IGNORE_DEPRECATED_PUSH
	APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromString(VersionContainerInterface * const vci, pkgCacheFile &Cache,
			       std::string pkg, Version const &fallback, CacheSetHelper &helper,
			       bool const onlyFromName = false) {
	   return FromString(vci, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper, onlyFromName);
	}
APT_IGNORE_DEPRECATED_POP

	static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
				pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback,
				CacheSetHelper &helper);
APT_IGNORE_DEPRECATED_PUSH
	APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromPackage(VersionContainerInterface * const vci, pkgCacheFile &Cache,
				pkgCache::PkgIterator const &P, Version const &fallback,
				CacheSetHelper &helper) {
	   return FromPackage(vci, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
	}
APT_IGNORE_DEPRECATED_POP

	static bool FromModifierCommandLine(unsigned short &modID,
					    VersionContainerInterface * const vci,
					    pkgCacheFile &Cache, const char * cmdline,
					    std::list<Modifier> const &mods,
					    CacheSetHelper &helper);


	static bool FromDependency(VersionContainerInterface * const vci,
				   pkgCacheFile &Cache,
				   pkgCache::DepIterator const &D,
				   CacheSetHelper::VerSelector const selector,
				   CacheSetHelper &helper);
APT_IGNORE_DEPRECATED_PUSH
	APT_DEPRECATED_MSG("Use CacheSetHelper::VerSelector as fallback selector") static bool FromDependency(VersionContainerInterface * const vci,
				   pkgCacheFile &Cache,
				   pkgCache::DepIterator const &D,
				   Version const &selector,
				   CacheSetHelper &helper) {
	   return FromDependency(vci, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
	}
APT_IGNORE_DEPRECATED_POP

	VersionContainerInterface();
	VersionContainerInterface& operator=(VersionContainerInterface const &other);
	virtual ~VersionContainerInterface();
private:
	void * const d;

protected:								/*{{{*/

	/** \brief returns the candidate version of the package

	    \param Cache to be used to query for information
	    \param Pkg we want the candidate version from this package
	    \param helper used in this container instance */
	static pkgCache::VerIterator getCandidateVer(pkgCacheFile &Cache,
		pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);

	/** \brief returns the installed version of the package

	    \param Cache to be used to query for information
	    \param Pkg we want the installed version from this package
	    \param helper used in this container instance */
	static pkgCache::VerIterator getInstalledVer(pkgCacheFile &Cache,
		pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper);
									/*}}}*/
};
									/*}}}*/
template<class Container> class VersionContainer : public VersionContainerInterface {/*{{{*/
/** \class APT::VersionContainer

    Simple wrapper around a container class like std::set to provide a similar
    interface to a set of versions as to the complete set of all versions in the
    pkgCache. */
	Container _cont;
public:									/*{{{*/

	typedef Container_const_iterator<VersionContainerInterface, Container, VersionContainer> const_iterator;
	typedef Container_iterator<VersionContainerInterface, Container, VersionContainer> iterator;
	typedef Container_const_reverse_iterator<VersionContainerInterface, Container, VersionContainer> const_reverse_iterator;
	typedef Container_reverse_iterator<VersionContainerInterface, Container, VersionContainer> reverse_iterator;
	typedef typename Container::value_type value_type;
	typedef typename Container::pointer pointer;
	typedef typename Container::const_pointer const_pointer;
	typedef typename Container::reference reference;
	typedef typename Container::const_reference const_reference;
	typedef typename Container::difference_type difference_type;
	typedef typename Container::size_type size_type;
	typedef typename Container::allocator_type allocator_type;

	bool insert(pkgCache::VerIterator const &V) APT_OVERRIDE { if (V.end() == true) return false; _cont.insert(V); return true; }
	template<class Cont> void insert(VersionContainer<Cont> const &vercont) { _cont.insert((typename Cont::const_iterator)vercont.begin(), (typename Cont::const_iterator)vercont.end()); }
	void insert(const_iterator begin, const_iterator end) { _cont.insert(begin, end); }
	bool empty() const APT_OVERRIDE { return _cont.empty(); }
	void clear() APT_OVERRIDE { return _cont.clear(); }
	size_t size() const APT_OVERRIDE { return _cont.size(); }
#if APT_GCC_VERSION >= 0x409
	iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
	iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
#else
	iterator erase( iterator pos ) { return iterator(_cont.erase(pos._iter)); }
	iterator erase( iterator first, iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
#endif
	const_iterator begin() const { return const_iterator(_cont.begin()); }
	const_iterator end() const { return const_iterator(_cont.end()); }
	const_reverse_iterator rbegin() const { return const_reverse_iterator(_cont.rbegin()); }
	const_reverse_iterator rend() const { return const_reverse_iterator(_cont.rend()); }
#if __cplusplus >= 201103L
	const_iterator cbegin() const { return const_iterator(_cont.cbegin()); }
	const_iterator cend() const { return const_iterator(_cont.cend()); }
	const_reverse_iterator crbegin() const { return const_reverse_iterator(_cont.crbegin()); }
	const_reverse_iterator crend() const { return const_reverse_iterator(_cont.crend()); }
#endif
	iterator begin() { return iterator(_cont.begin()); }
	iterator end() { return iterator(_cont.end()); }
	reverse_iterator rbegin() { return reverse_iterator(_cont.rbegin()); }
	reverse_iterator rend() { return reverse_iterator(_cont.rend()); }
	const_iterator find(pkgCache::VerIterator const &V) const { return const_iterator(_cont.find(V)); }

	VersionContainer() : VersionContainerInterface() {}
	template<typename Itr> VersionContainer(Itr first, Itr last) : VersionContainerInterface(), _cont(first, last) {}
#if __cplusplus >= 201103L
	VersionContainer(std::initializer_list<value_type> list) : VersionContainerInterface(), _cont(list) {}
	void push_back(value_type&& P) { _cont.emplace_back(std::move(P)); }
	template<typename... Args> void emplace_back(Args&&... args) { _cont.emplace_back(std::forward<Args>(args)...); }
#endif
	void push_back(const value_type& P) { _cont.push_back(P); }

	/** \brief sort all included versions with given comparer

	    Some containers are sorted by default, some are not and can't be,
	    but a few like std::vector can be sorted if need be, so this can be
	    specialized in later on. The default is that this will fail though.
	    Specifically, already sorted containers like std::set will return
	    false as well as there is no easy way to check that the given comparer
	    would sort in the same way the set is currently sorted

	    \return \b true if the set was sorted, \b false if not. */
	template<class Compare> bool sort(Compare /*Comp*/) { return false; }

	/** \brief returns all versions specified on the commandline

	    Get all versions from the commandline, uses given default version if
	    non specifically requested  and executes regex's if needed on names.
	    \param Cache the packages and versions are in
	    \param cmdline Command line the versions should be extracted from
	    \param fallback version specification
	    \param helper responsible for error and message handling */
	static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
			CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
		VersionContainer vercon;
		VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, fallback, helper);
		return vercon;
	}
	static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
			CacheSetHelper::VerSelector const fallback) {
		CacheSetHelper helper;
		return FromCommandLine(Cache, cmdline, fallback, helper);
	}
	static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline) {
		return FromCommandLine(Cache, cmdline, CacheSetHelper::CANDINST);
	}
	static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
			CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper,
                                           bool const /*onlyFromName = false*/) {
		VersionContainer vercon;
		VersionContainerInterface::FromString(&vercon, Cache, pkg, fallback, helper);
		return vercon;
	}
	static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
			CacheSetHelper::VerSelector const fallback) {
		CacheSetHelper helper;
		return FromString(Cache, pkg, fallback, helper);
	}
	static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg) {
		return FromString(Cache, pkg, CacheSetHelper::CANDINST);
	}
APT_IGNORE_DEPRECATED_PUSH
	static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
			Version const &fallback, CacheSetHelper &helper) {
		VersionContainer vercon;
		VersionContainerInterface::FromCommandLine(&vercon, Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
		return vercon;
	}
	static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline,
			Version const &fallback) {
		CacheSetHelper helper;
		return FromCommandLine(Cache, cmdline, (CacheSetHelper::VerSelector)fallback, helper);
	}
	static VersionContainer FromString(pkgCacheFile &Cache, std::string const &pkg,
			Version const &fallback, CacheSetHelper &helper,
                                           bool const /*onlyFromName = false*/) {
		VersionContainer vercon;
		VersionContainerInterface::FromString(&vercon, Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
		return vercon;
	}
	static VersionContainer FromString(pkgCacheFile &Cache, std::string pkg,
			Version const &fallback) {
		CacheSetHelper helper;
		return FromString(Cache, pkg, (CacheSetHelper::VerSelector)fallback, helper);
	}
APT_IGNORE_DEPRECATED_POP

	/** \brief returns all versions specified for the package

	    \param Cache the package and versions are in
	    \param P the package in question
	    \param fallback the version(s) you want to get
	    \param helper the helper used for display and error handling */
	static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
		CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper) {
		VersionContainer vercon;
		VersionContainerInterface::FromPackage(&vercon, Cache, P, fallback, helper);
		return vercon;
	}
	static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
					    CacheSetHelper::VerSelector const fallback) {
		CacheSetHelper helper;
		return FromPackage(Cache, P, fallback, helper);
	}
APT_IGNORE_DEPRECATED_PUSH
	static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
		Version const &fallback, CacheSetHelper &helper) {
		VersionContainer vercon;
		VersionContainerInterface::FromPackage(&vercon, Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
		return vercon;
	}
	static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P,
					    Version const &fallback) {
		CacheSetHelper helper;
		return FromPackage(Cache, P, (CacheSetHelper::VerSelector)fallback, helper);
	}
APT_IGNORE_DEPRECATED_POP
	static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P) {
		return FromPackage(Cache, P, CacheSetHelper::CANDIDATE);
	}

	static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
										 pkgCacheFile &Cache,
										 const char **cmdline,
										 std::list<Modifier> const &mods,
										 unsigned short const fallback,
										 CacheSetHelper &helper) {
		std::map<unsigned short, VersionContainer> versets;
		for (const char **I = cmdline; *I != 0; ++I) {
			unsigned short modID = fallback;
			VersionContainer verset;
			VersionContainerInterface::FromModifierCommandLine(modID, &verset, Cache, *I, mods, helper);
			versets[modID].insert(verset);
		}
		return versets;

	}
	static std::map<unsigned short, VersionContainer> GroupedFromCommandLine(
		pkgCacheFile &Cache, const char **cmdline,
		std::list<Modifier> const &mods,
		unsigned short const fallback) {
		CacheSetHelper helper;
		return GroupedFromCommandLine(Cache, cmdline,
				mods, fallback, helper);
	}

	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
					       CacheSetHelper::VerSelector const selector, CacheSetHelper &helper) {
		VersionContainer vercon;
		VersionContainerInterface::FromDependency(&vercon, Cache, D, selector, helper);
		return vercon;
	}
	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
					       CacheSetHelper::VerSelector const selector) {
		CacheSetHelper helper;
		return FromDependency(Cache, D, selector, helper);
	}
APT_IGNORE_DEPRECATED_PUSH
	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
					       Version const &selector, CacheSetHelper &helper) {
		VersionContainer vercon;
		VersionContainerInterface::FromDependency(&vercon, Cache, D, (CacheSetHelper::VerSelector)selector, helper);
		return vercon;
	}
	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D,
					       Version const &selector) {
		CacheSetHelper helper;
		return FromDependency(Cache, D, (CacheSetHelper::VerSelector)selector, helper);
	}
APT_IGNORE_DEPRECATED_POP
	static VersionContainer FromDependency(pkgCacheFile &Cache, pkgCache::DepIterator const &D) {
		return FromDependency(Cache, D, CacheSetHelper::CANDIDATE);
	}
									/*}}}*/
};									/*}}}*/
// various specialisations for VersionContainer				/*{{{*/
template<> template<class Cont> void VersionContainer<std::list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
		_cont.push_back(*v);
}
#if __cplusplus >= 201103L
template<> template<class Cont> void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
		_cont.push_front(*v);
}
#endif
template<> template<class Cont> void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
		_cont.push_back(*v);
}
template<> template<class Cont> void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(VersionContainer<Cont> const &vercont) {
	for (typename VersionContainer<Cont>::const_iterator v = vercont.begin(); v != vercont.end(); ++v)
		_cont.push_back(*v);
}
// these are 'inline' as otherwise the linker has problems with seeing these untemplated
// specializations again and again - but we need to see them, so that library users can use them
template<> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
	if (V.end() == true)
		return false;
	_cont.push_back(V);
	return true;
}
#if __cplusplus >= 201103L
template<> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
	if (V.end() == true)
		return false;
	_cont.push_front(V);
	return true;
}
#endif
template<> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
	if (V.end() == true)
		return false;
	_cont.push_back(V);
	return true;
}
template<> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::insert(pkgCache::VerIterator const &V) {
	if (V.end() == true)
		return false;
	_cont.push_back(V);
	return true;
}
template<> inline void VersionContainer<std::list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator v = begin; v != end; ++v)
		_cont.push_back(*v);
}
#if __cplusplus >= 201103L
template<> inline void VersionContainer<std::forward_list<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator v = begin; v != end; ++v)
		_cont.push_front(*v);
}
#endif
template<> inline void VersionContainer<std::deque<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator v = begin; v != end; ++v)
		_cont.push_back(*v);
}
template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::insert(const_iterator begin, const_iterator end) {
	for (const_iterator v = begin; v != end; ++v)
		_cont.push_back(*v);
}
#if APT_GCC_VERSION < 0x409
template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
	_cont.erase(i._iter);
	return end();
}
template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator first, iterator last) {
	_cont.erase(first, last);
	return end();
}
#endif
template<> template<class Compare> inline bool VersionContainer<std::vector<pkgCache::VerIterator> >::sort(Compare Comp) {
	std::sort(_cont.begin(), _cont.end(), Comp);
	return true;
}
template<> template<class Compare> inline bool VersionContainer<std::list<pkgCache::VerIterator> >::sort(Compare Comp) {
	_cont.sort(Comp);
	return true;
}
#if __cplusplus >= 201103L
template<> template<class Compare> inline bool VersionContainer<std::forward_list<pkgCache::VerIterator> >::sort(Compare Comp) {
	_cont.sort(Comp);
	return true;
}
#endif
template<> template<class Compare> inline bool VersionContainer<std::deque<pkgCache::VerIterator> >::sort(Compare Comp) {
	std::sort(_cont.begin(), _cont.end(), Comp);
	return true;
}
									/*}}}*/

typedef VersionContainer<std::set<pkgCache::VerIterator> > VersionSet;
#if __cplusplus >= 201103L
typedef VersionContainer<std::unordered_set<pkgCache::VerIterator> > VersionUnorderedSet;
typedef VersionContainer<std::forward_list<pkgCache::VerIterator> > VersionForwardList;
#endif
typedef VersionContainer<std::list<pkgCache::VerIterator> > VersionList;
typedef VersionContainer<std::deque<pkgCache::VerIterator> > VersionDeque;
typedef VersionContainer<std::vector<pkgCache::VerIterator> > VersionVector;
}
#endif