<div dir="ltr"><div dir="ltr">On Tue, Jul 16, 2019 at 8:35 AM Michael Van Canneyt <<a href="mailto:michael@freepascal.org">michael@freepascal.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
2. The Low(T) does not work, as there is no way to tell Delphi that T must<br>
be an enum.<br></blockquote><div><br></div><div>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++.)</div><div><br></div><div>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:</div><div><br></div><div>program Example;<br><br>{$mode Delphi}<br><br>type<br> TComparer<T> = record<br> public<br> class function Min(const A, B: T): T; static; inline;<br> class function Max(const A, B: T): T; static; inline;<br> end;<br> <br> class function TComparer<T>.Min(const A, B: T): T;<br> begin<br> if A < B then<br> Result := A<br> else<br> Result := B;<br> end;<br> <br> class function TComparer<T>.Max(const A, B: T): T;<br> begin<br> if A > B then<br> Result := A<br> else<br> Result := B;<br> end;<br><br>begin<br> WriteLn(TComparer<Single>.Min(2.0, 4.0));<br> WriteLn(TComparer<Single>.Max(2.0, 4.0));<br>end.<br></div></div></div>