[fpc-pascal] List of integers? Any class available in RTL or FCL to help?

Sven Barth pascaldragon at googlemail.com
Sun Dec 4 18:39:33 CET 2016


Am 04.12.2016 11:25 schrieb "Graeme Geldenhuys" <
mailinglists at geldenhuys.co.uk>:
> > Then you should have a look at TFPGList, even if you do not like
> > generics. TFPGList is our approach to extend FPC carefully with
generics.
>
> At the moment I'm using FPC 2.6.4 for the work I'm doing. I can't yet
> move to FPC 3.0.0.

Unit fgl is a part of FPC since around 2.2 or so and only for records you'd
need 2.6.4 as an = operator overload is required (and no, a global one
wouldn't be sufficient with generics). Thus regarding the compiler version
it would be perfectly safe to use it.

> My worry about Generics is the following statement in the fgl.pp unit:
>
> "
> { be aware, this unit is a prototype and subject to be changed heavily }
> "
>
> So that tells me this is not to be used in production software as it is
> more like an experiment than anything else.

I think we can throw out that statement. As said the unit is already part
of FPC for a long time and up until some time in the 2.6 series I think the
only generic containers provided by the RTL (then fcl-stl was added). 3.1
also contains the Delphi compatible and more versatile Generics.Collections
unit.
So even if in the future the latter would become the main one, the fgl unit
will at least stay as we don't like to break code without good reason and
it's also more lightweight (though it has its restrictions like the need
for an = operator when specializing TFPGList).

> ps:
>   Is it recommended to always define a specialised type? I guess it
>   makes the code more clear when read by a human. Or is it perfectly
>   acceptable doing:
>
>   var
>     lst: specialize TFPGList<Int8>;
>   begin
>     ...
>   end;

This will only really work in 3.1.1 as I solved some problems there. Other
than that, yes, it's completely fine. Delphi code mainly uses that approach
though you can of course explicitly declare your types like in mode ObjFPC
as well. The only exception to this are generic functions and methods,
those always must be specialized inline.

I'd suggest you to at least play around with generics a bit as they're
definitely here to stay and with them now working better than in 2.6 not to
mention 2.4 they definitely make quite some coding easier.

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


More information about the fpc-pascal mailing list