Top: Basic types: cset

- ##### Constructors

- ##### Operators

- ##### Manipulation

The character set class (cset) implements Pascal-style set of integer values from 0 to 255, or set of characters. Unlike Pascal sets, the range of a cset cannot be changed and is always 0 through 255. Cset class implements various operators (membership, union, intersection, equality, less than or equal to, etc.) as they are described in the Pascal language. See Operators for details.

Cset is a packed array of 256 bits, it occupies 32 bytes of static or local memory. Each bit indicates whether the corresponding character is a member of a given set.

Another difference between cset and Pascal sets is that since C++ compiler does not have a built-in set constructor like the one in Pascal (e.g. ['A'..'Z', 'a'..'z']), cset provides a simple run-time interpreter instead (see Constructors).

The cset class is declared in <ptypes.h>.

The example below shows the general usage of character sets.

>     cset s = "A-Za-z!";       // same as ['A'..'Z', 'a'..'z', '!'] in Pascal

>     include(s, '_');          // include underscore character
>     include(s, '0', '9');     // include all chars from '0' to '9'

>     if ('a' & s)              // check membership
>         cout << "Letter 'a' found in the set! :)\n";

>     const cset letters = "A-Za-z_";     // define a set of letters
>     string tok = pin.token(letters);    // read a token from the input stream

See also: Constructors, Operators, Manipulation

PTypes home