Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73828 - in trunk/libs/unordered/test: objects unordered
From: dnljms_at_[hidden]
Date: 2011-08-16 18:17:12


Author: danieljames
Date: 2011-08-16 18:17:11 EDT (Tue, 16 Aug 2011)
New Revision: 73828
URL: http://svn.boost.org/trac/boost/changeset/73828

Log:
Unordered: Use Boost.Move in minimal tests.
Text files modified:
   trunk/libs/unordered/test/objects/minimal.hpp | 34 ++++++++
   trunk/libs/unordered/test/unordered/compile_map.cpp | 12 +-
   trunk/libs/unordered/test/unordered/compile_set.cpp | 78 ++++++++++++++++++-
   trunk/libs/unordered/test/unordered/compile_tests.hpp | 154 ++++++++++++++++++++++++++++++---------
   4 files changed, 230 insertions(+), 48 deletions(-)

Modified: trunk/libs/unordered/test/objects/minimal.hpp
==============================================================================
--- trunk/libs/unordered/test/objects/minimal.hpp (original)
+++ trunk/libs/unordered/test/objects/minimal.hpp 2011-08-16 18:17:11 EDT (Tue, 16 Aug 2011)
@@ -11,6 +11,8 @@
 #define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
 
 #include <cstddef>
+#include <boost/move/move.hpp>
+#include <utility>
 
 #if defined(BOOST_MSVC)
 #pragma warning(push)
@@ -135,6 +137,38 @@
         //ampersand_operator_used operator&() const { return ampersand_operator_used(); }
     };
 
+ struct movable_init {};
+
+ class movable1
+ {
+ BOOST_MOVABLE_BUT_NOT_COPYABLE(movable1)
+
+ public:
+ movable1(constructor_param const&) {}
+ movable1() {}
+ explicit movable1(movable_init) {}
+ movable1(BOOST_RV_REF(movable1)) {}
+ movable1& operator=(BOOST_RV_REF(movable1));
+ ~movable1() {}
+ };
+
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
+ class movable2
+ {
+ public:
+ movable2(constructor_param const&) {}
+ explicit movable2(movable_init) {}
+ movable2(movable2&&) {}
+ ~movable2() {}
+ private:
+ movable2() {}
+ movable2(movable2 const&);
+ movable2& operator=(movable2 const&);
+ };
+#else
+ typedef movable1 movable2;
+#endif
+
     template <class T>
     class hash
     {

Modified: trunk/libs/unordered/test/unordered/compile_map.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/compile_map.cpp (original)
+++ trunk/libs/unordered/test/unordered/compile_map.cpp 2011-08-16 18:17:11 EDT (Tue, 16 Aug 2011)
@@ -151,12 +151,12 @@
 
     unordered_unique_test(map, map_value);
     unordered_map_test(map, value, value);
- unordered_test(map, value, map_value, hash, equal_to);
+ unordered_copyable_test(map, value, map_value, hash, equal_to);
     unordered_map_functions(map, value, value);
 
     unordered_unique_test(map2, map_value);
     unordered_map_test(map2, value, value);
- unordered_test(map2, value, map_value, hash, equal_to);
+ unordered_copyable_test(map2, value, map_value, hash, equal_to);
     unordered_map_functions(map2, value, value);
 
     std::cout<<"Test unordered_multimap.\n";
@@ -170,11 +170,11 @@
 
     unordered_equivalent_test(multimap, map_value);
     unordered_map_test(multimap, value, value);
- unordered_test(multimap, value, map_value, hash, equal_to);
+ unordered_copyable_test(multimap, value, map_value, hash, equal_to);
 
     unordered_equivalent_test(multimap2, map_value);
     unordered_map_test(multimap2, value, value);
- unordered_test(multimap2, value, map_value, hash, equal_to);
+ unordered_copyable_test(multimap2, value, map_value, hash, equal_to);
 }
 
 UNORDERED_AUTO_TEST(test2)
@@ -201,7 +201,7 @@
 
     unordered_unique_test(map, map_value);
     unordered_map_test(map, assignable, copy_constructible);
