* * *

Author Topic: RTL-Generics supports generic lists of records, but FGL doesn't?  (Read 727 times)

SlightlyOutOfPhase

  • New member
  • *
  • Posts: 8
Why is this?

For example

Code: Pascal  [Select]
  1. TTestRec = record
  2.   TestString: String;
  3. end;
  4.  
  5. TTestRecList = specialize TFPGList<TTestRec>;

would fail to compile, and complain about how the equality operator isn't overloaded. However

Code: Pascal  [Select]
  1. TTestRec = record
  2.   TestString: String;
  3. end;
  4.  
  5. TTestRecList = specialize TList<TTestRec>;

works fine. If FGL is supposed to be the "flagship" generics library for FPC, shouldn't it have all the features RTL-Generics does?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5640
Re: RTL-Generics supports generic lists of records, but FGL doesn't?
« Reply #1 on: March 26, 2017, 11:18:20 am »
Just use rtl-generics. fgl is more something designed when the generics support was still new, it's designed around generics limitations of that time and while fixes were applied it was never conceptually updated after.

As usual, the main benefit is that it is small and on RTL level and can be used for utils that can't use packages.

Even fcl-stl is slightly better.

Akira1364

  • Sr. Member
  • ****
  • Posts: 293
Re: RTL-Generics supports generic lists of records, but FGL doesn't?
« Reply #2 on: March 27, 2017, 01:53:51 am »
If I recall correctly this is specifically related to the way the list classes in FGL implement the IndexOf function... by which I mean, they use the actual = operator to compare list items. If for whatever reason you're absolutely dead set on using FGL, you could modify your copy of FGL.pp to use something like CompareByte instead of = in those functions, and it would then be able to create lists of any type. However, in my opinion that wouldn't really be worth it at all, and as Marco said you should really just use RTL-Generics. Not only does it have a lot more features than FGL, but it's also significantly more performant.
« Last Edit: April 02, 2017, 02:46:07 am by Akira1364 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus