diff --git a/test/objects/test.hpp b/test/objects/test.hpp index 62aae7aa..2a1dfbdf 100644 --- a/test/objects/test.hpp +++ b/test/objects/test.hpp @@ -22,7 +22,8 @@ namespace test class hash; class less; class equal_to; - template class allocator; + template class allocator1; + template class allocator2; object generate(object const*); implicitly_convertible generate(implicitly_convertible const*); @@ -183,13 +184,97 @@ namespace test } }; + // allocator1 and allocator2 are pretty similar. + // allocator1 only has the old fashioned 'construct' method and has + // a few less typedefs + template - class allocator + class allocator1 + { + public: + int tag_; + + typedef T value_type; + + template struct rebind { typedef allocator1 other; }; + + explicit allocator1(int t = 0) : tag_(t) + { + detail::tracker.allocator_ref(); + } + + template allocator1(allocator1 const& x) + : tag_(x.tag_) + { + detail::tracker.allocator_ref(); + } + + allocator1(allocator1 const& x) + : tag_(x.tag_) + { + detail::tracker.allocator_ref(); + } + + ~allocator1() + { + detail::tracker.allocator_unref(); + } + + T* allocate(std::size_t n) { + T* ptr(static_cast(::operator new(n * sizeof(T)))); + detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); + return ptr; + } + + T* allocate(std::size_t n, void const* u) + { + T* ptr(static_cast(::operator new(n * sizeof(T)))); + detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); + return ptr; + } + + void deallocate(T* p, std::size_t n) + { + detail::tracker.track_deallocate((void*) p, n, sizeof(T), tag_); + ::operator delete((void*) p); + } + + void construct(T* p, T const& t) { + // Don't count constructions here as it isn't always called. + //detail::tracker.track_construct((void*) p, sizeof(T), tag_); + new(p) T(t); + } + + void destroy(T* p) { + //detail::tracker.track_destroy((void*) p, sizeof(T), tag_); + p->~T(); + } + + bool operator==(allocator1 const& x) const + { + return tag_ == x.tag_; + } + + bool operator!=(allocator1 const& x) const + { + return tag_ != x.tag_; + } + + enum { + is_select_on_copy = false, + is_propagate_on_swap = false, + is_propagate_on_assign = false, + is_propagate_on_move = false + }; + }; + + template + class allocator2 { # ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: # else - template friend class allocator; + template friend class allocator2; # endif int tag_; public: @@ -201,26 +286,26 @@ namespace test typedef T const& const_reference; typedef T value_type; - template struct rebind { typedef allocator other; }; + template struct rebind { typedef allocator2 other; }; - explicit allocator(int t = 0) : tag_(t) + explicit allocator2(int t = 0) : tag_(t) { detail::tracker.allocator_ref(); } - template allocator(allocator const& x) + template allocator2(allocator2 const& x) : tag_(x.tag_) { detail::tracker.allocator_ref(); } - allocator(allocator const& x) + allocator2(allocator2 const& x) : tag_(x.tag_) { detail::tracker.allocator_ref(); } - ~allocator() + ~allocator2() { detail::tracker.allocator_unref(); } @@ -275,12 +360,12 @@ namespace test return (std::numeric_limits::max)(); } - bool operator==(allocator const& x) const + bool operator==(allocator2 const& x) const { return tag_ == x.tag_; } - bool operator!=(allocator const& x) const + bool operator!=(allocator2 const& x) const { return tag_ != x.tag_; } @@ -294,7 +379,14 @@ namespace test }; template - bool equivalent_impl(allocator const& x, allocator const& y, + bool equivalent_impl(allocator1 const& x, allocator1 const& y, + test::derived_type) + { + return x == y; + } + + template + bool equivalent_impl(allocator2 const& x, allocator2 const& y, test::derived_type) { return x == y; diff --git a/test/unordered/assign_tests.cpp b/test/unordered/assign_tests.cpp index 60a11306..cd750998 100644 --- a/test/unordered/assign_tests.cpp +++ b/test/unordered/assign_tests.cpp @@ -114,18 +114,22 @@ void assign_tests2(T*, } } -boost::unordered_set >* test_set; -boost::unordered_multiset >* test_multiset; boost::unordered_map >* test_map; + std::allocator >* test_map_std_alloc; + +boost::unordered_set >* test_set; +boost::unordered_multiset >* test_multiset; +boost::unordered_map >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator1 >* test_multimap; boost::unordered_set >* test_set; -boost::unordered_multiset >* test_multiset; -boost::unordered_map >* test_map; boost::unordered_multimap >* test_multimap; + std::allocator >* test_multimap_std_alloc; -UNORDERED_TEST(tests, ((test_set)(test_multiset)(test_map)(test_multimap))) +boost::unordered_set >* test_set; +boost::unordered_multiset >* test_multiset; +boost::unordered_map >* test_map; +boost::unordered_multimap >* test_multimap; + +UNORDERED_TEST(tests, ((test_multimap_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap))) } diff --git a/test/unordered/constructor_tests.cpp b/test/unordered/constructor_tests.cpp index e0536187..82c13669 100644 --- a/test/unordered/constructor_tests.cpp +++ b/test/unordered/constructor_tests.cpp @@ -402,24 +402,28 @@ void map_constructor_test(T* = 0, test::check_equivalent_keys(x); } -boost::unordered_set >* test_set; -boost::unordered_multiset >* test_multiset; boost::unordered_map >* test_map; + std::allocator >* test_map_std_alloc; + +boost::unordered_set >* test_set; +boost::unordered_multiset >* test_multiset; +boost::unordered_map >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator1 >* test_multimap; using test::default_generator; using test::generate_collisions; UNORDERED_TEST(constructor_tests1, - ((test_set)(test_multiset)(test_map)(test_multimap)) + ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)) ((default_generator)(generate_collisions)) ) @@ -429,7 +433,7 @@ UNORDERED_TEST(constructor_tests2, ) UNORDERED_TEST(map_constructor_test, - ((test_map)(test_multimap)) + ((test_map_std_alloc)(test_map)(test_multimap)) ) #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) diff --git a/test/unordered/copy_tests.cpp b/test/unordered/copy_tests.cpp index 2fe79b1b..08c58baa 100644 --- a/test/unordered/copy_tests.cpp +++ b/test/unordered/copy_tests.cpp @@ -155,16 +155,16 @@ void copy_construct_tests2(T* ptr, boost::unordered_set >* test_set; + test::allocator1 >* test_set; boost::unordered_multiset >* test_multiset; + test::allocator2 >* test_multiset; boost::unordered_map >* test_map; + test::allocator1 >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator2 >* test_multimap; boost::unordered_set, - test::allocator > > collide_map; + test::allocator1 > > collide_map; typedef boost::unordered_multimap, - test::allocator > > collide_map2; + test::allocator2 > > collide_map2; typedef collide_map::value_type collide_value; typedef test::list collide_list; diff --git a/test/unordered/erase_tests.cpp b/test/unordered/erase_tests.cpp index 0d5a0b4a..3d6c3ef2 100644 --- a/test/unordered/erase_tests.cpp +++ b/test/unordered/erase_tests.cpp @@ -196,16 +196,16 @@ void erase_tests1(Container*, boost::unordered_set >* test_set; + test::allocator1 >* test_set; boost::unordered_multiset >* test_multiset; + test::allocator2 >* test_multiset; boost::unordered_map >* test_map; + test::allocator1 >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator2 >* test_multimap; using test::default_generator; using test::generate_collisions; diff --git a/test/unordered/find_tests.cpp b/test/unordered/find_tests.cpp index 3999bae4..a7efaa1c 100644 --- a/test/unordered/find_tests.cpp +++ b/test/unordered/find_tests.cpp @@ -142,16 +142,16 @@ void find_compatible_keys_test(X*, boost::unordered_set >* test_set; + test::allocator2 >* test_set; boost::unordered_multiset >* test_multiset; + test::allocator1 >* test_multiset; boost::unordered_map >* test_map; + test::allocator2 >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator1 >* test_multimap; using test::default_generator; using test::generate_collisions; diff --git a/test/unordered/insert_tests.cpp b/test/unordered/insert_tests.cpp index 2db28c24..1de40266 100644 --- a/test/unordered/insert_tests.cpp +++ b/test/unordered/insert_tests.cpp @@ -410,43 +410,50 @@ void map_insert_range_test2(X*, boost::unordered_set >* test_set; -boost::unordered_multiset >* test_multiset; -boost::unordered_map >* test_map; + std::allocator >* test_set_std_alloc; boost::unordered_multimap >* test_multimap; + std::allocator >* test_multimap_std_alloc; + +boost::unordered_set >* test_set; +boost::unordered_multiset >* test_multiset; +boost::unordered_map >* test_map; +boost::unordered_multimap >* test_multimap; using test::default_generator; using test::generate_collisions; UNORDERED_TEST(unique_insert_tests1, - ((test_set)(test_map)) + ((test_set_std_alloc)(test_set)(test_map)) ((default_generator)(generate_collisions)) ) UNORDERED_TEST(equivalent_insert_tests1, - ((test_multiset)(test_multimap)) + ((test_multimap_std_alloc)(test_multiset)(test_multimap)) ((default_generator)(generate_collisions)) ) UNORDERED_TEST(insert_tests2, - ((test_set)(test_multiset)(test_map)(test_multimap)) + ((test_multimap_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)) ((default_generator)(generate_collisions)) ) #if !defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_NO_VARIADIC_TEMPLATES) UNORDERED_TEST(unique_emplace_tests1, - ((test_set)(test_map)) + ((test_set_std_alloc)(test_set)(test_map)) ((default_generator)(generate_collisions)) ) UNORDERED_TEST(equivalent_emplace_tests1, - ((test_multiset)(test_multimap)) + ((test_multimap_std_alloc)(test_multiset)(test_multimap)) ((default_generator)(generate_collisions)) ) #endif @@ -457,12 +464,12 @@ UNORDERED_TEST(map_tests, ) UNORDERED_TEST(map_insert_range_test1, - ((test_map)(test_multimap)) + ((test_multimap_std_alloc)(test_map)(test_multimap)) ((default_generator)(generate_collisions)) ) UNORDERED_TEST(map_insert_range_test2, - ((test_map)(test_multimap)) + ((test_multimap_std_alloc)(test_map)(test_multimap)) ((default_generator)(generate_collisions)) ) diff --git a/test/unordered/move_tests.cpp b/test/unordered/move_tests.cpp index 164eb88d..7a3c84d3 100644 --- a/test/unordered/move_tests.cpp +++ b/test/unordered/move_tests.cpp @@ -316,18 +316,22 @@ namespace move_tests } } - boost::unordered_set >* test_set; - boost::unordered_multiset >* test_multiset; boost::unordered_map >* test_map; + std::allocator >* test_map_std_alloc; + + boost::unordered_set >* test_set; + boost::unordered_multiset >* test_multiset; + boost::unordered_map >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator2 >* test_multimap; boost::unordered_set >* test_set; -boost::unordered_multiset >* test_multiset; boost::unordered_map >* test_map; + std::allocator >* test_map_std_alloc; + +boost::unordered_set >* test_set; +boost::unordered_multiset >* test_multiset; +boost::unordered_map >* test_map; boost::unordered_multimap >* test_multimap; + test::allocator2 >* test_multimap; boost::unordered_set