[fpc-devel] Templates / Generics
peter at freepascal.org
Mon Nov 7 12:54:23 CET 2005
>> - instantiation will be only possible in declaration blocks, not in code
>> mylist : TList<integer>;
>> mylist : TList<integer> = nil;
>> mylist = TList<integer>;
>> procedure p(mylist : TList<integer>);
> This seems like a smart and sufficient solution to avoid the problem of
> parsing < tokens in code blocks.
> On the other hand, programmers will like it (a lot) more if they don't
> need to separately define a type for every generic instantiation. Is the
> token-lookahead approach proposed elsewhere in this thread not a
> sufficient solution? If it is not very easy, or if we are quite unsure
> about this for now, perhaps we can postpone the implementation of
> in-code(block) generic instantiation to a later time and first implement
> generics as above.
The token-lookahead is a hack and will create more problems and
performance loss in a critical part of the compiler.
The restriction of type blocks only is not strange at all, Delphi allows
'class of' is also only in type blocks
More information about the fpc-devel