ptr_unordered_set.hpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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_SET_HPP
  12. #define BOOST_PTR_CONTAINER_PTR_UNORDERED_SET_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/ptr_container/indirect_fun.hpp>
  17. #include <boost/ptr_container/ptr_set_adapter.hpp>
  18. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  19. #include <boost/unordered_set.hpp>
  20. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  21. #pragma GCC diagnostic push
  22. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  23. #endif
  24. namespace boost
  25. {
  26. template
  27. <
  28. class Key,
  29. class Hash = boost::hash<Key>,
  30. class Pred = std::equal_to<Key>,
  31. class CloneAllocator = heap_clone_allocator,
  32. class Allocator = std::allocator< typename ptr_container_detail::void_ptr<Key>::type >
  33. >
  34. class ptr_unordered_set :
  35. public ptr_set_adapter< Key, boost::unordered_set<
  36. typename ptr_container_detail::void_ptr<Key>::type,
  37. void_ptr_indirect_fun<Hash,Key>,
  38. void_ptr_indirect_fun<Pred,Key>,Allocator>,
  39. CloneAllocator, false >
  40. {
  41. typedef ptr_set_adapter< Key, boost::unordered_set<
  42. typename ptr_container_detail::void_ptr<Key>::type,
  43. void_ptr_indirect_fun<Hash,Key>,
  44. void_ptr_indirect_fun<Pred,Key>,Allocator>,
  45. CloneAllocator, false >
  46. base_type;
  47. typedef ptr_unordered_set<Key,Hash,Pred,CloneAllocator,Allocator> this_type;
  48. public:
  49. typedef typename base_type::size_type size_type;
  50. private:
  51. using base_type::lower_bound;
  52. using base_type::upper_bound;
  53. using base_type::rbegin;
  54. using base_type::rend;
  55. using base_type::crbegin;
  56. using base_type::crend;
  57. using base_type::key_comp;
  58. using base_type::value_comp;
  59. using base_type::front;
  60. using base_type::back;
  61. public:
  62. using base_type::begin;
  63. using base_type::end;
  64. using base_type::cbegin;
  65. using base_type::cend;
  66. using base_type::bucket_count;
  67. using base_type::max_bucket_count;
  68. using base_type::bucket_size;
  69. using base_type::bucket;
  70. using base_type::load_factor;
  71. using base_type::max_load_factor;
  72. using base_type::rehash;
  73. using base_type::key_eq;
  74. using base_type::hash_function;
  75. public:
  76. ptr_unordered_set()
  77. {}
  78. explicit ptr_unordered_set( size_type n )
  79. : base_type( n, ptr_container_detail::unordered_associative_container_tag() )
  80. { }
  81. ptr_unordered_set( size_type n,
  82. const Hash& comp,
  83. const Pred& pred = Pred(),
  84. const Allocator& a = Allocator() )
  85. : base_type( n, comp, pred, a )
  86. { }
  87. template< typename InputIterator >
  88. ptr_unordered_set( InputIterator first, InputIterator last )
  89. : base_type( first, last )
  90. { }
  91. template< typename InputIterator >
  92. ptr_unordered_set( InputIterator first, InputIterator last,
  93. const Hash& comp,
  94. const Pred& pred = Pred(),
  95. const Allocator& a = Allocator() )
  96. : base_type( first, last, comp, pred, a )
  97. { }
  98. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_unordered_set,
  99. base_type,
  100. this_type )
  101. BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_unordered_set,
  102. base_type )
  103. };
  104. template
  105. <
  106. class Key,
  107. class Hash = boost::hash<Key>,
  108. class Pred = std::equal_to<Key>,
  109. class CloneAllocator = heap_clone_allocator,
  110. class Allocator = std::allocator<void*>
  111. >
  112. class ptr_unordered_multiset :
  113. public ptr_multiset_adapter< Key,
  114. boost::unordered_multiset<void*,void_ptr_indirect_fun<Hash,Key>,
  115. void_ptr_indirect_fun<Pred,Key>,Allocator>,
  116. CloneAllocator, false >
  117. {
  118. typedef ptr_multiset_adapter< Key,
  119. boost::unordered_multiset<void*,void_ptr_indirect_fun<Hash,Key>,
  120. void_ptr_indirect_fun<Pred,Key>,Allocator>,
  121. CloneAllocator, false >
  122. base_type;
  123. typedef ptr_unordered_multiset<Key,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_multiset()
  153. { }
  154. explicit ptr_unordered_multiset( size_type n )
  155. : base_type( n, ptr_container_detail::unordered_associative_container_tag() )
  156. { }
  157. ptr_unordered_multiset( 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_multiset( InputIterator first, InputIterator last )
  165. : base_type( first, last )
  166. { }
  167. template< typename InputIterator >
  168. ptr_unordered_multiset( 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_multiset,
  175. base_type,
  176. this_type )
  177. BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_unordered_multiset,
  178. base_type )
  179. };
  180. /////////////////////////////////////////////////////////////////////////
  181. // clonability
  182. template< typename K, typename H, typename P, typename CA, typename A >
  183. inline ptr_unordered_set<K,H,P,CA,A>*
  184. new_clone( const ptr_unordered_set<K,H,P,CA,A>& r )
  185. {
  186. return r.clone().release();
  187. }
  188. template< typename K, typename H, typename P, typename CA, typename A >
  189. inline ptr_unordered_multiset<K,H,P,CA,A>*
  190. new_clone( const ptr_unordered_multiset<K,H,P,CA,A>& r )
  191. {
  192. return r.clone().release();
  193. }
  194. /////////////////////////////////////////////////////////////////////////
  195. // swap
  196. template< typename K, typename H, typename P, typename CA, typename A >
  197. inline void swap( ptr_unordered_set<K,H,P,CA,A>& l,
  198. ptr_unordered_set<K,H,P,CA,A>& r )
  199. {
  200. l.swap(r);
  201. }
  202. template< typename K, typename H, typename P, typename CA, typename A >
  203. inline void swap( ptr_unordered_multiset<K,H,P,CA,A>& l,
  204. ptr_unordered_multiset<K,H,P,CA,A>& r )
  205. {
  206. l.swap(r);
  207. }
  208. }
  209. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  210. #pragma GCC diagnostic pop
  211. #endif
  212. #endif