Old thread, but anyway:
Since I got a bit bored with this discussion at the time, I did a write up how it actually works. Alas it is not possible - without using records - to have all operators for any size of ordinal, I will explain how it actually works, so you will be able to use "sets" on any ordinal:
SET operations in Pascal are typically represented as a "set of bits in a byte" and can be used to perform various mathematical operations.
A standard Pascal set has a maximum range of 0..255. And that is supported by build in operants.
Here I have written up an explanation of how sets are actually implemented at the low level.
There are four operations that form the core and I have tried to explain those below.
All other set operations can be derived from those four.
So, although set notation is restricted to byte, when you really understand how they work you can apply it to word, dword and qword.
Just by using boolean logic you can create your own sets. But not with operators..
But since their simple nature the generated code is inherently very fast.
Set Union (OR), notation +
The set union operation is used to combine the elements of two sets into one set. This operation is implemented in Pascal by using the OR operator.
For example:
SetA = [1, 2, 3]
SetB = [4, 5, 6]
SetC = SetA OR SetB
This would result in SetC = [1, 2, 3, 4, 5, 6]
With standard set notation it is done like this: SetC:=SetA+SetB
Set Intersection (AND), notation *
The set intersection operation is used to find the elements that are common within two sets. This operation is implemented in Pascal by using the AND operator.
For example:
SetA = [1, 2, 3]
SetB = [2, 3, 4]
SetC = SetA AND SetB
This would result in SetC = [2, 3]
With standard set notation it is done like this: SetC:=SetA*SetB
Set Difference (NOT), notation -
The set difference operation is used to find the elements that are in the first set but not in the second set. This operation is implemented in Pascal by using the NOT operator.
For example:
SetA = [1, 2, 3]
SetB = [2, 3, 4]
SetC = SetA NOT SetB or actually SetA and (SetA xor SetB)
This would result in SetC = [1]
With standard set notation it is done like this: SetC:=SetA-SetB
Set Symmetric Difference (XOR), notation ><
The set symmetric difference operation is used to find the elements that are either in the first set but not in the second set, or in the second set but not in the first set. This operation is implemented in Pascal by using the XOR operator.
For example:
SetA = [1, 2, 3]
SetB = [2, 3, 4]
SetC = SetA XOR SetB
This would result in SetC = [1, 4]
With standard set notation it is done like this: SetC:=SetA><SetB
In Boolean logic, each operation is represented by the following equations:
Set Union: SetC = SetA OR SetB, notation +
Set Intersection: SetC = SetA AND SetB, notation *
Set Difference: SetC = SetA NOT SetB, notation -
Set Symmetric Difference: SetC = SetA XOR SetB, notation ><
As I wrote, all other set operations can be derived from the above.
Hope this helps, it is not rocket science.
And NO, apart from in, you can't create full sets of operator overloads, otherwise I would have done so.