ptr_unordered_set.hpp 8.2 KB

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