[fpc-pascal] Array of const and generics
ryan at thealchemistguild.com
Thu Mar 2 10:05:25 CET 2017
Is it possible to use array of const inside of generics?
Quick example I just typed up. If you specialize the generic the compiler always complains about the type in array of const not being the specialized type. Type casting doesn’t work either because you may have specialized for incompatible types like classes and strings. It would be nice to say: TIntegerCollection.Create([1, 3, 4, 8, 10]) as a way to init the instance.
generic TCollection<T> = class (TObject)
constructor Create (args: array of const);
procedure Add (a: T);
TIntegerCollection = specialize TCollection<Integer>;
constructor TCollection.Create (args: array of const);
// ERROR: args is not the type we specialized for. can’t typecast either.
if args.vtype = vtinteger then
procedure TCollection.Add (a: T);
More information about the fpc-pascal