Opened 10 years ago

Closed 10 years ago

#7357 closed Bugs (fixed)

copy constructor of mutable_heap does not copy Compare base class

Reported by: Alex Hagen-Zanker <ahh34@…> Owned by: timblechmann
Milestone: To Be Determined Component: heap
Version: Boost 1.52.0 Severity: Problem
Keywords: indirect compare, mutable heap Cc:

Description

The copy constructor of priority_queue_mutable_wrapper only copies over the elements in the queue and it default constructs the Compare base class.

Therefore the third assertion in the code below fails. This is a severe problem when an indirect comparison is applied.

#include <boost/heap/d_ary_heap.hpp> #include <assert.h> struct multiplied_compare {

multiplied_compare(int m = 1) : m(m) {}

bool operator()(const int& a, const int& b) const {

return m*a < m*b;

} int m;

};

int main() {

typedef boost::heap::d_ary_heap<

int, boost::heap::mutable_<true>, boost::heap::compare<multiplied_compare>, boost::heap::arity<4> > heap_type;

heap_type plus(1); plus.push(100); plus.push(200); assert(plus.top() == 200);

heap_type minus(-1); minus.push(100); minus.push(200); assert(minus.top() == 100);

heap_type copy = minus; copy.clear(); copy.push(100); copy.push(200); assert(copy.top() == 100);

return 0;

}

Change History (2)

comment:1 by timblechmann, 10 years ago

thanks for reporting. fixed in trunk

comment:2 by timblechmann, 10 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.