Переглянути джерело

* Patch from Thaddy De Koning to add generic RandomFrom

git-svn-id: trunk@36706 -
michael 8 роки тому
батько
коміт
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 Double): Double; overload;
 function RandomFrom(const AValues: array of Integer): Integer; overload;
 function RandomFrom(const AValues: array of Integer): Integer; overload;
 function RandomFrom(const AValues: array of Int64): Int64; 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 }
 { cpu specific stuff }
+
 type
 type
   TFPURoundingMode = system.TFPURoundingMode;
   TFPURoundingMode = system.TFPURoundingMode;
   TFPUPrecisionMode = system.TFPUPrecisionMode;
   TFPUPrecisionMode = system.TFPUPrecisionMode;
@@ -2600,6 +2604,13 @@ begin
   result:=AValues[random(High(AValues)+1)];
   result:=AValues[random(High(AValues)+1)];
 end;
 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;
 function FutureValue(ARate: Float; NPeriods: Integer;
   APayment, APresentValue: Float; APaymentTime: TPaymentTime): Float;
   APayment, APresentValue: Float; APaymentTime: TPaymentTime): Float;
 var
 var