Consider the following comparison function:
bool compare(std::shared_ptr<myObject> &lhs, std::shared_ptr<myObject> &rhs){ return lhs->value < rhs->value; }
Now the idea is to initialize a multiset of type std::shared_ptr<myObject> , which arranges the elements with the above function. Therefore, from the book that I read, it should be done as follows:
std::multiset<std::shared_ptr<myObject>, decltype(compare)*> myset{compare};
Question:
My question is that in the declaration I understand that the function pointer is passed to refer to the comparison function, but why do we initialize the wtih {compare} set ?? What is its significance and why should it be done like this?
Jason source share