- unordered_test(map, assignable, map_value, hash, equal_to);
+ unordered_copyable_test(map, assignable, map_value, hash, equal_to);
 
     boost::unordered_map<
         test::minimal::assignable,
@@ -225,7 +225,7 @@
 
     unordered_equivalent_test(multimap, map_value);
     unordered_map_test(multimap, assignable, copy_constructible);
- unordered_test(multimap, assignable, map_value, hash, equal_to);
+ unordered_copyable_test(multimap, assignable, map_value, hash, equal_to);
 }
 
 RUN_TESTS()

Modified: trunk/libs/unordered/test/unordered/compile_set.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/compile_set.cpp (original)
+++ trunk/libs/unordered/test/unordered/compile_set.cpp 2011-08-16 18:17:11 EDT (Tue, 16 Aug 2011)
@@ -139,11 +139,11 @@
 
     unordered_unique_test(set, value);
     unordered_set_test(set, value);
- unordered_test(set, value, value, hash, equal_to);
+ unordered_copyable_test(set, value, value, hash, equal_to);
 
     unordered_unique_test(set2, value);
     unordered_set_test(set2, value);
- unordered_test(set2, value, value, hash, equal_to);
+ unordered_copyable_test(set2, value, value, hash, equal_to);
 
     std::cout<<"Test unordered_multiset.\n";
 
@@ -156,11 +156,11 @@
 
     unordered_equivalent_test(multiset, value);
     unordered_set_test(multiset, value);
- unordered_test(multiset, value, value, hash, equal_to);
+ unordered_copyable_test(multiset, value, value, hash, equal_to);
 
     unordered_equivalent_test(multiset2, value);
     unordered_set_test(multiset2, value);
- unordered_test(multiset2, value, value, hash, equal_to);
+ unordered_copyable_test(multiset2, value, value, hash, equal_to);
 }
 
 UNORDERED_AUTO_TEST(test2)
@@ -182,7 +182,7 @@
 
     unordered_unique_test(set, assignable);
     unordered_set_test(set, assignable);
- unordered_test(set, assignable, assignable, hash, equal_to);
+ unordered_copyable_test(set, assignable, assignable, hash, equal_to);
 
     std::cout<<"Test unordered_multiset.\n";
 
@@ -194,7 +194,73 @@
 
     unordered_equivalent_test(multiset, assignable);
     unordered_set_test(multiset, assignable);
- unordered_test(multiset, assignable, assignable, hash, equal_to);
+ unordered_copyable_test(multiset, assignable, assignable, hash, equal_to);
+}
+
+UNORDERED_AUTO_TEST(movable1_tests)
+{
+ test::minimal::constructor_param x;
+
+ test::minimal::movable1 movable1(x);
+ test::minimal::hash<test::minimal::movable1> hash(x);
+ test::minimal::equal_to<test::minimal::movable1> equal_to(x);
+
+ std::cout<<"Test unordered_set.\n";
+
+ boost::unordered_set<
+ test::minimal::movable1,
+ test::minimal::hash<test::minimal::movable1>,
+ test::minimal::equal_to<test::minimal::movable1>,
+ test::minimal::allocator<test::minimal::movable1> > set;
+
+ //unordered_unique_test(set, movable1);
+ unordered_set_test(set, movable1);
+ unordered_movable_test(set, movable1, movable1, hash, equal_to);
+
+ std::cout<<"Test unordered_multiset.\n";
+
+ boost::unordered_multiset<
+ test::minimal::movable1,
+ test::minimal::hash<test::minimal::movable1>,
+ test::minimal::equal_to<test::minimal::movable1>,
+ test::minimal::allocator<test::minimal::movable1> > multiset;
+
+ //unordered_equivalent_test(multiset, movable1);
+ unordered_set_test(multiset, movable1);
+ unordered_movable_test(multiset, movable1, movable1, hash, equal_to);
+}
+
+UNORDERED_AUTO_TEST(movable2_tests)
+{
+ test::minimal::constructor_param x;
+
+ test::minimal::movable2 movable2(x);
+ test::minimal::hash<test::minimal::movable2> hash(x);
+ test::minimal::equal_to<test::minimal::movable2> equal_to(x);
+
+ std::cout<<"Test unordered_set.\n";
+
+ boost::unordered_set<
+ test::minimal::movable2,
+ test::minimal::hash<test::minimal::movable2>,
+ test::minimal::equal_to<test::minimal::movable2>,
+ test::minimal::allocator<test::minimal::movable2> > set;
+
+ //unordered_unique_test(set, movable2);
+ unordered_set_test(set, movable2);
+ unordered_movable_test(set, movable2, movable2, hash, equal_to);
+
+ std::cout<<"Test unordered_multiset.\n";
+
+ boost::unordered_multiset<
+ test::minimal::movable2,
+ test::minimal::hash<test::minimal::movable2>,
+ test::minimal::equal_to<test::minimal::movable2>,
+ test::minimal::allocator<test::minimal::movable2> > multiset;
+
+ //unordered_equivalent_test(multiset, movable2);
+ unordered_set_test(multiset, movable2);
+ unordered_movable_test(multiset, movable2, movable2, hash, equal_to);
 }
 
 UNORDERED_AUTO_TEST(destructible_tests)

