Sign in Join

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

Mailing lists / fpc-devel / 2022-05

constant evaluation in generics params

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Martin Frb

In the below code specialization takes a boolean constant. The compiler (kind of) allows expressions that can be evaluated at compile time.

Of course
    specialize TGen<  5>1  >;
does not work. The ">" can't be distinguished from the end of the param list.

Not sure why
    specialize TGen<  5=1  >;
does not work.
It does work though, if the expression is in brackets.

And talking about brackets
    specialize TGen<  (5>1)  >;
does not, but could work. while in () the ">" can't be the end of the param list.

program Project1;
{$mode objfpc}{$H+}
type
   generic TGen<const CC: boolean> = class end;
   TBar1 = specialize TGen<true>;
   TBar2 = specialize TGen<(1=1)>;
   TBar3 = specialize TGen<1=1>; // err
   TBar4 = specialize TGen<(1>1)>; // err
   TBar5 = specialize TGen<(1<1)>; // err

Reply by email