AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Template for numbers only

Ein Thema von WojTec · begonnen am 5. Feb 2015 · letzter Beitrag vom 5. Feb 2015
 
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Template for numbers only

  Alt 5. Feb 2015, 12:19
Delphi-Version: XE6
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;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:26 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz