Somewhat a fix for Mantis #25025 : added generic variants of the TEnumerable/TEnumerator interfaces. Added to unit ObjPas, because mode ObjFPC does not allow overloading of types with generics (which would be the case in unit System). Also the two interfaces are not completely Delphi compatible on purpose! In Delphi they inherit from corresponding non generic interfaces, but this leads in FPC as well as in Delphi to problems.

rtl/objpas/objpas.pp:
  + add generic interfaces IEnumerator<T> and IEnumerable<T> which are equivalent to TEnumerator and TEnumerable

git-svn-id: trunk@25498 -
This commit is contained in:
svenbarth 2013-09-16 10:15:19 +00:00
parent 0d8ad2a932
commit 4ea89d01ea

View File

@ -48,6 +48,30 @@ unit objpas;
PPointerArray = ^PointerArray;
TBoundArray = array of integer;
{$if FPC_FULLVERSION >= 20701}
{ Generic support for enumerator interfaces. These are added here, because
mode (Obj)FPC does currently not allow the overloading of types with
generic types (this will need a modeswitch...) }
{ Note: In Delphi these two generic types inherit from the two interfaces
above, but in FPC as well as in Delphi(!) this leads to problems,
because of method hiding and method implementation. E.g.
consider a class which enumerates integers one needs to implement
a GetCurrent for TObject as well... }
generic IEnumerator<T> = interface
function GetCurrent: T;
function MoveNext: Boolean;
procedure Reset;
property Current: T read GetCurrent;
end;
generic IEnumerable<T> = interface
function GetEnumerator: specialize IEnumerator<T>;
end;
{$endif}
{$ifdef FPC_HAS_FEATURE_CLASSES}
Var
ExceptionClass: TClass; { Exception base class (must actually be Exception, defined in sysutils ) }