[fpc-devel] Templates / Generics

Marc Weustink marc.weustink at cuperus.nl
Fri Nov 4 10:22:14 CET 2005


Peter Vreman wrote:
>>Mattias Gaertner wrote:
>>
>>
>>>This page looks only like the start of a proposal. Neither complete nor
>>>official.
>>>Why do you think, that D2006 will have generics?
>>>
>>>
>>>
>>
>>D2006 <> D11=D2007
> 
> 
> How will Delphi handle the following case with overloads and different types:

If it is handled as a kind of macro, then it is no problem. The type of 
data is known at compile time.
If the generic is "pre"compiled (which is maybe necesary if you need 
access to privates) then I fear some runtime logic has to be added to 
call the correct procedure. IE. something like

   case TypeInfo(Data) of
     StringType: Show(Data);
     IntegerType: Show(Data);
   end;

Marc





> 
> unit test;
> 
> interface
> 
> type
>   List<T> = class
>     data : T;
>     constructor(aData: T);
>     procedure dump;
>   end;
> 
> implementation
> 
> procedure show(i:integer);overload;
> begin
> end;
> 
> procedure show(s:string);overload;
> begin
> end;
> 
> constructor List<T>(aData: T);
> begin
>   Data := aData;
> end;
> 
> procedure List<T>.Dump;
> begin
>   Show(Data);
> end;
> 
> end.
> 
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 




More information about the fpc-devel mailing list