If you want to call std::pop_heap() in your own container v , you can just first v.push_back() in the container "change" the element before v.push_back() up the heap. Then squeeze v .
// Precondition is that v is already a heap. void change_max_element (std::vector<int> &v, int modified_value) { v.push_back(modified_value); std::pop_heap(v.begin(), v.end()); v.pop_back(); }
This "works" because std::pop_heap() is defined to replace the first and last elements and create bubbles. However, it is also indicated that the input sequence must be a valid heap. If we can define a specialized comparison operation that would allow the newly pushed back element to inform itself that it belongs in the last position, if it was already in the last position, then it could technically satisfy this requirement.
source share