Modified: trunk/libs/unordered/test/unordered/compile_tests.hpp
==============================================================================
--- trunk/libs/unordered/test/unordered/compile_tests.hpp (original)
+++ trunk/libs/unordered/test/unordered/compile_tests.hpp 2011-08-16 18:17:11 EDT (Tue, 16 Aug 2011)
@@ -189,6 +189,7 @@
 {
     typedef BOOST_DEDUCED_TYPENAME X::value_type value_type;
     typedef BOOST_DEDUCED_TYPENAME X::key_type key_type;
+
     BOOST_MPL_ASSERT((
         boost::is_same<value_type, std::pair<key_type const, T> >));
 
@@ -242,8 +243,8 @@
     test::check_return_type<mapped_type const>::equals_ref(b.at(k));
 }
 
-template <class X, class Key, class T, class Hash, class Pred>
-void unordered_test(X& x, Key& k, T& t, Hash& hf, Pred& eq)
+template <class X, class Key, class Hash, class Pred>
+void unordered_test(X& x, Key& k, Hash& hf, Pred& eq)
 {
     unordered_destructible_test(x);
 
@@ -310,8 +311,8 @@
         const_local_iterator_reference;
 
     BOOST_MPL_ASSERT((boost::is_same<Key, key_type>));
- boost::function_requires<boost::CopyConstructibleConcept<key_type> >();
- boost::function_requires<boost::AssignableConcept<key_type> >();
+ //boost::function_requires<boost::CopyConstructibleConcept<key_type> >();
+ //boost::function_requires<boost::AssignableConcept<key_type> >();
 
     BOOST_MPL_ASSERT((boost::is_same<Hash, hasher>));
     test::check_return_type<std::size_t>::equals(hf(k));
@@ -349,45 +350,18 @@
     X();
     X a4;
 
- BOOST_DEDUCED_TYPENAME X::value_type* i = 0;
- BOOST_DEDUCED_TYPENAME X::value_type* j = 0;
-
- X(i, j, 10, hf, eq);
- X a5(i, j, 10, hf, eq);
- X(i, j, 10, hf);
- X a6(i, j, 10, hf);
- X(i, j, 10);
- X a7(i, j, 10);
- X(i, j);
- X a8(i, j);
-
- X const b;
- sink(X(b));
- X a9(b);
- a = b;
-
- test::check_return_type<hasher>::equals(b.hash_function());
- test::check_return_type<key_equal>::equals(b.key_eq());
-
- const_iterator q = a.cbegin();
- test::check_return_type<iterator>::equals(a.insert(q, t));
- test::check_return_type<iterator>::equals(a.emplace_hint(q, t));
-
- a.insert(i, j);
     test::check_return_type<size_type>::equals(a.erase(k));
 
- BOOST_TEST(a.empty());
- if(a.empty()) {
- a.insert(t);
- q = a.cbegin();
- test::check_return_type<iterator>::equals(a.erase(q));
- }
-
     const_iterator q1 = a.cbegin(), q2 = a.cend();
     test::check_return_type<iterator>::equals(a.erase(q1, q2));
 
     a.clear();
 
+ X const b;
+
+ test::check_return_type<hasher>::equals(b.hash_function());
+ test::check_return_type<key_equal>::equals(b.key_eq());
+
     test::check_return_type<iterator>::equals(a.find(k));
     test::check_return_type<const_iterator>::equals(b.find(k));
     test::check_return_type<size_type>::equals(b.count(k));
@@ -421,9 +395,117 @@
     sink(a2);
     sink(a3);
     sink(a4);
+}
+
+template <class X, class Key, class T, class Hash, class Pred>
+void unordered_copyable_test(X& x, Key& k, T& t, Hash& hf, Pred& eq)
+{
+ unordered_test(x, k, hf, eq);
+
+ typedef BOOST_DEDUCED_TYPENAME X::iterator iterator;
+ typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator;
+
+ X a;
+
+ BOOST_DEDUCED_TYPENAME X::value_type* i = 0;
+ BOOST_DEDUCED_TYPENAME X::value_type* j = 0;
+
+ X(i, j, 10, hf, eq);
+ X a5(i, j, 10, hf, eq);
+ X(i, j, 10, hf);
+ X a6(i, j, 10, hf);
+ X(i, j, 10);
+ X a7(i, j, 10);
+ X(i, j);
+ X a8(i, j);
+
+ X const b;
+ sink(X(b));
+ X a9(b);
+ a = b;
+
+ const_iterator q = a.cbegin();
+
+ test::check_return_type<iterator>::equals(a.insert(q, t));
+ test::check_return_type<iterator>::equals(a.emplace_hint(q, t));
+
+ a.insert(i, j);
+
+ X a10;
+ a10.insert(t);
+ q = a10.cbegin();
+ test::check_return_type<iterator>::equals(a10.erase(q));
+
+ // Avoid unused variable warnings:
+
+ sink(a);
     sink(a5);
     sink(a6);
     sink(a7);
     sink(a8);
     sink(a9);
 }
