Forum > General

TFPGMap (new?) bug(?)

(1/1)

dgaspary:
Hi,

I was trying to compile the following code

--- Code: ---uses
    classes, fgl;

type
  TMyMap = specialize TFPGMap <TObject, TObject>; 

--- End code ---

But I got the following messages:


--- Code: ---Error: Operator is not overloaded: "TObject" < "TObject"
Error: Operator is not overloaded: "TObject" > "TObject"
--- End code ---

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

engkin:

--- Quote from: dgaspary on October 12, 2014, 01:12:23 am ---It's really a bug? Should I open an issue on the bug tracker?

--- End quote ---
I don't think so, because based on the source code relative operators were used in KeyCompare:

--- Code: ---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;

--- End code ---
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.

dgaspary:

--- Quote from: engkin on October 12, 2014, 04:48:24 am ---I suggest that you copy TFPGMap and replace KeyCompare with something else more specialized with your objects

--- End quote ---

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.
--- End quote ---

The source cited in the commentary was moved somewhere else, I believe.

Leledumbo:

--- Quote from: dgaspary on October 12, 2014, 05:10:18 am ---Replacing  it is not an option? (Although I  don't know how could be done.)

--- End quote ---
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.

engkin:

--- Quote from: dgaspary on October 12, 2014, 05:10:18 am ---The source cited in the commentary was moved somewhere else, I believe.

--- End quote ---
Here you go!

Navigation

[0] Message Index

Go to full version