A lot of Generics' implementations
Original Reporter info from Mantis: Basil Peace
-
Reporter name: Basil Peace
Original Reporter info from Mantis: Basil Peace
- Reporter name: Basil Peace
Description:
Current implementations of Generics seems unfinished.
Some (but not all) erroneous cases:
- Forward generic class/interface declaration
- Generic class implements generic interface
And, also, use of generics has no delights and convenience without the following features:
- Constraints for generics' template placeholders
- Function Default for generics template placeholders
Such features exists in Delphi. To my mind, Delphi's implementation isn't fully excellent, since there is also some potential for mistakes.
Steps to reproduce:
unit ForwardGenericsDeclarations;
interface
type
{$IFDEF FPC}generic{$ENDIF} ITestInterface<T> = interface;
{$IFDEF FPC}generic{$ENDIF} TTestClass<T> = class;
{$IFDEF FPC}generic{$ENDIF} ITestInterface<T> = interface
function Test: {$IFDEF FPC}{specialize}{$ENDIF} TTestClass<T>;
end;
{$IFDEF FPC}generic{$ENDIF} TTestClass<T> = class
function Test: {$IFDEF FPC}specialize{$ENDIF} TTestClass<T>;
end;
implementation
function TTestClass{$IFNDEF FPC}<T>{$ENDIF}.Test: TTestClass<T>;
begin
Result := Self;
end;
end.
unit GenericsInterfacesImplementationInheritance;
interface
type
{$IFDEF FPC}generic{$ENDIF} ITestInterface<T> = interface
procedure Test(const A: T);
end;
{$IFDEF FPC}generic{$ENDIF} TTestClass<T1, T2> = class(TInterfacedObject, {$IFDEF FPC}{specialize}{$ENDIF} ITestInterface<T1>)
procedure Test(const A: T1); overload;
end;
{$IFDEF FPC}generic{$ENDIF} TTestClass2<T1, T2> = class(TTestClass<T1, T2>, {$IFDEF FPC}specialize{$ENDIF} ITestInterface<T2>)
procedure Test(const A: T2); overload;
end;
implementation
procedure TTestClass{$IFNDEF FPC}<T1, T2>{$ENDIF}.Test (const A: T1);
begin
end;
procedure TTestClass2{$IFNDEF FPC}<T1, T2>{$ENDIF}.Test (const A: T2);
begin
end;
end.
Additional information:
I've written some tests for Default and constaints. If you need them, I can send them you.
Mantis conversion info:
- Mantis ID: 19491
- Version: 2.4.3
- Monitored by: » Basil Peace (Basil Peace), » kyan (Constantine Yannakopoulos)