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

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to