Просмотр исходного кода

* Patch from Thaddy De Koning to add generic RandomFrom

git-svn-id: trunk@36706 -
michael 8 лет назад
Родитель
Сommit
162b938409
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      rtl/objpas/math.pp

+ 11 - 0
rtl/objpas/math.pp

@@ -613,8 +613,12 @@ function CompareValue ( const A, B : Extended; delta : Extended = 0.0 ) : TValue
 function RandomFrom(const AValues: array of Double): Double; overload;
 function RandomFrom(const AValues: array of Integer): Integer; overload;
 function RandomFrom(const AValues: array of Int64): Int64; overload;
+{$if FPC_FULLVERSION >=301010}
+generic function RandomFrom<T>(const AValues:array of T):T;
+{$endif}
 
 { cpu specific stuff }
+
 type
   TFPURoundingMode = system.TFPURoundingMode;
   TFPUPrecisionMode = system.TFPUPrecisionMode;
@@ -2600,6 +2604,13 @@ begin
   result:=AValues[random(High(AValues)+1)];
 end;
 
+{$if FPC_FULLVERSION >=301010}
+generic function RandomFrom<T>(const AValues:array of T):T;
+begin
+  result:=AValues[random(High(AValues)+1)];
+end;
+{$endif}
+
 function FutureValue(ARate: Float; NPeriods: Integer;
   APayment, APresentValue: Float; APaymentTime: TPaymentTime): Float;
 var