+
+template <class X, class Key, class T, class Hash, class Pred>
+void unordered_movable_test(X& x, Key& k, T& /* t */, Hash& hf, Pred& eq)
+{
+ unordered_test(x, k, hf, eq);
+
+ typedef BOOST_DEDUCED_TYPENAME X::iterator iterator;
+ typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator;
+
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
+ X x1(rvalue_default<X>();
+ X x2(boost::move(x1));
+ x1 = rvalue_default<X>();
+ x2 = boost::move(x1);
+#endif
+
+ test::minimal::constructor_param* i = 0;
+ test::minimal::constructor_param* j = 0;
+
+ X(i, j, 10, hf, eq);
+ X a5(i, j, 10, hf, eq);
+ X(i, j, 10, hf);
+ X a6(i, j, 10, hf);
+ X(i, j, 10);
+ X a7(i, j, 10);
+ X(i, j);
+ X a8(i, j);
+
+ X a;
+
+ const_iterator q = a.cbegin();
+
+ test::minimal::constructor_param v;
+ a.emplace(v);
+ test::check_return_type<iterator>::equals(a.emplace_hint(q, v));
+
+ T v1(v);
+ a.emplace(boost::move(v1));
+ T v2(v);
+ a.insert(boost::move(v2));
+ T v3(v);
+ test::check_return_type<iterator>::equals(
+ a.emplace_hint(q, boost::move(v3)));
+ T v4(v);
+ test::check_return_type<iterator>::equals(
+ a.insert(q, boost::move(v4)));
+
+ a.insert(i, j);
+
+ X a10;
+ T v5(v);
+ a10.insert(boost::move(v5));
+ q = a10.cbegin();
+ test::check_return_type<iterator>::equals(a10.erase(q));
+
+ // Avoid unused variable warnings:
+
+ sink(a);
+ sink(a5);
+ sink(a6);
+ sink(a7);
+ sink(a8);
+ sink(a10);
+}


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