How to use comparison function with more than two arguments with priority C ++ queue?

I have an object class that stores a database record. There is also a comparison class that can take two of these records and an additional object that describes the order execution process. I need to use these two priority queue classes to combine records. From what I can say, I can only give a comparison function that takes 2 arguments in priority_queue. What is the best way to use this 3D priority queue comparator?

    priority_queue <Record, vector<Record>, Comparison(RecordA, RecordB, SortOrderObject)> pq;
+3
source share
2 answers

, , boost::bind, std::bind, , . ​​:

class my_compare {
  SortOrder so;
  public:
  my_compare(const SortOrder& so): so(so) {}
  bool operator()(const Record& a, const Record& b) const {
    return comparison(a, b, so);
  }
};

my_compare priority_queue my_compare(sort_order) .

+6

- , SortOrderObject .

+1

Source: https://habr.com/ru/post/1796713/


All Articles