Browse Source

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 -
svenbarth 12 years ago
parent
commit
4ea89d01ea
1 changed files with 24 additions and 0 deletions
  1. 24 0
      rtl/objpas/objpas.pp

+ 24 - 0
rtl/objpas/objpas.pp

@@ -48,6 +48,30 @@ unit objpas;
        PPointerArray = ^PointerArray;
        PPointerArray = ^PointerArray;
        TBoundArray = array of integer;
        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}
 {$ifdef FPC_HAS_FEATURE_CLASSES}
 Var
 Var
    ExceptionClass: TClass; { Exception base class (must actually be Exception, defined in sysutils ) }
    ExceptionClass: TClass; { Exception base class (must actually be Exception, defined in sysutils ) }