[fpc-pascal] Constants in generics
    Martin 
    fpc at mfriebe.de
       
    Wed Nov  7 12:51:47 CET 2018
    
    
  
On 06/11/2018 08:13, Ryan Joseph wrote:
> I implemented a first draft of constants (integers) in generics. My reason was specifically that I wanted a way to add methods to static arrays and generic records is the only way to accomplish this AFAIK.
>
> If I fix this up will it be considered as a patch? I wanted to present the idea first before I spent any more time. Here’s what I has so far (on GitHub).
>
Just for info, there already is a way to do this, though being able to 
do it direct would be nice. You can wrap any constants into an object 
(or advanced record).
program Project1;
{$mode objfpc}{$H+}
uses  Classes;
type
   generic Foo<A> = object
     class procedure test;
   end;
   Data = object
     const val = 1;
   end;
var
   bar: specialize Foo<data>;
class procedure Foo.test;
begin
   writeln(A.val);
end;
begin
   bar.test;
   readln;
end.
    
    
More information about the fpc-pascal
mailing list