Skip to content

Set of Enum in generic

Summary

I have a function and this function only specializes with enum types and I do not want to make a set for each. The normal way of declaring new set type (S3 in the sample) is not working. @martin_frb kindly suggested the S2 way at the forum.

System Information

Lazarus 3.99 (rev ca9f504a0d) FPC 3.3.1 x86_64-win64-win32/win64

Example Project

program Project1;

  {$mode delphi}

type
  TEnum = (A, B, C);

  procedure Test<T>(E: T);
  type
    S1 = set of TEnum;
    S2 = set of Low(T)..High(T);
    S3 = set of T; //Error
  begin
  end;

begin
  Test<TEnum>(B);
  ReadLn;
end.          

What is the expected (correct) behavior?

I think the S3 way need to be compiled too.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information