Lazarus

Free Pascal => General => Topic started by: dgaspary on October 12, 2014, 01:12:23 am

Title: TFPGMap (new?) bug(?)
Post by: dgaspary on October 12, 2014, 01:12:23 am
Hi,

I was trying to compile the following code
Code: [Select]
uses
    classes, fgl;

type
  TMyMap = specialize TFPGMap <TObject, TObject>; 

But I got the following messages:

Code: [Select]
Error: Operator is not overloaded: "TObject" < "TObject"
Error: Operator is not overloaded: "TObject" > "TObject"

I found a 2011 thread[1] about the issue, but it seems a mantis issue was not registered.

It's really a bug? Should I open an issue on the bug tracker?

Thank you.

Update: I am using FPC Trunk(rev 28799).

[1] http://free-pascal-general.1045716.n5.nabble.com/fgl-TFPGMap-td3350031.html

Title: Re: TFPGMap (new?) bug(?)
Post by: engkin on October 12, 2014, 04:48:24 am
It's really a bug? Should I open an issue on the bug tracker?
I don't think so, because based on the source code (http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/objpas/fgl.pp?view=markup) relative operators were used in KeyCompare:
Code: [Select]
function TFPGMap.KeyCompare(Key1, Key2: Pointer): Integer;
begin
  if PKey(Key1)^ < PKey(Key2)^ then
    Result := -1
  else if PKey(Key1)^ > PKey(Key2)^ then
    Result := 1
  else
    Result := 0;
end;
and PKey(Key1)^ < PKey(Key2)^ , for instance, is meaningless in the general case when dealing with TObject.

I suggest that you copy TFPGMap and replace KeyCompare with something else more specialized with your objects, similarly to what was mentioned here (http://bugs.freepascal.org/view.php?id=15480#c50594).
Title: Re: TFPGMap (new?) bug(?)
Post by: dgaspary on October 12, 2014, 05:10:18 am
I suggest that you copy TFPGMap and replace KeyCompare with something else more specialized with your objects

The KeyCompare was the reason I decided to ask instead of directly creating an issue.

Replacing  it is not an option? (Although I  don't know how could be done.)

This way would avoid future problems. It is weird to have a generic class that is incompatible with a large portion of  the language.

Quote
similarly to what was mentioned here (http://bugs.freepascal.org/view.php?id=15480#c50594).

The source cited in the commentary was moved somewhere else, I believe.
Title: Re: TFPGMap (new?) bug(?)
Post by: Leledumbo on October 12, 2014, 05:41:21 am
Replacing  it is not an option? (Although I  don't know how could be done.)
Overloading it for your object might work, but as far as I remember this isn't yet possible under objfpc mode. Under Delphi mode, using operator overloading inside classes, someone has ever posted an example here.
Title: Re: TFPGMap (new?) bug(?)
Post by: engkin on October 12, 2014, 06:05:19 am
The source cited in the commentary was moved somewhere else, I believe.
Here you go (http://sourceforge.net/p/castle-engine/code/HEAD/tree/trunk/castle_game_engine/src/base/castlegenericlists.pas)!
TinyPortal © 2005-2018