Hello,
I'm trying to port C++ code containing this local variable declaration:
std::multimap<std::pair<double, int>, int, event_less> events;
where event_less is a comprarer class:
class event_less
{
public:
bool operator()(const std::pair<double, int>& a, const std::pair<double, int>& b) const
{
if (a.first < b.first - 1.0e-9)
return true;
else if (a.first > b.first + 1.0e-9)
return false;
else if (a.second < b.second)
return true;
return false;
}
};
In Delphi, I declared this:
var
Events : IMultiMap<TPair<Double, Integer>, Integer>;
KeyComparer : IEqualityComparer<TPair<Double, Integer>>;
begin
KeyComparer := TEqualityComparerInteger.Create;
Events := TMultiMap<TPair<Double, Integer>, Integer>.Create(KeyComparer);
// More code
end;
and this:
TEqualityComparerInteger = class(TInterfacedObject, IEqualityComparer<TPair<Double, Integer>>)
function Equals(const Left, Right: TPair<Double, Integer>): Boolean; reintroduce;
function GetHashCode(const Value: TPair<Double, Integer>): Integer; reintroduce;
end;
function TEqualityComparerInteger.Equals(const Left, Right: TPair<Double, Integer>): Boolean;
begin
if Left.Key < (Right.Key - 1E-9) then
Result := TRUE
else if Left.Key > (Right.Key + 1E-9) then
Result := FALSE
else if Left.Value < Right.Value then
Result := TRUE
else
Result := FALSE;
end;
function TEqualityComparerInteger.GetHashCode(const Value: TPair<Double, Integer>): Integer;
begin
Result := Value.Value + Round(Value.Key * 1E6);
end;
I get a compiler error on the line calling TMultiMap constructor:
[dcc32 Error] TestCode.pas(113): E2250 There is no overloaded version of 'Create' that can be called with these arguments
I don't understand what I'm doing wrong.