| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-18 20:00:59 +00:00
										 |  |  | // Copyright 2006-2007 Daniel James.
 | 
					
						
							| 
									
										
										
										
											2006-07-01 22:31:26 +00:00
										 |  |  | // Distributed under the Boost Software License, Version 1.0. (See accompanying
 | 
					
						
							|  |  |  | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_UNORDERED_TEST_OBJECTS_HEADER)
 | 
					
						
							|  |  |  | #define BOOST_UNORDERED_TEST_OBJECTS_HEADER
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | #include <boost/limits.hpp>
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | #include <cstddef>
 | 
					
						
							|  |  |  | #include "../helpers/fwd.hpp"
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Note that the default hash function will work for any equal_to (but not
 | 
					
						
							|  |  |  |     // very well).
 | 
					
						
							|  |  |  |     class object; | 
					
						
							|  |  |  |     class hash; | 
					
						
							|  |  |  |     class less; | 
					
						
							|  |  |  |     class equal_to; | 
					
						
							|  |  |  |     template <class T> class allocator; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class object | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         friend class hash; | 
					
						
							|  |  |  |         friend class equal_to; | 
					
						
							|  |  |  |         friend class less; | 
					
						
							|  |  |  |         int tag1_, tag2_; | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         explicit object(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-31 22:19:26 +00:00
										 |  |  |         ~object() { | 
					
						
							|  |  |  |             tag1_ = -1; | 
					
						
							|  |  |  |             tag2_ = -1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         friend bool operator==(object const& x1, object const& x2) { | 
					
						
							|  |  |  |             return x1.tag1_ == x2.tag1_ && x1.tag2_ == x2.tag2_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator!=(object const& x1, object const& x2) { | 
					
						
							|  |  |  |             return x1.tag1_ != x2.tag1_ || x1.tag2_ != x2.tag2_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator<(object const& x1, object const& x2) { | 
					
						
							|  |  |  |             return x1.tag1_ < x2.tag1_ || | 
					
						
							|  |  |  |                 (x1.tag1_ == x2.tag1_ && x1.tag2_ < x2.tag2_); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend object generate(object const*) { | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  |             int* x = 0; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |             return object(generate(x), generate(x)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend std::ostream& operator<<(std::ostream& out, object const& o) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return out<<"("<<o.tag1_<<","<<o.tag2_<<")"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-17 23:17:21 +00:00
										 |  |  |     // This object is usd to test how well the containers cope with equivalent keys.
 | 
					
						
							|  |  |  |     class equivalent_object | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         friend class hash; | 
					
						
							|  |  |  |         friend class equal_to; | 
					
						
							|  |  |  |         friend class less; | 
					
						
							|  |  |  |         int tag1_, tag2_; | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         explicit equivalent_object(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ~equivalent_object() { | 
					
						
							|  |  |  |             tag1_ = -1; | 
					
						
							|  |  |  |             tag2_ = -1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator==(equivalent_object const& x1, equivalent_object const& x2) { | 
					
						
							|  |  |  |             return x1.tag1_ == x2.tag1_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator!=(equivalent_object const& x1, equivalent_object const& x2) { | 
					
						
							|  |  |  |             return x1.tag1_ != x2.tag1_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator<(equivalent_object const& x1, equivalent_object const& x2) { | 
					
						
							|  |  |  |             return x1.tag1_ < x2.tag1_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend equivalent_object generate(equivalent_object const*) { | 
					
						
							|  |  |  |             signed char* x = 0; | 
					
						
							|  |  |  |             return equivalent_object(generate(x), generate(x)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend std::ostream& operator<<(std::ostream& out, equivalent_object const& o) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return out<<"("<<o.tag1_<<","<<o.tag2_<<")"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     class hash | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int type_; | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         explicit hash(int t = 0) : type_(t) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         std::size_t operator()(object const& x) const { | 
					
						
							|  |  |  |             switch(type_) { | 
					
						
							|  |  |  |             case 1: | 
					
						
							|  |  |  |                 return x.tag1_; | 
					
						
							|  |  |  |             case 2: | 
					
						
							|  |  |  |                 return x.tag2_; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 return x.tag1_ + x.tag2_;  | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-17 23:17:21 +00:00
										 |  |  |         std::size_t operator()(equivalent_object const& x) const { | 
					
						
							|  |  |  |             return x.tag1_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         std::size_t operator()(int x) const { | 
					
						
							|  |  |  |             return x; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator==(hash const& x1, hash const& x2) { | 
					
						
							|  |  |  |             return x1.type_ == x2.type_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator!=(hash const& x1, hash const& x2) { | 
					
						
							|  |  |  |             return x1.type_ != x2.type_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class less | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int type_; | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         explicit less(int t = 0) : type_(t) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bool operator()(object const& x1, object const& x2) const { | 
					
						
							|  |  |  |             switch(type_) { | 
					
						
							|  |  |  |             case 1: | 
					
						
							|  |  |  |                 return x1.tag1_ < x2.tag1_; | 
					
						
							|  |  |  |             case 2: | 
					
						
							|  |  |  |                 return x1.tag2_ < x2.tag2_; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 return x1 < x2; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-17 23:17:21 +00:00
										 |  |  |         bool operator()(equivalent_object const& x1, equivalent_object const& x2) const { | 
					
						
							|  |  |  |             return x1 < x2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         std::size_t operator()(int x1, int x2) const { | 
					
						
							|  |  |  |             return x1 < x2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator==(less const& x1, less const& x2) { | 
					
						
							|  |  |  |             return x1.type_ == x2.type_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class equal_to | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int type_; | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         explicit equal_to(int t = 0) : type_(t) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bool operator()(object const& x1, object const& x2) const { | 
					
						
							|  |  |  |             switch(type_) { | 
					
						
							|  |  |  |             case 1: | 
					
						
							|  |  |  |                 return x1.tag1_ == x2.tag1_; | 
					
						
							|  |  |  |             case 2: | 
					
						
							|  |  |  |                 return x1.tag2_ == x2.tag2_; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 return x1 == x2; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-17 23:17:21 +00:00
										 |  |  |         bool operator()(equivalent_object const& x1, equivalent_object const& x2) const { | 
					
						
							|  |  |  |             return x1 == x2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         std::size_t operator()(int x1, int x2) const { | 
					
						
							|  |  |  |             return x1 == x2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator==(equal_to const& x1, equal_to const& x2) { | 
					
						
							|  |  |  |             return x1.type_ == x2.type_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend bool operator!=(equal_to const& x1, equal_to const& x2) { | 
					
						
							|  |  |  |             return x1.type_ != x2.type_; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         friend less create_compare(equal_to x) { | 
					
						
							|  |  |  |             return less(x.type_); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |     namespace detail | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2006-12-03 23:08:17 +00:00
										 |  |  |         // This annoymous namespace won't cause ODR violations as I won't
 | 
					
						
							|  |  |  |         // be linking multiple translation units together. I'll probably
 | 
					
						
							|  |  |  |         // move this into a cpp file before a full release, but for now it's
 | 
					
						
							|  |  |  |         // the most convenient way.
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |         namespace { | 
					
						
							|  |  |  |             struct memory_area { | 
					
						
							|  |  |  |                 void const* start; | 
					
						
							|  |  |  |                 void const* end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 memory_area(void const* s, void const* e) | 
					
						
							|  |  |  |                     : start(s), end(e) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |                     BOOST_ASSERT(start != end); | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             struct memory_track { | 
					
						
							|  |  |  |                 explicit memory_track(int tag = -1) : | 
					
						
							|  |  |  |                     constructed_(0), | 
					
						
							|  |  |  |                     tag_(tag) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 int constructed_; | 
					
						
							|  |  |  |                 int tag_; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |             // This is a bit dodgy as it defines overlapping
 | 
					
						
							|  |  |  |             // areas as 'equal', so this isn't a total ordering.
 | 
					
						
							|  |  |  |             // But it is for non-overlapping memory regions - which
 | 
					
						
							|  |  |  |             // is what'll be stored.
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // All searches will be for areas entirely contained by
 | 
					
						
							|  |  |  |             // a member of the set - so it should find the area that contains
 | 
					
						
							|  |  |  |             // the region that is searched for.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             struct memory_area_compare { | 
					
						
							|  |  |  |                 bool operator()(memory_area const& x, memory_area const& y) const { | 
					
						
							|  |  |  |                     return x.end <= y.start; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             typedef std::map<memory_area, memory_track, memory_area_compare> allocated_memory_type; | 
					
						
							| 
									
										
										
										
											2006-12-03 23:08:17 +00:00
										 |  |  |             allocated_memory_type allocated_memory; | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             unsigned int count_allocators = 0; | 
					
						
							|  |  |  |             unsigned int count_allocations = 0; | 
					
						
							|  |  |  |             unsigned int count_constructions = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void allocator_ref() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if(count_allocators == 0) { | 
					
						
							|  |  |  |                 count_allocations = 0; | 
					
						
							|  |  |  |                 count_constructions = 0; | 
					
						
							|  |  |  |                 allocated_memory.clear(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ++count_allocators; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void allocator_unref() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             BOOST_TEST(count_allocators > 0); | 
					
						
							|  |  |  |             if(count_allocators > 0) { | 
					
						
							|  |  |  |                 --count_allocators; | 
					
						
							|  |  |  |                 if(count_allocators == 0) { | 
					
						
							|  |  |  |                     bool no_allocations_left = (count_allocations == 0); | 
					
						
							|  |  |  |                     bool no_constructions_left = (count_constructions == 0); | 
					
						
							|  |  |  |                     bool allocated_memory_empty = allocated_memory.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     // Clearing the data before the checks terminate the tests.
 | 
					
						
							|  |  |  |                     count_allocations = 0; | 
					
						
							|  |  |  |                     count_constructions = 0; | 
					
						
							|  |  |  |                     allocated_memory.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     BOOST_TEST(no_allocations_left); | 
					
						
							|  |  |  |                     BOOST_TEST(no_constructions_left); | 
					
						
							|  |  |  |                     BOOST_TEST(allocated_memory_empty); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void track_allocate(void *ptr, std::size_t n, std::size_t size, int tag) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if(n == 0) { | 
					
						
							| 
									
										
										
										
											2006-10-31 22:19:26 +00:00
										 |  |  |                 BOOST_ERROR("Allocating 0 length array."); | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 ++count_allocations; | 
					
						
							|  |  |  |                 allocated_memory[memory_area(ptr, (char*) ptr + n * size)] = | 
					
						
							|  |  |  |                     memory_track(tag); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2006-12-03 23:08:17 +00:00
										 |  |  |             allocated_memory_type::iterator pos | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |                 = allocated_memory.find(memory_area(ptr, (char*) ptr + n)); | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             if(pos == allocated_memory.end()) { | 
					
						
							|  |  |  |                 BOOST_ERROR("Deallocating unknown pointer."); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 BOOST_TEST(pos->first.start == ptr); | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |                 BOOST_TEST(pos->first.end == (char*) ptr + n * size - 1); | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |                 BOOST_TEST(pos->second.tag_ == tag); | 
					
						
							|  |  |  |                 BOOST_TEST(pos->second.constructed_ == 0); | 
					
						
							|  |  |  |                 allocated_memory.erase(pos); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             BOOST_TEST(count_allocations > 0); | 
					
						
							|  |  |  |             if(count_allocations > 0) --count_allocations; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |         void track_construct(void* ptr, std::size_t size, int tag) | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2006-12-03 23:08:17 +00:00
										 |  |  |             allocated_memory_type::iterator pos | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |                 = allocated_memory.find(memory_area(ptr, (char*) ptr + size)); | 
					
						
							| 
									
										
										
										
											2008-01-07 20:06:15 +00:00
										 |  |  |             if(pos == allocated_memory.end()) { | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |                 BOOST_ERROR("Constructing unknown pointer."); | 
					
						
							| 
									
										
										
										
											2008-01-07 20:06:15 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 BOOST_TEST(pos->second.tag_ == tag); | 
					
						
							|  |  |  |                 ++pos->second.constructed_; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             ++count_constructions; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |         void track_destroy(void* ptr, std::size_t size, int tag) | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2006-12-03 23:08:17 +00:00
										 |  |  |             allocated_memory_type::iterator pos | 
					
						
							| 
									
										
										
										
											2008-01-07 21:05:42 +00:00
										 |  |  |                 = allocated_memory.find(memory_area(ptr, (char*) ptr + size)); | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             if(pos == allocated_memory.end()) | 
					
						
							|  |  |  |                 BOOST_ERROR("Destroying unknown pointer."); | 
					
						
							| 
									
										
										
										
											2008-01-07 20:06:15 +00:00
										 |  |  |             else { | 
					
						
							|  |  |  |                 BOOST_TEST(pos->second.tag_ == tag); | 
					
						
							|  |  |  |                 BOOST_TEST(pos->second.constructed_ > 0); | 
					
						
							|  |  |  |                 if(pos->second.constructed_ > 0) --pos->second.constructed_; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             BOOST_TEST(count_constructions > 0); | 
					
						
							|  |  |  |             if(count_constructions > 0) --count_constructions; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     template <class T> | 
					
						
							|  |  |  |     class allocator | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  | # ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  | # else
 | 
					
						
							|  |  |  |         template <class> friend class allocator; | 
					
						
							|  |  |  | # endif
 | 
					
						
							|  |  |  |         int tag_; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |     public: | 
					
						
							|  |  |  |         typedef std::size_t size_type; | 
					
						
							|  |  |  |         typedef std::ptrdiff_t difference_type; | 
					
						
							|  |  |  |         typedef T* pointer; | 
					
						
							|  |  |  |         typedef T const* const_pointer; | 
					
						
							|  |  |  |         typedef T& reference; | 
					
						
							|  |  |  |         typedef T const& const_reference; | 
					
						
							|  |  |  |         typedef T value_type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         template <class U> struct rebind { typedef allocator<U> other; }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |         explicit allocator(int t = 0) : tag_(t) { detail::allocator_ref(); } | 
					
						
							|  |  |  |         template <class Y> allocator(allocator<Y> const& x) : tag_(x.tag_) { detail::allocator_ref(); } | 
					
						
							|  |  |  |         allocator(allocator const& x) : tag_(x.tag_) { detail::allocator_ref(); } | 
					
						
							|  |  |  |         ~allocator() { detail::allocator_unref(); } | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         pointer address(reference r) { return pointer(&r); } | 
					
						
							|  |  |  |         const_pointer address(const_reference r) { return const_pointer(&r); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pointer allocate(size_type n) { | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             pointer ptr(static_cast<T*>(::operator new(n * sizeof(T)))); | 
					
						
							|  |  |  |             detail::track_allocate((void*) ptr, n, sizeof(T), tag_); | 
					
						
							|  |  |  |             return ptr; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pointer allocate(size_type n, const_pointer u) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             pointer ptr(static_cast<T*>(::operator new(n * sizeof(T)))); | 
					
						
							|  |  |  |             detail::track_allocate((void*) ptr, n, sizeof(T), tag_); | 
					
						
							|  |  |  |             return ptr; | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void deallocate(pointer p, size_type n) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |             detail::track_deallocate((void*) p, n, sizeof(T), tag_); | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  |             ::operator delete((void*) p); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-11 19:42:55 +00:00
										 |  |  |         void construct(pointer p, T const& t) { | 
					
						
							|  |  |  |             detail::track_construct((void*) p, sizeof(T), tag_); | 
					
						
							|  |  |  |             new(p) T(t); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void destroy(pointer p) { | 
					
						
							|  |  |  |             detail::track_destroy((void*) p, sizeof(T), tag_); | 
					
						
							|  |  |  |             p->~T(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |         size_type max_size() const { | 
					
						
							|  |  |  |             return (std::numeric_limits<size_type>::max)(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-18 13:24:38 +00:00
										 |  |  |         bool operator==(allocator const& x) const | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return tag_ == x.tag_; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-18 13:24:38 +00:00
										 |  |  |         bool operator!=(allocator const& x) const | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2006-06-18 13:24:38 +00:00
										 |  |  |             return tag_ != x.tag_; | 
					
						
							| 
									
										
										
										
											2006-05-21 17:14:11 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2006-12-03 23:08:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  |     template <class T> | 
					
						
							| 
									
										
										
										
											2006-06-18 13:24:38 +00:00
										 |  |  |     bool equivalent_impl(allocator<T> const& x, allocator<T> const& y, test::derived_type) { | 
					
						
							|  |  |  |         return x == y; | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-07-17 23:17:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if BOOST_WORKAROUND(__GNUC__, < 3)
 | 
					
						
							|  |  |  |     void swap(test::object& x, test::object& y) { | 
					
						
							|  |  |  |         test::object tmp; | 
					
						
							|  |  |  |         tmp = x; | 
					
						
							|  |  |  |         x = y; | 
					
						
							|  |  |  |         y = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void swap(test::equivalent_object& x, test::equivalent_object& y) { | 
					
						
							|  |  |  |         test::equivalent_object tmp; | 
					
						
							|  |  |  |         tmp = x; | 
					
						
							|  |  |  |         x = y; | 
					
						
							|  |  |  |         y = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void swap(test::hash& x, test::hash& y) { | 
					
						
							|  |  |  |         test::hash tmp; | 
					
						
							|  |  |  |         tmp = x; | 
					
						
							|  |  |  |         x = y; | 
					
						
							|  |  |  |         y = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void swap(test::less& x, test::less& y) { | 
					
						
							|  |  |  |         test::less tmp; | 
					
						
							|  |  |  |         tmp = x; | 
					
						
							|  |  |  |         x = y; | 
					
						
							|  |  |  |         y = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void swap(test::equal_to& x, test::equal_to& y) { | 
					
						
							|  |  |  |         test::equal_to tmp; | 
					
						
							|  |  |  |         tmp = x; | 
					
						
							|  |  |  |         x = y; | 
					
						
							|  |  |  |         y = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class T> | 
					
						
							|  |  |  |     void swap(test::allocator<T>& x, test::allocator<T>& y) { | 
					
						
							|  |  |  |         test::allocator<T> tmp; | 
					
						
							|  |  |  |         tmp = x; | 
					
						
							|  |  |  |         x = y; | 
					
						
							|  |  |  |         y = tmp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-06-12 23:30:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-17 17:19:16 +00:00
										 |  |  | #endif
 |