Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83263 - in trunk: boost/heap boost/heap/detail libs/heap/test
From: tim_at_[hidden]
Date: 2013-03-03 05:54:26


Author: timblechmann
Date: 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
New Revision: 83263
URL: http://svn.boost.org/trac/boost/changeset/83263

Log:
heap: fix emplace operations

fixes #8195
Text files modified:
   trunk/boost/heap/detail/stable_heap.hpp | 25 ++++++++++++++++++++++---
   trunk/boost/heap/pairing_heap.hpp | 2 +-
   trunk/libs/heap/test/binomial_heap_test.cpp | 2 ++
   trunk/libs/heap/test/common_heap_tests.hpp | 36 ++++++++++++++++++++++++++++++++++++
   trunk/libs/heap/test/d_ary_heap_test.cpp | 6 ++++++
   trunk/libs/heap/test/fibonacci_heap_test.cpp | 2 ++
   trunk/libs/heap/test/pairing_heap_tests.cpp | 2 ++
   trunk/libs/heap/test/skew_heap_test.cpp | 2 ++
   8 files changed, 73 insertions(+), 4 deletions(-)

Modified: trunk/boost/heap/detail/stable_heap.hpp
==============================================================================
--- trunk/boost/heap/detail/stable_heap.hpp (original)
+++ trunk/boost/heap/detail/stable_heap.hpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -217,6 +217,14 @@
     }
 #endif
 
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+ template <class... Args>
+ internal_type make_node(Args && ... val)
+ {
+ return internal_type(std::forward<Args>(val)...);
+ }
+#endif
+
     static T & get_value(internal_type & val)
     {
         return val;
@@ -283,7 +291,18 @@
 {
     typedef StabilityCounterType stability_counter_type;
     typedef T value_type;
- typedef std::pair<T, stability_counter_type> internal_type;
+
+ struct internal_type
+ {
+ template <class ...Args>
+ internal_type(stability_counter_type cnt, Args && ... args):
+ first(std::forward<Args>(args)...), second(cnt)
+ {}
+
+ T first;
+ stability_counter_type second;
+ };
+
     typedef size_holder<constant_time_size, size_t> size_holder_type;
     typedef Cmp value_compare;
 
@@ -356,7 +375,7 @@
         stability_counter_type count = ++counter_;
         if (counter_ == (std::numeric_limits<stability_counter_type>::max)())
             BOOST_THROW_EXCEPTION(std::runtime_error("boost::heap counter overflow"));
- return std::make_pair(val, count);
+ return internal_type(count, val);
     }
 
 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
@@ -366,7 +385,7 @@
         stability_counter_type count = ++counter_;
         if (counter_ == (std::numeric_limits<stability_counter_type>::max)())
             BOOST_THROW_EXCEPTION(std::runtime_error("boost::heap counter overflow"));
- return std::make_pair(std::forward<T>(args)..., count);
+ return internal_type (count, std::forward<Args>(args)...);
     }
 #endif
 

Modified: trunk/boost/heap/pairing_heap.hpp
==============================================================================
--- trunk/boost/heap/pairing_heap.hpp (original)
+++ trunk/boost/heap/pairing_heap.hpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -375,7 +375,7 @@
 
         node_pointer n = allocator_type::allocate(1);
 
- new(n) node(super_t::make_node(std::forward<T>(args)...));
+ new(n) node(super_t::make_node(std::forward<Args>(args)...));
 
         merge_node(n);
         return handle_type(n);

Modified: trunk/libs/heap/test/binomial_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/binomial_heap_test.cpp (original)
+++ trunk/libs/heap/test/binomial_heap_test.cpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -57,6 +57,8 @@
     run_binomial_heap_test<false, true>();
     run_binomial_heap_test<true, false>();
     run_binomial_heap_test<true, true>();
+
+ RUN_EMPLACE_TEST(binomial_heap);
 }
 
 BOOST_AUTO_TEST_CASE( binomial_heap_compare_lookup_test )

Modified: trunk/libs/heap/test/common_heap_tests.hpp
==============================================================================
--- trunk/libs/heap/test/common_heap_tests.hpp (original)
+++ trunk/libs/heap/test/common_heap_tests.hpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -449,4 +449,40 @@
     }
 };
 
+
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+
+class thing {
+public:
+ thing( int a_, int b_, int c_ ) : a(a_), b(b_), c(c_) {}
+public:
+ int a;
+ int b;
+ int c;
+};
+
+class cmpthings {
+public:
+ bool operator() ( const thing& lhs, const thing& rhs ) const {
+ return lhs.a > rhs.a;
+ }
+ bool operator() ( const thing& lhs, const thing& rhs ) {
+ return lhs.a > rhs.a;
+ }
+};
+
+#define RUN_EMPLACE_TEST(HEAP_TYPE) \
+ do { \
+ cmpthings ord; \
+ boost::heap::HEAP_TYPE<thing, boost::heap::compare<cmpthings> > vpq(ord); \
+ vpq.emplace(5, 6, 7); \
+ boost::heap::HEAP_TYPE<thing, boost::heap::compare<cmpthings>, boost::heap::stable<true> > vpq2(ord); \
+ vpq2.emplace(5, 6, 7); \
+ } while(0);
+
+#else
+#define RUN_EMPLACE_TEST(HEAP_TYPE)
+#endif
+
+
 #endif // COMMON_HEAP_TESTS_HPP_INCLUDED

Modified: trunk/libs/heap/test/d_ary_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/d_ary_heap_test.cpp (original)
+++ trunk/libs/heap/test/d_ary_heap_test.cpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -50,6 +50,12 @@
 
         run_stable_heap_tests<stable_pri_queue>();
     }
+
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+ cmpthings ord;
+ boost::heap::d_ary_heap<thing, boost::heap::arity<D>, boost::heap::compare<cmpthings>, boost::heap::stable<stable> > vpq(ord);
+ vpq.emplace(5, 6, 7);
+#endif
 }
 
 

Modified: trunk/libs/heap/test/fibonacci_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/fibonacci_heap_test.cpp (original)
+++ trunk/libs/heap/test/fibonacci_heap_test.cpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -61,6 +61,8 @@
 
     run_fibonacci_heap_test<false, false>();
     run_fibonacci_heap_test<false, true>();
+
+ RUN_EMPLACE_TEST(fibonacci_heap);
 }
 
 BOOST_AUTO_TEST_CASE( fibonacci_heap_compare_lookup_test )

Modified: trunk/libs/heap/test/pairing_heap_tests.cpp
==============================================================================
--- trunk/libs/heap/test/pairing_heap_tests.cpp (original)
+++ trunk/libs/heap/test/pairing_heap_tests.cpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -59,6 +59,8 @@
     run_pairing_heap_test<false, true>();
     run_pairing_heap_test<true, false>();
     run_pairing_heap_test<true, true>();
+
+ RUN_EMPLACE_TEST(pairing_heap);
 }
 
 BOOST_AUTO_TEST_CASE( pairing_heap_compare_lookup_test )

Modified: trunk/libs/heap/test/skew_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/skew_heap_test.cpp (original)
+++ trunk/libs/heap/test/skew_heap_test.cpp 2013-03-03 05:54:25 EST (Sun, 03 Mar 2013)
@@ -97,6 +97,8 @@
     run_skew_heap_test<false, true, false>();
     run_skew_heap_test<true, false, false>();
     run_skew_heap_test<true, true, false>();
+
+ RUN_EMPLACE_TEST(skew_heap);
 }
 
 BOOST_AUTO_TEST_CASE( skew_heap_mutable_test )


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk