Title
priority_queue doesn't work with move-only types
Status
nad
Section
[priority.queue]
Submitter
Matt Austern

Created on 2015-10-27.00:00:00 last changed 108 months ago

Messages

Date: 2016-02-07.20:24:45

[ 2016-02, Issues Telecon ]

This should be addressed by a paper addressed to LEWG.

Date: 2015-10-27.00:00:00

Suppose we want to remove and process the topmost element of a priority_queue<T>. For a copyable type we might write

auto tmp = q.top();
q.pop();

but of course that doesn't work if T is move-only. Nothing of that sort can work, since moving out of top() would make the subsequent call to pop() fail.

Currently, pop() is defined to perform

pop_heap(c.begin(), c.end(), comp);
c.pop_back();

so the removed value continues to exist between the first and second lines but there isn't any access to it. The sort of primitive that would allow consuming and removing the topmost element would be some variation on this, e.g.

pop_heap(c.begin(), c.end(), comp);
auto tmp = move(c.back());
c.pop_back();
return tmp;
History
Date User Action Args
2016-02-07 20:24:45adminsetmessages: + msg7955
2016-02-07 20:24:45adminsetstatus: new -> nad
2015-10-27 00:00:00admincreate