Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2022-05

Element type of set at compile time

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hairy Pixels

Is there a compiler intrinsic to get the element type of a set at compile time? So if you have “set of T” it should return T.

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Hairy Pixels
Hairy Pixels wrote
Is there a compiler intrinsic to get the element type of a set at compile time? So if you have “set of T” it should return T.

I don't think you can make such an intrinsic.
This type does not always exist, since you can define

Type
   TMySet = set of (one,two,three);

The element type does not exist as a separate type.

Michael.

Reply by email

Hairy Pixels
to Michael Van Canneyt
Show quoted text 6 lines
On May 15, 2022, at 2:03 PM, Michael Van Canneyt via fpc-pascal wrote: Type TMySet = set of (one,two,three); The element type does not exist as a separate type.

I mean if you had code like this T would be the anonymous enum (one,two,three). Maybe element is not the correct term here but the type which is the enum in the set.

var
  I: ElementType(TMySet);
begin
  for i := low(TMySet) to high(TMySet) do
    ;

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Michael Van Canneyt: I don't think you can make such an intrinsic. This type does not always exist, since you…

On Sun, 15 May 2022 09:03:58 +0200 (CEST)
Michael Van Canneyt via fpc-pascal

Show quoted text 12 lines
On Sun, 15 May 2022, Hairy Pixels via fpc-pascal wrote: > Is there a compiler intrinsic to get the element type of a set at > compile time? So if you have “set of T” it should return T. I don't think you can make such an intrinsic. This type does not always exist, since you can define Type TMySet = set of (one,two,three); The element type does not exist as a separate type.

The RTTI supports it, so it always exists.

Mattias

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 14 lines
On 15/05/2022 15:07, Hairy Pixels via fpc-pascal wrote: > var > I: ElementType(TMySet); > begin > for i := low(TMySet) to high(TMySet) do > ; > type   TMySet = set of (one,two,three); var   I: low(TMySet) .. high(TMySet) ; begin   for i := low(TMySet) to high(TMySet) do     ;
type
   TMySet=set of (one,two,three);
var
   I:low(TMySet)..high(TMySet);
begin
   for i:=low(TMySet) to high(TMySet) do
    writeln(i);
end.

prints indeed

one
two
three

Michael.

Reply by email