$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54085 - sandbox/monotonic/libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-18 23:46:12
Author: cschladetsch
Date: 2009-06-18 23:46:10 EDT (Thu, 18 Jun 2009)
New Revision: 54085
URL: http://svn.boost.org/trac/boost/changeset/54085
Log:
changed tests to just pass the allocator type
Text files modified: 
   sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp |   109 ++++++++++++++++++++++----------------- 
   1 files changed, 61 insertions(+), 48 deletions(-)
Modified: sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp	(original)
+++ sandbox/monotonic/libs/monotonic/test/compare_memory_pool.cpp	2009-06-18 23:46:10 EDT (Thu, 18 Jun 2009)
@@ -20,35 +20,42 @@
         return A.c < B.c;
 }
 
+template <class Alloc, class T>
+struct Rebind
+{
+	typedef typename Alloc::template rebind<T>::other type;
+};
+
 struct thrash_pool
 {
-	template <class Pool>
-	int operator()(size_t length, Pool &pool) const
+	template <class Alloc>
+	int test(size_t length) const
         {
-		pool.resize(length*rand()/RAND_MAX);
-		return accumulate(pool.begin(), pool.end(), 0);
+		std::vector<int, Rebind<Alloc, int>::type> vector;
+		vector.resize(length*rand()/RAND_MAX);
+		return accumulate(vector.begin(), vector.end(), 0);
         }
 };
 
 struct thrash_pool_sort
 {
-	template <class Pool>
-	int operator()(size_t length, Pool &pool) const
+	template <class Alloc>
+	int test(size_t length) const
         {
-		pool.resize(length*rand()/RAND_MAX);
-		generate_n(back_inserter(pool), length, rand);
-		sort(pool.begin(), pool.end());
+		std::vector<int, Rebind<Alloc, int>::type> vector;
+		vector.resize(length*rand()/RAND_MAX);
+		generate_n(back_inserter(vector), length, rand);
+		sort(vector.begin(), vector.end());
                 return 0;
         }
 };
 
 struct thrash_pool_sort_list_int
 {
-	template <class Pool>
-	int operator()(size_t length, Pool &pool) const
+	template <class Alloc>
+	int test(size_t length) const
         {
-		typedef typename Pool::allocator_type allocator;
-		std::list<int, typename allocator::template rebind<int>::other> list;
+		std::list<int, Rebind<Alloc, int>::type> list;
                 generate_n(back_inserter(list), length, rand);
                 list.sort();
                 return 0;
@@ -57,14 +64,13 @@
 
 struct thrash_pool_iter
 {
-	template <class Pool>
-	int operator()(size_t length, Pool &pool) const
+	template <class Alloc>
+	int test(size_t length) const
         {
-		typedef typename Pool::allocator_type allocator;
-		std::vector<Unaligned, typename allocator::template rebind<Unaligned>::other> vec;
-		vec.resize(length);
+		std::vector<Unaligned, Rebind<Alloc, Unaligned>::type> vector;
+		vector.resize(length);
                 int total = 0;
-		BOOST_FOREACH(Unaligned const &val, vec)
+		BOOST_FOREACH(Unaligned const &val, vector)
                 {
                         total += val.c;
                 }
@@ -75,14 +81,13 @@
 
 struct thrash_pool_map_list_unaligned
 {
-	template <class Pool>
-	int operator()(size_t length, Pool &pool) const
+	template <class Alloc>
+	int test(size_t length) const
         {
-		typedef typename Pool::allocator_type allocator;
                 std::map<int
-			, std::list<Unaligned, typename allocator::template rebind<Unaligned>::other>
+			, std::list<Unaligned, Rebind<Alloc, Unaligned>::type>
                         , std::less<int>
-			, typename allocator::template rebind<int>::other
+			, Rebind<Alloc, int>::type
 		> map;
                 size_t mod = length/10;
                 for (size_t n = 0; n < length; ++n)
@@ -94,6 +99,23 @@
         }
 };
 
+struct test_dupe_list
+{
+	template <class Alloc>
+	int test(size_t count) const
+	{
+		size_t dummy = 0;
+		std::list<int, Rebind<Alloc, int>::type> list;
+		fill_n(back_inserter(list), size, 42);
+		for (size_t n = 0; n < count; ++n)
+		{
+			List dupe = list;
+			dummy += dupe.size();
+		}
+		return dummy;
+	}
+};
+
 struct PoolResult 
 {
         double pool_elapsed;
@@ -112,20 +134,16 @@
 template <class Fun>
 PoolResult compare_memory_pool(size_t count, size_t length, Fun fun)
 {
-	typedef std::vector<
-		int
-		, boost::fast_pool_allocator<int
-			, boost::default_user_allocator_new_delete
-			, boost::details::pool::null_mutex> > 
-		fast_pool_v;
-	typedef std::vector<
-		int
-		, boost::pool_allocator<int
-			, boost::default_user_allocator_new_delete
-			, boost::details::pool::null_mutex> > 
-		pool_v;
-	typedef std::vector<int, boost::monotonic::allocator<int> > mono_v;
-	typedef std::vector<int > std_v;
+	typedef boost::fast_pool_allocator<int
+		, boost::default_user_allocator_new_delete
+		, boost::details::pool::null_mutex>
+		fast_pool_alloc;
+	typedef boost::pool_allocator<int
+		, boost::default_user_allocator_new_delete
+		, boost::details::pool::null_mutex>
+		pool_alloc;
+	typedef monotonic::allocator<int> mono_alloc;
+	typedef std::allocator<int > std_alloc;
 
         PoolResult result;
 
@@ -136,8 +154,7 @@
                 for (size_t n = 0; n < count; ++n)
                 {
                         {
-				fast_pool_v pool;
-				fun(length, pool);
+				fun.test<fast_pool_alloc>(length);
                         }
                         boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(int)>::release_memory();
                         boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(Unaligned)>::release_memory();
@@ -153,8 +170,7 @@
                 for (size_t n = 0; n < count; ++n)
                 {
                         {
-				pool_v pool;
-				fun(length, pool);
+				fun.test<pool_alloc>(length);
                         }
                         boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>::release_memory();
                         boost::singleton_pool<boost::pool_allocator_tag, sizeof(Unaligned)>::release_memory();
@@ -170,8 +186,7 @@
                 for (size_t n = 0; n < count; ++n)
                 {
                         {
-				mono_v pool;
-				fun(length, pool);
+				fun.test<mono_alloc>(length);
                         }
                         boost::monotonic::reset_storage();
                 }
@@ -186,8 +201,7 @@
                 for (size_t n = 0; n < count; ++n)
                 {
                         {
-				mono_v pool;
-				fun(length, pool);
+				fun.test<mono_alloc>(length);
                         }
                         storage.reset();
                 }
@@ -201,8 +215,7 @@
                 for (size_t n = 0; n < count; ++n)
                 {
                         {
-				std_v pool;
-				fun(length, pool);
+				fun.test<std_alloc>(length);
                         }
                 }
                 result.std_elapsed = timer.elapsed();