[fpc-devel] Templates / Generics Syntax

Marc Weustink marc.weustink at cuperus.nl
Fri Nov 4 14:07:50 CET 2005


Ales Katona wrote:
> Micha Nelissen wrote:
> 
>> Marc Weustink wrote:
>>
>>> BTW,
>>> what woud be the problem with
>>>
>>> type
>>>   TMySpecificClass = TGenericClass(TObject, Integer);
>>
>>
>>
>> Or:
>>
>> <code>
>> type
>>   TGenericCollection = generic(T: TCollectionItem) class(TComponent)
>>   ...implement TCollection and use T
>>   end;
>>
>>   TCollection = TGenericCollection of (TCollectionItem);
>>   TFieldDefs = TGenericCollection of (TFieldDef);
>> </code>
>>
>> And:
>>
>> <code>
>> type
>>   TGenericList = generic(T: PtrInt) class(TObject)
>>   ...implement TList and use PtrInt size for code generation
>>   end;
>>
>>   TList = TGenericList of (Pointer);
>> </code>
>>
>> Combining some of the wiki ideas, and has no "evil" <> characters :-). 
>> Probably TFieldDefs adds functionality to TCollection, but it was 
>> first example I came up with.
>>
>> Implementation of TGenericCollection can be compiled as if (T: 
>> TCollectionItem) were used.
>>
>> Would this solve the circular dependency ? It seems so to me, because 
>> one knows at least as much as in current implementation of these 
>> classes, but I'm no compiler engineer.
>>
>> Micha
>>
> Are the () required? Why not TSomeList = TGenericList of Pointer; ?

You can have more types
<code>
type
   TList = TGenericList of (Pointer, Pointer);
</code>

Marc



More information about the fpc-devel mailing list