It appears the below code can distinguish between the 2 TFoo (generic vs constant).

But if the constraint to the generic is an "const integer" then how to you specialize it?
The 2 commented lines give errors.
   project1.lpr(16,14) Error: Identifier not found "TBar"

Originally I had a "var TBar: integer" too, but then it was
   project1.lpr(16,16) Error: Illegal expression


program Project1; {$Mode delphi}
type
  TBar<const A: integer> = class   end;
  TFoo<A> = class   end;
var
  TFoo: integer;
  x: pointer;

begin
  x := Pointer( TFoo<1> false );  // (TFoo < 1) > False
  x := Pointer( TFoo<byte> .Create );

  //x := TBar<1> .Create ;
  //x := Pointer( TBar<1> .Create );
end.

    ================================
Also got issues with

program Project1; {$Mode delphi}
uses Unit1;
type    TFoo<A> = class   end;
var
  TFoo: integer;
  x: pointer;
begin
  x := Pointer( TFoo<1> false );  // variable TFoo
  x := Pointer( TFoo< TObject);  // variable TFoo

//but trying to continue the bool exression with another compare
  x := Pointer( TFoo< TObject > False); // ERROR
end.


unit Unit1; {$mode ObjFPC}{$H+} interface
   type   TClass = class of TObject;
   operator <(a: integer; b: TClass): boolean;
implementation
operator<(a: integer; b: TClass): boolean;  begin result:=true;  end;
end.

_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to