I have function:
Delphi-Quellcode:
function SimilarValue(const AValue: Float32; AValues: array of Float32; out AResult: Float32): Int32;
var
I: Int32;
Distance: Float80;
SmallestDistance: Float80;
begin
Result := -1;
AResult := 0;
SmallestDistance := 16777216;
for I := Low(AValues) to High(AValues) do
begin
Distance := Sqr(AValue - AValues[I]);
if Distance < SmallestDistance then
begin
Result := I;
AResult := AValues[I];
SmallestDistance := Distance
end;
end;
end;
I want to make it working for any numeric type, but won't to overloading. Is it possible to do it with templates?
Delphi-Quellcode:
type
TSimilarValue<T> = class
class function Get(const AValue: T; AValues: array of T; out AResult: T): Int32;
end;
class function TSimilarValue<T>.Get(const AValue: T; AValues: array of T; out AResult: T): Int32;