Здравствуйте, MarcoPolo, Вы писали:
MP>Нельзя просто так взять и priority_queue of unique_ptr ...
MP>Подскажите, как такое "идиоматически выдержанно " делать в C++ 14?
На Stackoverflow в принципе ответили, на ваш вопрос. Еще можно снять константность со ссылки результата `queue::top()`. Это должно быть безопасно, если не планируется менять ключ объекта по которому упорядочены элементы priority queue:
https://ideone.com/c47H9D
#include <iostream>
#include <memory>
#include <queue>
int main ()
{
auto const less = [](std::unique_ptr<int> const& x, std::unique_ptr<int> const& y)
{
return x && y && (*x < *y);
};
using container = std::vector<std::unique_ptr<int>>;
std::priority_queue<std::unique_ptr<int>, container, decltype(less)> queue(less);
queue.push(std::make_unique<int>(24));
queue.push(std::make_unique<int>(42));
queue.push(std::make_unique<int>(11));
while (!queue.empty())
{
std::unique_ptr<int>& top = const_cast<std::unique_ptr<int>&>(queue.top());
std::unique_ptr<int> myInt = std::move(top);
queue.pop();
std::cout << *myInt << '\n';
if (*myInt == 24) queue.push(std::make_unique<int>(33));
}
}