static void merge(Heap1 & lhs, Heap2 & rhs) { if (Heap1::constant_time_size && Heap2::constant_time_size) { if (Heap1::has_reserve) { std::size_t required_size = lhs.size() + rhs.size(); space_reserver::reserve(lhs, required_size); } } // FIXME: container adaptors could benefit from first appending all elements and then restoring the heap order // FIXME: optimize: if we have ordered iterators and we can efficiently insert keys with a below the lowest key in the heap // d-ary, b and fibonacci heaps fall into this category while (!rhs.empty()) { lhs.push(rhs.top()); rhs.pop(); } lhs.set_stability_count((std::max)(lhs.get_stability_count(), rhs.get_stability_count())); rhs.set_stability_count(0); }