소스 검색

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 년 전
부모
커밋
4ea89d01ea
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. 24 0
      rtl/objpas/objpas.pp

+ 24 - 0
rtl/objpas/objpas.pp

@@ -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 ) }