Create a set containing each member

Is there a way to create at compile time (or with a constant runtime) a set with members of an ordinal type Tcontaining each named value T?

In other words, how can I complement an empty set of a specific type?

type 
  TEnum = 
  ( 
    eA = 1,
    eB = 5,
    eC = 34 
  );
  TSet = set of TEnum;

const
  CSet: TSet = ~[]; // with ~ being my fictional set complement operator

It CSetshould then contain only named values eA, eBand eC.

Of course, this is not a practical question, I'm just wondering


EDIT

I was not aware of the behavior of enum types when declaring with explicit, non-sequential values. The listing still contains unnamed members to fill in the blanks. Updated question to apply only to named members

+4
source share
1

, ,

type 
  TEnum = 
  ( 
    eA,
    eB,
    eC 
  );
  TSet = set of TEnum;

const
  CSet: TSet = [eA..eC];
  CSet: TSet = [low(TEnum)..high(TEnum)];

TEnum,

type 
  TEnum = 
  ( 
    eA = 1,
    eB = 5,
    eC = 34 
  );

, . CSet ( 1 34).

TEnum, , - CSet: TSet = [eA, eB, eC];

,

+10

Source: https://habr.com/ru/post/1615644/


All Articles