
Andrew Sutton <asutton.list <at> gmail.com> writes:
the current Heap::merge() and Heap::merge_and_clear() are somewhat odd ...
thoughts?
So... taking a quick look, we shouldn't call the operation merge(), we should call it heap_merge() to avoid ADL issues with std::merge. We don't want to break merge_sort :) I see two algorithms:
void heap_merge(Heap1& lhs, Heap2& rhs); void heap_union(const Heap1& lhs, const Heap2& rhs, Heap3& result);
The first transfers all objects owned by rhs into lhs. I think that's important. The second is more like std::merge (but without iterators). Obviously, there should be specializations for Mergeable heaps.
FWIW, I also found Heap::merge() and Heap::merge_and_clear() «somewhat odd» and was left wondering why not overload ::insert() (which copies elements from a source) and reuse splice() name from std::list<> which moves nodes from one container to the other. Best Regards, Bernard