<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Am Di., 6. Nov. 2018, 08:44 hat Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> geschrieben:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I implemented a first draft of constants (integers) in generics. My reason was specifically that I wanted a way to add methods to static arrays and generic records is the only way to accomplish this AFAIK.<br>
<br>
If I fix this up will it be considered as a patch? I wanted to present the idea first before I spent any more time. Here’s what I has so far (on GitHub).<br>
<br>
<a href="https://github.com/genericptr/freepascal/commit/ec518542b2da7d7f016702a82b2d05349a01a6fb" rel="noreferrer noreferrer" target="_blank">https://github.com/genericptr/freepascal/commit/ec518542b2da7d7f016702a82b2d05349a01a6fb</a><br>
<br>
{$mode objfpc}<br>
{$modeswitch advancedrecords}<br>
<br>
program generic_constants;<br>
<br>
type<br>
        generic TList<T, U> = record<br>
                list: array[0..U-1] of T;<br>
                function capacity: integer;<br>
        end;<br>
<br>
function TList.capacity: integer;<br>
begin<br>
        result := U;    <br>
end;    <br>
<br>
var<br>
        nums: specialize TList<integer,10>;<br>
        strs: specialize TList<integer,4>;<br>
begin<br>
        writeln('sizeof:',sizeof(nums), ' capacity:',nums.capacity);<br>
        writeln('sizeof:',sizeof(strs), ' capacity:',strs.capacity);<br>
end.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">First of I'm not a fan of adding support for constants, mainly because it will definitely not help parsing of inline specializations in mode Delphi which are going to be annoying enough already. </div><div dir="auto">That said: even if we do add it, then only if a generic constant parameter is designated as such with "const N" in the generic declaration instead of merely "N", so that the compiler does not assume it's a type. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>