Am Di., 6. Nov. 2018, 08:44 hat Ryan Joseph <r...@thealchemistguild.com> geschrieben:
> 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. > > 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). > > > https://github.com/genericptr/freepascal/commit/ec518542b2da7d7f016702a82b2d05349a01a6fb > > {$mode objfpc} > {$modeswitch advancedrecords} > > program generic_constants; > > type > generic TList<T, U> = record > list: array[0..U-1] of T; > function capacity: integer; > end; > > function TList.capacity: integer; > begin > result := U; > end; > > var > nums: specialize TList<integer,10>; > strs: specialize TList<integer,4>; > begin > writeln('sizeof:',sizeof(nums), ' capacity:',nums.capacity); > writeln('sizeof:',sizeof(strs), ' capacity:',strs.capacity); > end. > 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. 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. Regards, Sven >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal