On Tue, Jul 16, 2019 at 8:35 AM Michael Van Canneyt <mich...@freepascal.org>
wrote:

> 2. The Low(T) does not work, as there is no way to tell Delphi that T must
> be an enum.
>

Hmm, I guess it makes sense Delphi wouldn't allow the "Low", based on other
Delphi generics behavior (more like C#, whereas FPC is more like C++.)

I only realized recently that you can't even actually use "arithmetic"
operators on Delphi generics at all, E.G, the following is valid FPC code,
but not valid Delphi code:

program Example;

{$mode Delphi}

type
  TComparer<T> = record
  public
    class function Min(const A, B: T): T; static; inline;
    class function Max(const A, B: T): T; static; inline;
  end;

  class function TComparer<T>.Min(const A, B: T): T;
  begin
    if A < B then
      Result := A
    else
      Result := B;
  end;

  class function TComparer<T>.Max(const A, B: T): T;
  begin
    if A > B then
      Result := A
    else
      Result := B;
  end;

begin
  WriteLn(TComparer<Single>.Min(2.0, 4.0));
  WriteLn(TComparer<Single>.Max(2.0, 4.0));
end.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to