Add a fast replace_top method to std::priority_queue.
Also std::poke_heap(first, last), which assumes that the given range is in max-heap order *except* for the first element, which needs to be put into its proper place. This is just like push_heap, except that push_heap assumes the *last* element is out of order, whereas poke_heap assumes the *first* element is out of order.
The changes in <queue> could use _VSTD::poke_heap instead of __sift_down, but they do not, in order to keep the <queue> changes usable as a single-file patch (in case someone wants to take the <queue> changes without the <algorithm> changes).
The poke_heap approach would replace the last line of each new method with this line instead:
_VSTD::poke_heap(c.begin(), c.end(), comp);
I did this patch a while back for a blog post, and initially didn't intend to do anything else with it. Just recently I learned that people (well, Simon Brand and @Leandros) apparently want it enough to tweet about the existence of the patch
https://twitter.com/ArvidGerstmann/status/1071033081719676928
so I figure I should take the next step and actually post it for review.
(The blog post in question was https://quuxplusone.github.io/blog/2018/04/27/pq-replace-top/ )
This should instead be #if _LIBCPP_STD_VER > 23, or whatever standard version you target with this feature.