[fpc-pascal] Generics vs templates
pascaldragon at googlemail.com
Wed Jan 10 07:51:28 CET 2018
Am 10.01.2018 05:10 schrieb "Ryan Joseph" <ryan at thealchemistguild.com>:
> On Jan 10, 2018, at 6:37 AM, Graeme Geldenhuys <
mailinglists at geldenhuys.co.uk> wrote:
> When using the Generics.Collections unit of Delphi I can define a list
class that can hold Integer data types, by doing the following:
> IntList: TList<Integer>;
> IntList := TList<Integer>.Create;
I presume then TList<> and TList class are not implemented the same then
because I still don’t know how the generic itself affects runtime
Btw this looks like C# code because C# explicitly does not specialize at
compile time but rather runtime so every instance will be using
TList<Integer>. Does Delphi do this also? I think FPC requires you MUST
specialize at compile time so simply using TList<Integer> won’t compile.
That are two orthogonal points. FPC and Delphi both allow inline
specializations which is what you see above (in the non-Delphi modes of
course with the "specialize" keyword). That doesn't change that such
specializations are done at compile time. For the compiler it is as if the
type "TList<Integer>" exists as a full type wherever it is used.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal