Multiset of pair, find

646 views Asked by At

I need to find and erase a value in mutliset of pair sorted by my own function. Apparently, .find always returns the iterator to the end, not to the searched value. Any tips? This is the function :

struct cmp
{
  bool operator() (const para &a, const para &b)
  {
    if (a.first > b.first) return false;
    if (b.first > a.first) return true;

    if (a.second < b.second) return false;
    else return true;
  }
};

Edit:

kolej.insert(para(0,2));
if (kolej.find(para(0,2)) == kolej.end()) printf("Jej");

Even if I do something like that, where para is pair<int,int> and kolej is multiset, it will always proceed to print "Jej"

1

There are 1 answers

0
Anton Savin On BEST ANSWER

Your comparator will evaluate to true for equal objects. You should change

if (a.second < b.second) return false;
else return true;

to

return b.second > a.second;