Daily bit(e) of C++ | std::priority_queue
Daily bit(e) of C++ #234, The ordered queue container adapter: std::priority_queue.
The std::priority_queue is a container adapter implementing an ordered queue, i.e. a queue in which the largest element is always on the top and extracted first.
The behaviour is similar to manually managing a heap using heap algorithms, with a more convenient interface. However, with the caveat that the elements can only be copied from the queue, not moved out.
did you have anything w/ result_of, invoke and invoke_result ? if not it's a suggestion :)
It has alway been very counter-intuitive to me that when you write a custom lambda (in this case left.size() > right.size()) for priority_queue, it pops out smaller elements first. I always have to remind myself “It’s the other way around”. I think I even came up with a mental picture to memorize that.
Do you have a better way to remember this? Or a technical detail that I couldn’t find.