GPC supports Standard Pascal set operations. In addition it supports
the Extended Pascal set operation symmetric difference
(set1 >< set2) operation whose result consists of those
elements which are in exactly one of the operannds.
It also has a function that counts the elements in the set: a := Card (set1).
In the following description, S1 and S2 are variables of set type, s is of the base type of the set.
S1 := S2S1 + S2S1 - S2S1 * S2S1 >< S2S1 = S2True if
S1 has the same elements as S2.
S1 <> S2True if
S1 does not have the same elements as S2.
S1 < S2S2 > S1True if
S1 is a strict subset of S2.
S1 <= S2S2 >= S1True if
S1 is a subset of (or equal to) S2.
s in S1s and a set. Returns
boolean result. True if s is an element of S1.
The following example demonstrates some set operations. The results
of the operations are given in the comments.
program SetOpDemo;
type
TCharSet = set of Char;
var
S1, S2, S3: TCharSet;
Result: Boolean;
begin
S1 := ['a', 'b', 'c'];
S2 := ['c', 'd', 'e'];
S3 := S1 + S2; { S3 = ['a', 'b', 'c', 'd', 'e'] }
S3 := S1 * S2; { S3 = ['c'] }
S3 := S1 - S2; { S3 = ['a', 'b'] }
S3 := S1 >< S2; { S3 = ['a', 'b', 'd', 'e'] }
S1 := ['c', 'd', 'e'];
Result := S1 = S2; { False }
Result := S1 < S2; { False }
Result := S1 <= S2; { True }
S1 := ['c', 'd'];
Result := S1 <> S2; { True }
Result := S2 > S1; { True }
Result := S2 >= S1 { True }
end.