ptr_unordered_map.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // Boost.Pointer Container
  3. //
  4. // Copyright Thorsten Ottosen 2008. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/ptr_container/
  10. //
  11. #ifndef BOOST_PTR_CONTAINER_PTR_UNORDERED_MAP_HPP
  12. #define BOOST_PTR_CONTAINER_PTR_UNORDERED_MAP_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/unordered_map.hpp>
  17. #include <boost/ptr_container/ptr_map_adapter.hpp>
  18. namespace boost
  19. {
  20. template
  21. <
  22. class Key,
  23. class T,
  24. class Hash = boost::hash<Key>,
  25. class Pred = std::equal_to<Key>,
  26. class CloneAllocator = heap_clone_allocator,
  27. class Allocator = std::allocator< std::pair<const Key,void*> >
  28. >
  29. class ptr_unordered_map :
  30. public ptr_map_adapter<T,boost::unordered_map<Key,void*,Hash,Pred,Allocator>,
  31. CloneAllocator,false>
  32. {
  33. typedef ptr_map_adapter<T,boost::unordered_map<Key,void*,Hash,Pred,Allocator>,
  34. CloneAllocator,false>
  35. base_type;
  36. typedef ptr_unordered_map<Key,T,Hash,Pred,CloneAllocator,Allocator> this_type;
  37. public:
  38. typedef typename base_type::size_type size_type;
  39. private:
  40. using base_type::lower_bound;
  41. using base_type::upper_bound;
  42. using base_type::rbegin;
  43. using base_type::rend;
  44. using base_type::crbegin;
  45. using base_type::crend;
  46. using base_type::key_comp;
  47. using base_type::value_comp;
  48. using base_type::front;
  49. using base_type::back;
  50. public:
  51. using base_type::begin;
  52. using base_type::end;
  53. using base_type::cbegin;
  54. using base_type::cend;
  55. using base_type::bucket_count;
  56. using base_type::max_bucket_count;
  57. using base_type::bucket_size;
  58. using base_type::bucket;
  59. using base_type::load_factor;
  60. using base_type::max_load_factor;
  61. using base_type::rehash;
  62. using base_type::key_eq;
  63. using base_type::hash_function;
  64. public:
  65. ptr_unordered_map()
  66. { }
  67. explicit ptr_unordered_map( size_type n )
  68. : base_type( n, ptr_container_detail::unordered_associative_container_tag() )
  69. { }
  70. ptr_unordered_map( size_type n,
  71. const Hash& comp,
  72. const Pred& pred = Pred(),
  73. const Allocator& a = Allocator() )
  74. : base_type( n, comp, pred, a )
  75. { }
  76. template< typename InputIterator >
  77. ptr_unordered_map( InputIterator first, InputIterator last )
  78. : base_type( first, last )
  79. { }
  80. template< typename InputIterator >
  81. ptr_unordered_map( InputIterator first, InputIterator last,
  82. const Hash& comp,
  83. const Pred& pred = Pred(),
  84. const Allocator& a = Allocator() )
  85. : base_type( first, last, comp, pred, a )
  86. { }
  87. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_map,
  88. base_type,
  89. this_type )
  90. template< class U >
  91. ptr_unordered_map( const ptr_unordered_map<Key,U>& r ) : base_type( r )
  92. { }
  93. ptr_unordered_map& operator=( ptr_unordered_map r )
  94. {
  95. this->swap( r );
  96. return *this;
  97. }
  98. };
  99. template
  100. <
  101. class Key,
  102. class T,
  103. class Hash = boost::hash<Key>,
  104. class Pred = std::equal_to<Key>,
  105. class CloneAllocator = heap_clone_allocator,
  106. class Allocator = std::allocator< std::pair<const Key,void*> >
  107. >
  108. class ptr_unordered_multimap :
  109. public ptr_multimap_adapter<T,boost::unordered_multimap<Key,void*,Hash,Pred,Allocator>,
  110. CloneAllocator,false>
  111. {
  112. typedef ptr_multimap_adapter<T,boost::unordered_multimap<Key,void*,Hash,Pred,Allocator>,
  113. CloneAllocator,false>
  114. base_type;
  115. typedef ptr_unordered_multimap<Key,T,Hash,Pred,CloneAllocator,Allocator> this_type;
  116. public:
  117. typedef typename base_type::size_type size_type;
  118. private:
  119. using base_type::lower_bound;
  120. using base_type::upper_bound;
  121. using base_type::rbegin;
  122. using base_type::rend;
  123. using base_type::crbegin;
  124. using base_type::crend;
  125. using base_type::key_comp;
  126. using base_type::value_comp;
  127. using base_type::front;
  128. using base_type::back;
  129. public:
  130. using base_type::begin;
  131. using base_type::end;
  132. using base_type::cbegin;
  133. using base_type::cend;
  134. using base_type::bucket_count;
  135. using base_type::max_bucket_count;
  136. using base_type::bucket_size;
  137. using base_type::bucket;
  138. using base_type::load_factor;
  139. using base_type::max_load_factor;
  140. using base_type::rehash;
  141. using base_type::key_eq;
  142. using base_type::hash_function;
  143. public:
  144. ptr_unordered_multimap()
  145. { }
  146. explicit ptr_unordered_multimap( size_type n )
  147. : base_type( n, ptr_container_detail::unordered_associative_container_tag() )
  148. { }
  149. ptr_unordered_multimap( size_type n,
  150. const Hash& comp,
  151. const Pred& pred = Pred(),
  152. const Allocator& a = Allocator() )
  153. : base_type( n, comp, pred, a )
  154. { }
  155. template< typename InputIterator >
  156. ptr_unordered_multimap( InputIterator first, InputIterator last )
  157. : base_type( first, last )
  158. { }
  159. template< typename InputIterator >
  160. ptr_unordered_multimap( InputIterator first, InputIterator last,
  161. const Hash& comp,
  162. const Pred& pred = Pred(),
  163. const Allocator& a = Allocator() )
  164. : base_type( first, last, comp, pred, a )
  165. { }
  166. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_multimap,
  167. base_type,
  168. this_type )
  169. template< class U >
  170. ptr_unordered_multimap( const ptr_unordered_multimap<Key,U>& r ) : base_type( r )
  171. { }
  172. ptr_unordered_multimap& operator=( ptr_unordered_multimap r )
  173. {
  174. this->swap( r );
  175. return *this;
  176. }
  177. };
  178. //////////////////////////////////////////////////////////////////////////////
  179. // clonability
  180. template< class K, class T, class H, class P, class CA, class A >
  181. inline ptr_unordered_map<K,T,H,P,CA,A>*
  182. new_clone( const ptr_unordered_map<K,T,H,P,CA,A>& r )
  183. {
  184. return r.clone().release();
  185. }
  186. template< class K, class T, class H, class P, class CA, class A >
  187. inline ptr_unordered_multimap<K,T,H,P,CA,A>*
  188. new_clone( const ptr_unordered_multimap<K,T,H,P,CA,A>& r )
  189. {
  190. return r.clone().release();
  191. }
  192. /////////////////////////////////////////////////////////////////////////
  193. // swap
  194. template< class K, class T, class H, class P, class CA, class A >
  195. inline void swap( ptr_unordered_map<K,T,H,P,CA,A>& l,
  196. ptr_unordered_map<K,T,H,P,CA,A>& r )
  197. {
  198. l.swap(r);
  199. }
  200. template< class K, class T, class H, class P, class CA, class A >
  201. inline void swap( ptr_unordered_multimap<K,T,H,P,CA,A>& l,
  202. ptr_unordered_multimap<K,T,H,P,CA,A>& r )
  203. {
  204. l.swap(r);
  205. }
  206. }
  207. #endif