Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73539 - trunk/libs/unordered/test/unordered
From: dnljms_at_[hidden]
Date: 2011-08-04 18:54:27


Author: danieljames
Date: 2011-08-04 18:54:26 EDT (Thu, 04 Aug 2011)
New Revision: 73539
URL: http://svn.boost.org/trac/boost/changeset/73539

Log:
Unordered: Update unnecessary_copy_tests for Boost.Move.

Seems to be better in some cases. For example, better forwarding if
rvalue references are supported but variadic template parameters aren't.
Also can use `boost::move` when inserting.

Older versions of gcc still fail this test. They perform more moves than
expected. It might be a limitation of Boost.Move, or maybe just poor
copy optimization.
Text files modified:
   trunk/libs/unordered/test/unordered/unnecessary_copy_tests.cpp | 54 ++++++++++++++++++++++++++++++++++++---
   1 files changed, 49 insertions(+), 5 deletions(-)

Modified: trunk/libs/unordered/test/unordered/unnecessary_copy_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/unnecessary_copy_tests.cpp (original)
+++ trunk/libs/unordered/test/unordered/unnecessary_copy_tests.cpp 2011-08-04 18:54:26 EDT (Thu, 04 Aug 2011)
@@ -13,6 +13,9 @@
 {
     struct count_copies
     {
+ private:
+ BOOST_COPYABLE_AND_MOVABLE(count_copies)
+ public:
         static int copies;
         static int moves;
         count_copies() : tag_(0) { ++copies; }
@@ -31,13 +34,17 @@
             : tag_(x.tag_) { ++copies; }
 
         count_copies(count_copies const& x) : tag_(x.tag_) { ++copies; }
-#if !defined(BOOST_NO_RVALUE_REFERENCES)
- count_copies(count_copies&& x) : tag_(x.tag_) {
+ count_copies(BOOST_RV_REF(count_copies) x) : tag_(x.tag_) {
             x.tag_ = -1; ++moves;
         }
-#endif
+
        int tag_;
     private:
+ // I think the standard might require assignment (or move
+ // assignment) for some operations. That Boost.Unordered doesn't
+ // is an implementation detail. But these tests are very specific
+ // to the implementation, so it's probably okay that this doesn't
+ // meet the standard requirements.
        count_copies& operator=(count_copies const&);
     };
 
@@ -136,7 +143,7 @@
         reset();
         T x;
         x.emplace(source<BOOST_DEDUCED_TYPENAME T::value_type>());
-#if !defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
         COPY_COUNT(1);
 #else
         COPY_COUNT(2);
@@ -148,7 +155,7 @@
     UNORDERED_TEST(unnecessary_copy_emplace_rvalue_test,
             ((set)(multiset)(map)(multimap)))
 
-#if !defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
     template <class T>
     void unnecessary_copy_emplace_move_test(T*)
     {
@@ -162,8 +169,39 @@
 
     UNORDERED_TEST(unnecessary_copy_emplace_move_test,
             ((set)(multiset)(map)(multimap)))
+#endif
+
+ template <class T>
+ void unnecessary_copy_emplace_boost_move_set_test(T*)
+ {
+ reset();
+ T x;
+ BOOST_DEDUCED_TYPENAME T::value_type a;
+ COPY_COUNT(1); MOVE_COUNT(0);
+ x.emplace(boost::move(a));
+ COPY_COUNT(1); MOVE_COUNT(1);
+ }
 
+ UNORDERED_TEST(unnecessary_copy_emplace_boost_move_set_test,
+ ((set)(multiset)))
+
+ template <class T>
+ void unnecessary_copy_emplace_boost_move_map_test(T*)
+ {
+ reset();
+ T x;
+ BOOST_DEDUCED_TYPENAME T::value_type a;
+ COPY_COUNT(1); MOVE_COUNT(0);
+ x.emplace(boost::move(a));
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
+ COPY_COUNT(1); MOVE_COUNT(1);
+#else
+ COPY_COUNT(2); MOVE_COUNT(0);
 #endif
+ }
+
+ UNORDERED_TEST(unnecessary_copy_emplace_boost_move_map_test,
+ ((map)(multimap)))
 
     UNORDERED_AUTO_TEST(unnecessary_copy_emplace_set_test)
     {
@@ -181,7 +219,13 @@
         // the existing element.
         reset();
         x.emplace();
+#if !defined(BOOST_UNORDERED_STD_FORWARD)
+ // TODO: I think that in this case the move could be delayed until
+ // after checking for a collision, giving MOVE_COUNT(0).
+ COPY_COUNT(1); MOVE_COUNT(1);
+#else
         COPY_COUNT(1); MOVE_COUNT(0);
+#endif
 
         //
         // 1 argument


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