[fpc-pascal] Array of const and generics

Sven Barth pascaldragon at googlemail.com
Thu Mar 2 11:45:52 CET 2017


Am 02.03.2017 10:42 schrieb "Ryan Joseph" <ryan at thealchemistguild.com>:
>
> Is it possible to use array of const inside of generics?
>
>
> Quick example I just typed up. If you specialize the generic the compiler
always complains about the type in array of const not being the specialized
type. Type casting doesn’t work either because you may have specialized for
incompatible types like classes and strings. It would be nice to say:
TIntegerCollection.Create([1, 3, 4, 8, 10]) as a way to init the instance.

"array of const" itself should work without problems though mixing the type
parameters and the values contained in the array might be problematic (I'd
need to test it myself).
However for your specific example case why don't you use "array of T" as a
parameter type for the constructor. It would work the same, but would be
even more type safe and in the spirit of generics.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170302/3372f11a/attachment.html>


More information about the fpc-pascal mailing list