ptr_unordered_map.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  19. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  20. #pragma GCC diagnostic push
  21. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  22. #endif
  23. namespace boost
  24. {
  25. template
  26. <
  27. class Key,
  28. class T,
  29. class Hash = boost::hash<Key>,
  30. class Pred = std::equal_to<Key>,
  31. class CloneAllocator = heap_clone_allocator,
  32. class Allocator = std::allocator< std::pair<const Key,
  33. typename ptr_container_detail::void_ptr<T>::type> >
  34. >
  35. class ptr_unordered_map :
  36. public ptr_map_adapter<T,boost::unordered_map<Key,
  37. typename ptr_container_detail::void_ptr<T>::type,Hash,Pred,Allocator>,
  38. CloneAllocator,false>
  39. {
  40. typedef ptr_map_adapter<T,boost::unordered_map<Key,
  41. typename ptr_container_detail::void_ptr<T>::type,Hash,Pred,Allocator>,
  42. CloneAllocator,false>
  43. base_type;
  44. typedef ptr_unordered_map<Key,T,Hash,Pred,CloneAllocator,Allocator> this_type;
  45. public:
  46. typedef typename base_type::size_type size_type;
  47. private:
  48. using base_type::lower_bound;
  49. using base_type::upper_bound;
  50. using base_type::rbegin;
  51. using base_type::rend;
  52. using base_type::crbegin;
  53. using base_type::crend;
  54. using base_type::key_comp;
  55. using base_type::value_comp;
  56. using base_type::front;
  57. using base_type::back;
  58. public:
  59. using base_type::begin;
  60. using base_type::end;
  61. using base_type::cbegin;
  62. using base_type::cend;
  63. using base_type::bucket_count;
  64. using base_type::max_bucket_count;
  65. using base_type::bucket_size;
  66. using base_type::bucket;
  67. using base_type::load_factor;
  68. using base_type::max_load_factor;
  69. using base_type::rehash;
  70. using base_type::key_eq;
  71. using base_type::hash_function;
  72. public:
  73. ptr_unordered_map()
  74. { }
  75. explicit ptr_unordered_map( size_type n )
  76. : base_type( n, ptr_container_detail::unordered_associative_container_tag() )
  77. { }
  78. ptr_unordered_map( size_type n,
  79. const Hash& comp,
  80. const Pred& pred = Pred(),
  81. const Allocator& a = Allocator() )
  82. : base_type( n, comp, pred, a )
  83. { }
  84. template< typename InputIterator >
  85. ptr_unordered_map( InputIterator first, InputIterator last )
  86. : base_type( first, last )
  87. { }
  88. template< typename InputIterator >
  89. ptr_unordered_map( InputIterator first, InputIterator last,
  90. const Hash& comp,
  91. const Pred& pred = Pred(),
  92. const Allocator& a = Allocator() )
  93. : base_type( first, last, comp, pred, a )
  94. { }
  95. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_map,
  96. base_type,
  97. this_type )
  98. template< class U >
  99. ptr_unordered_map( const ptr_unordered_map<Key,U>& r ) : base_type( r )
  100. { }
  101. ptr_unordered_map& operator=( ptr_unordered_map r )
  102. {
  103. this->swap( r );
  104. return *this;
  105. }
  106. };
  107. template
  108. <
  109. class Key,
  110. class T,
  111. class Hash = boost::hash<Key>,
  112. class Pred = std::equal_to<Key>,
  113. class CloneAllocator = heap_clone_allocator,
  114. class Allocator = std::allocator< std::pair<const Key,void*> >
  115. >
  116. class ptr_unordered_multimap :
  117. public ptr_multimap_adapter<T,boost::unordered_multimap<Key,void*,Hash,Pred,Allocator>,
  118. CloneAllocator,false>
  119. {
  120. typedef ptr_multimap_adapter<T,boost::unordered_multimap<Key,void*,Hash,Pred,Allocator>,
  121. CloneAllocator,false>
  122. base_type;
  123. typedef ptr_unordered_multimap<Key,T,Hash,Pred,CloneAllocator,Allocator> this_type;
  124. public:
  125. typedef typename base_type::size_type size_type;
  126. private:
  127. using base_type::lower_bound;
  128. using base_type::upper_bound;
  129. using base_type::rbegin;
  130. using base_type::rend;
  131. using base_type::crbegin;
  132. using base_type::crend;
  133. using base_type::key_comp;
  134. using base_type::value_comp;
  135. using base_type::front;
  136. using base_type::back;
  137. public:
  138. using base_type::begin;
  139. using base_type::end;
  140. using base_type::cbegin;
  141. using base_type::cend;
  142. using base_type::bucket_count;
  143. using base_type::max_bucket_count;
  144. using base_type::bucket_size;
  145. using base_type::bucket;
  146. using base_type::load_factor;
  147. using base_type::max_load_factor;
  148. using base_type::rehash;
  149. using base_type::key_eq;
  150. using base_type::hash_function;
  151. public:
  152. ptr_unordered_multimap()
  153. { }
  154. explicit ptr_unordered_multimap( size_type n )
  155. : base_type( n, ptr_container_detail::unordered_associative_container_tag() )
  156. { }
  157. ptr_unordered_multimap( size_type n,
  158. const Hash& comp,
  159. const Pred& pred = Pred(),
  160. const Allocator& a = Allocator() )
  161. : base_type( n, comp, pred, a )
  162. { }
  163. template< typename InputIterator >
  164. ptr_unordered_multimap( InputIterator first, InputIterator last )
  165. : base_type( first, last )
  166. { }
  167. template< typename InputIterator >
  168. ptr_unordered_multimap( InputIterator first, InputIterator last,
  169. const Hash& comp,
  170. const Pred& pred = Pred(),
  171. const Allocator& a = Allocator() )
  172. : base_type( first, last, comp, pred, a )
  173. { }
  174. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_multimap,
  175. base_type,
  176. this_type )
  177. template< class U >
  178. ptr_unordered_multimap( const ptr_unordered_multimap<Key,U>& r ) : base_type( r )
  179. { }
  180. ptr_unordered_multimap& operator=( ptr_unordered_multimap r )
  181. {
  182. this->swap( r );
  183. return *this;
  184. }
  185. };
  186. //////////////////////////////////////////////////////////////////////////////
  187. // clonability
  188. template< class K, class T, class H, class P, class CA, class A >
  189. inline ptr_unordered_map<K,T,H,P,CA,A>*
  190. new_clone( const ptr_unordered_map<K,T,H,P,CA,A>& r )
  191. {
  192. return r.clone().release();
  193. }
  194. template< class K, class T, class H, class P, class CA, class A >
  195. inline ptr_unordered_multimap<K,T,H,P,CA,A>*
  196. new_clone( const ptr_unordered_multimap<K,T,H,P,CA,A>& r )
  197. {
  198. return r.clone().release();
  199. }
  200. /////////////////////////////////////////////////////////////////////////
  201. // swap
  202. template< class K, class T, class H, class P, class CA, class A >
  203. inline void swap( ptr_unordered_map<K,T,H,P,CA,A>& l,
  204. ptr_unordered_map<K,T,H,P,CA,A>& r )
  205. {
  206. l.swap(r);
  207. }
  208. template< class K, class T, class H, class P, class CA, class A >
  209. inline void swap( ptr_unordered_multimap<K,T,H,P,CA,A>& l,
  210. ptr_unordered_multimap<K,T,H,P,CA,A>& r )
  211. {
  212. l.swap(r);
  213. }
  214. }
  215. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  216. #pragma GCC diagnostic pop
  217. #endif
  218. #endif