Consider following comparison function:
bool compare(std::shared_ptr<myObject> &lhs, std::shared_ptr<myObject> &rhs){
return lhs->value < rhs->value;
}
Now idea is to initialize a multiset of type std::shared_ptr<myObject>
which orders elements with above function. So from book i read it should be done like this:
std::multiset<std::shared_ptr<myObject>, decltype(compare)*> myset{compare};
QUESTION:
My question is, in the declaration i understand a function pointer is passed to refer to compare function, but why are we initializing the set with {compare}
? What is its importance and why is it necessary to do so like this??