Recent

Author Topic: TFPGMap (new?) bug(?)  (Read 3618 times)

dgaspary

  • Jr. Member
  • **
  • Posts: 55
TFPGMap (new?) bug(?)
« 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

« Last Edit: October 12, 2014, 01:29:20 am by dgaspary »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: TFPGMap (new?) bug(?)
« Reply #1 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 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.

dgaspary

  • Jr. Member
  • **
  • Posts: 55
Re: TFPGMap (new?) bug(?)
« Reply #2 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.

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

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TFPGMap (new?) bug(?)
« Reply #3 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.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: TFPGMap (new?) bug(?)
« Reply #4 on: October 12, 2014, 06:05:19 am »
The source cited in the commentary was moved somewhere else, I believe.
Here you go!