System.Set
C++
class RTL_DELPHIRETURN Set : public SetBase<T, (unsigned char)minEl, (unsigned char)maxEl>
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
class | public | sysset.h | System | System |
Description
Set is a C++ template for emulating the set types found in Delphi.
A set type is declared with three parameters:
Parameter | Usage |
---|---|
T
|
The type of the elements (usually int, char, or an enum type). |
minEl
|
The minimum value the set can hold (this value cannot be less than 0.) |
maxEl
|
The maximum value the set can hold (this value cannot be greater than 255.) |
Two set types are distinct if any of the three template parameters are different:
Set <char, 'A', 'C'> s1;
Set <char, 'X', 'Z'> s2;
...
if (s1 == s2) // ERROR: == not implemented for second set type
To create multiple instances of a Set type, use a typedef expression.
typedef Set <char, 'A','Z'> UPPERCASESet;
The declaration of a Set variable does not initialize the variable. You can declare the set types and initialize them by using the <<
operator, as shown in this example:
UPPERCASESet s1;
s1 << 'A' << 'B' << 'C'; // Initialize
UPPERCASESet s2;
s2 << 'X' << 'Y' << 'Z'; // Initialize
Note: To utilize the C++ streaming operators (
<<
and>>
) with Set types, you must include theiostream
library before thesysset
. This occurs automatically if you include vcl.h or System.hpp. The following stream operators are defined:
template <class T, unsigned char minEl, unsigned char maxEl> ostream&
operator <<(ostream& os, const Set<T, minEl, maxEl> & arg);
template <class T, unsigned char minEl, unsigned char maxEl> istream&
operator >>(istream& is, Set<T, minEl, maxEl> & arg)