[fpc-pascal] Generic specialization using $mode objfpc

silvioprog silvioprog at gmail.com
Thu Nov 13 16:02:22 CET 2014


On Tue, Nov 11, 2014 at 7:25 PM, Sven Barth <pascaldragon at googlemail.com>
wrote:

> On 11.11.2014 22:48, silvioprog wrote:
>
>> Oh, sorry. Just:
>>
>> unit Core.Singleton;
>>
>> {$mode objfpc}{$H+}
>>
>> interface
>>
>> type
>>
>>    { TSingleton }
>>
>>    generic TSingleton<T: class> = class(TObject)
>>    public
>>      class function GetInstance: T;
>>    end;
>>
>> implementation
>>
>> { TSingleton }
>>
>> class function TSingleton.GetInstance: T;
>> begin
>> end;
>>
>> end.
>>
>> And compiled like a charm. =)
>>
>
> Yes, since the ObjFPC dialect was developed without type overloading in
> mind (in Delphi (and FPC's mode Delphi) you can have TSingleton<T> and
> TSingleton<T, S> in the same unit) it was decided that it is not necessary
> to add the <T> at the definiton of the method as well.


Awesome. =)

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141113/d5a79f28/attachment.html>


More information about the fpc-pascal mailing list