[fpc-pascal] Constants in generics
ryan at thealchemistguild.com
Tue Nov 6 14:34:59 CET 2018
> On Nov 6, 2018, at 8:21 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 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.
Can you give an example? There’s lots of ways generics can be used and I tested in only a few.
This is a very important improvement because it allows us to extend static arrays in ways we haven’t been able to do before. Unless I missed something huge it seems like a simple thing to implement (see the minor changes I made in a single unit).
> 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.
Why is this preferable? If you tried to pass a type for a constant in a specialization then you’d probably just get a type error which is easy to catch. Generics in FPC are already very verbose (“specialize" keyword is exhaustingly long) but adding “const” is at least a small cosmetic change in a single location.
More information about the fpc-pascal