I am switching my design to use smart pointers and I've encountered a problem with std::priority_que
I had a method that inserts new task into queue and signalizes if new task landed at the top of it:
bool foo(SchedulerTask* task)
{
eventList_.push(task);
return task == eventList_.top();
}
After wrapping SchedulerTask into unique_ptr I met problem with checking its priority in container. After moving the object into queue I was not able to use it again for compare. I have end up with caching comparator member and comparing it with the top object:
bool foo(std::unique_ptr<SchedulerTask> task)
{
const auto prio = task->getCycle(); // my priority_queue compares objects by getCycle() value
eventList_.push(std::move(task));
return prio >= eventList_.top()->getCycle();;
}
Can it be done better way?