[fpc-pascal] Constants in generics
Ryan Joseph
ryan at thealchemistguild.com
Thu Jan 3 02:29:16 CET 2019
> On Jan 2, 2019, at 5:52 PM, Alexander Shishkin via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
> Thanks, now I`ve lost is a discussion again. What is the decision about syntax? Is "const" prefix and/or ": type" suffix required?
const is required but the type is not.
Here’s a test for all the const types supported.
program gc_types;
uses
sysutils;
type
generic TMyRecord_Int<T, const U:integer> = record
end;
type
generic TMyRecord_Byte<T, const U:byte> = record
end;
type
generic TMyRecord_String<T, const U:string> = record
end;
type
generic TMyRecord_Float<T, const U:single> = record
end;
type
TDay = (Mon, Tue, Wed);
TDays = set of TDay;
generic TMyRecord_Set<T, const U:TDays> = record
end;
type
generic TMyRecord_Nil<T, const U:pointer> = record
end;
type
generic TMyRecord_Undefined<T, const U> = record
end;
var
a: specialize TMyRecord_Int<integer,10>;
b: specialize TMyRecord_String<integer,'foo'>;
c: specialize TMyRecord_Float<integer,0.1>;
d: specialize TMyRecord_Set<integer,[Mon, Wed]>;
e: specialize TMyRecord_Nil<integer,nil>;
f: specialize TMyRecord_Byte<integer,kByte>;
g: specialize TMyRecord_Undefined<integer,[1,2,3]>;
begin
end.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list