I want to sort my objects according to some criteria (according to how big the items are) My funcSort in multiset slows down calculations and makes the solution does not scale. How can I make it faster? To avoid it I tried to use vector, sort it (should go quicker?) and change it into multiset. My solution however does not work, I am not sure what I do wrong?
Function arguments:
void deliver(const std::set<MyItem::Ptr> items, MyItem::Ptr item)
(Typedef of shared_ptr):
typedef boost::shared_ptr<MyItem> Ptr;
sort function:
auto funcSort = [item](MyItem::Ptr lhs, MyItem::Ptr rhs){
return lhs->howFar(item->howBig()) < rhs->howFar(item->howBig());
};
Original with multiset (SLOW when using funcSort):
std::multiset<MyItem::Ptr, decltype(funcSort)> sortedItems(funcSort);
for (MyItem::Ptr item : items){
sortedItems.insert(item);
}
My vector attempt (Error message):
std::vector<MyItem::Ptr> sortedItems;
for (MyItem::Ptr item : items)
{
sortedItems.push_back(item);
}
std::sort(sortedItems.begin(), sortedItems.end(), funcSort());
std::multiset<MyItem::Ptr> ms(sortedItems.begin(), sortedItems.end());
Error message:
__lambda1
auto funcSort = [item](MyItem::Ptr lhs, MyItem::Ptr rhs)
candidate expects 2 arguments, 0 provided