[Boost-bugs] [Boost C++ Libraries] #7357: copy constructor of mutable_heap does not copy Compare base class

Subject: [Boost-bugs] [Boost C++ Libraries] #7357: copy constructor of mutable_heap does not copy Compare base class
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-09-10 14:28:14


#7357: copy constructor of mutable_heap does not copy Compare base class
-------------------------------------------------+--------------------------
 Reporter: Alex Hagen-Zanker <ahh34@…> | Owner: timblechmann
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: heap
  Version: Boost 1.52.0 | Severity: Problem
 Keywords: indirect compare, mutable heap |
-------------------------------------------------+--------------------------
 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;
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7357>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC