If you want a value type bitset that is also possible, but then you need to define the range of possibilities before using.
I distilled the below code from earlier posts on this forum:
program bigvalueset;
{$mode objfpc}{$modeswitch advancedrecords}
type
generic TBigValueSet<T> = record
private
const
LOWER = Low(T);
UPPER = High(T) - LOWER;
SET_LEN = (Upper shr 5 + Ord(Upper and 31 <> 0)) + Ord(UPPER = 0);
type
TDWordBits = 0..31;
TDWordSet = set of TDWordBits;
PDWordSet = ^TDWordSet;
TSet = array[0..Pred(SET_LEN)] of DWord;
var
FSet: TSet;
class operator Initialize(var s: TBigValueSet);
public
procedure Include(aValue: T);
procedure Exclude(aValue: T);
class operator +(constref L, R: TBigValueSet): TBigValueSet;
class operator -(constref L, R: TBigValueSet): TBigValueSet;
class operator *(constref L, R: TBigValueSet): TBigValueSet;
class operator ><(constref L, R: TBigValueSet): TBigValueSet;
class operator =(constref L, R: TBigValueSet): Boolean;
class operator <=(constref L, R: TBigValueSet): Boolean;
class operator in (aValue: T; const aSet: TBigValueSet): Boolean;
end;
class operator TBigValueSet.Initialize(var s: TBigValueSet);
begin
s.FSet := Default(TSet);
end;
procedure TBigValueSet.Include(aValue: T);
begin
System.Include(PDWordSet(@FSet[(Integer(aValue) - LOWER) shr 5])^, (Integer(aValue) - LOWER) and 31);
end;
procedure TBigValueSet.Exclude(aValue: T);
begin
System.Exclude(PDWordSet(@FSet[(Integer(aValue) - LOWER) shr 5])^, (Integer(aValue) - LOWER) and 31);
end;
class operator TBigValueSet.+(constref L, R: TBigValueSet): TBigValueSet;
var
I: Integer;
begin
for I := 0 to Pred(SET_LEN) do
Result.FSet[I] := L.FSet[I] or R.FSet[I];
end;
class operator TBigValueSet.-(constref L, R: TBigValueSet): TBigValueSet;
var
I: Integer;
begin
for I := 0 to Pred(SET_LEN) do
Result.FSet[I] := L.FSet[I] and not R.FSet[I];
end;
class operator TBigValueSet.*(constref L, R: TBigValueSet): TBigValueSet;
var
I: Integer;
begin
for I := 0 to Pred(SET_LEN) do
Result.FSet[I] := L.FSet[I] and R.FSet[I];
end;
class operator TBigValueSet.><(constref L, R: TBigValueSet): TBigValueSet;
var
I: Integer;
begin
for I := 0 to Pred(SET_LEN) do
Result.FSet[I] := L.FSet[I] xor R.FSet[I];
end;
class operator TBigValueSet.=(constref L, R: TBigValueSet): Boolean; inline;
var
I: Integer;
begin
for I := 0 to Pred(SET_LEN) do
if L.FSet[I] <> R.FSet[I] then
exit(False);
Result := True;
end;
class operator TBigValueSet.<=(constref L, R: TBigValueSet): Boolean; inline;
var
I: Integer;
begin
for I := 0 to Pred(SET_LEN) do
if R.FSet[I] <> L.FSet[I] or R.FSet[I] then
exit(False);
Result := True;
end;
class operator TBigValueSet.in (aValue: T; const aSet: TBigValueSet): Boolean;
begin
Result := TDWordBits((Integer(aValue) - LOWER) and 31) in PDWordSet(@aSet.FSet[(Integer(aValue) - LOWER) shr 5])^;
end;
type
TMyRange = -1022..1023;
var
s, s2: specialize TBigValueSet<TMyRange>;
begin
WriteLn('SizeOf(s) = ', SizeOf(s));
s.Include(-5);
WriteLn('-5 in s = ', -5 in s);
s.Include(1022);
WriteLn('1022 in s = ', 1022 in s);
s2.Include(-15);
s2.Include(-900);
s2 := s2 + s;
WriteLn('-5 in s2 = ', -5 in s2);
WriteLn('-15 in s2 = ', -15 in s2);
WriteLn('-900 in s2 = ', -900 in s2);
WriteLn('1022 in s2 = ', 1022 in s2);
s2 := s2 - s2;
WriteLn('-5 in s2 = ', -5 in s2);
WriteLn('-15 in s2 = ', -15 in s2);
WriteLn('-900 in s2 = ', -900 in s2);
WriteLn('1022 in s2 = ', 1022 in s2);
end.