Recent

Author Topic: [SOLVED] FGL versus rtl-generics aka Generic.Collections  (Read 1620 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1353
  • Professional amateur ;-P
[SOLVED] FGL versus rtl-generics aka Generic.Collections
« on: August 02, 2025, 03:58:11 am »
Hey Y'all,

I've been dipping my feet into the usage of generics and due to the fact that bot of the above mentioned options exist out of the box, I never quite got to ask:
  • Are there any specific reasons to use one or the other?
  • What are the pros and cons of using one or the other?

I'm sorry to be asking such a newb set of questions!! It's been in my todo list to get these answers for quite a while. And I guess I'll admit I'm lazy to dive into the code to find it for myself.

With that in mind, and my apologies for being such a generics newb, I ask the community at large to give me a good answer. As I'm, shamefully yes, lazy to do a deep dive into then code, and for that I deeply apologise !!

If this has been already discussed in a previous post, I would deeply appreciate a link to it, or them, if more than one exists.

Cheers,
Gus
« Last Edit: August 03, 2025, 03:30:31 pm by Gustavo 'Gus' Carreno »

Thaddy

  • Hero Member
  • *****
  • Posts: 19438
  • Glad to be alive.
Re: FGL versus rtl-generics aka Generic.Collections
« Reply #1 on: August 02, 2025, 05:36:07 am »
pro's
- fgl is lightweight but still contains most of the common patterns.
- rtl-generics is Delphi compatible and has more patterns.
con's
- fgl is not Delphi compatible
- rtl-generics is heavy in code.

I use them both, and also lgenerics.
Any "programmer" that knows only one programming language is not a programmer

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12950
  • FPC developer.
Re: FGL versus rtl-generics aka Generic.Collections
« Reply #2 on: August 02, 2025, 12:37:10 pm »
fcl-stl is an attempt to build for the pre delphi compatible generics. Those are a bit less declarative, so in theory you should be able to do things with value types with fcl-stl and fgl that you can't do with rtl-generics, most notably call identifiers on the generic type in the unspecialized generic. I tried this sometimes, but it is hard to use and sensitive.

So I always use rtl-generics which IS generics.collections. In older Lazarus versions there was a copy of rtl-generics in lazarus to suit FPC 3.0 and 3.0.2, but that should not be necessary after FPC 3.2.0, maybe even 3.0.4

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1353
  • Professional amateur ;-P
Re: [SOLVED] FGL versus rtl-generics aka Generic.Collections
« Reply #3 on: August 03, 2025, 03:31:25 pm »
Hey Thaddy and Marco,

Thank you very much for your answers!! That did scratch my itch quite good!!

Cheers,
Gus

 

TinyPortal © 2005-2018