unordered_set.hpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Olaf Krzikalla 2004-2006.
  4. // (C) Copyright Ion Gaztanaga 2006-2014
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/intrusive for documentation.
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef BOOST_INTRUSIVE_UNORDERED_SET_HPP
  14. #define BOOST_INTRUSIVE_UNORDERED_SET_HPP
  15. #include <boost/intrusive/detail/config_begin.hpp>
  16. #include <boost/intrusive/intrusive_fwd.hpp>
  17. #include <boost/intrusive/hashtable.hpp>
  18. #include <boost/move/utility_core.hpp>
  19. #if defined(BOOST_HAS_PRAGMA_ONCE)
  20. # pragma once
  21. #endif
  22. namespace boost {
  23. namespace intrusive {
  24. //! The class template unordered_set is an intrusive container, that mimics most of
  25. //! the interface of std::tr1::unordered_set as described in the C++ TR1.
  26. //!
  27. //! unordered_set is a semi-intrusive container: each object to be stored in the
  28. //! container must contain a proper hook, but the container also needs
  29. //! additional auxiliary memory to work: unordered_set needs a pointer to an array
  30. //! of type `bucket_type` to be passed in the constructor. This bucket array must
  31. //! have at least the same lifetime as the container. This makes the use of
  32. //! unordered_set more complicated than purely intrusive containers.
  33. //! `bucket_type` is default-constructible, copyable and assignable
  34. //!
  35. //! The template parameter \c T is the type to be managed by the container.
  36. //! The user can specify additional options and if no options are provided
  37. //! default options are used.
  38. //!
  39. //! The container supports the following options:
  40. //! \c base_hook<>/member_hook<>/value_traits<>,
  41. //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
  42. //! \c bucket_traits<>, \c power_2_buckets<> and \c cache_begin<>.
  43. //!
  44. //! unordered_set only provides forward iterators but it provides 4 iterator types:
  45. //! iterator and const_iterator to navigate through the whole container and
  46. //! local_iterator and const_local_iterator to navigate through the values
  47. //! stored in a single bucket. Local iterators are faster and smaller.
  48. //!
  49. //! It's not recommended to use non constant-time size unordered_sets because several
  50. //! key functions, like "empty()", become non-constant time functions. Non
  51. //! constant-time size unordered_sets are mainly provided to support auto-unlink hooks.
  52. //!
  53. //! unordered_set, unlike std::unordered_set, does not make automatic rehashings nor
  54. //! offers functions related to a load factor. Rehashing can be explicitly requested
  55. //! and the user must provide a new bucket array that will be used from that moment.
  56. //!
  57. //! Since no automatic rehashing is done, iterators are never invalidated when
  58. //! inserting or erasing elements. Iterators are only invalidated when rehasing.
  59. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  60. template<class T, class ...Options>
  61. #else
  62. template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class SizeType, class BucketTraits, std::size_t BoolFlags>
  63. #endif
  64. class unordered_set_impl
  65. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  66. : public hashtable_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual, BucketTraits, SizeType, BoolFlags|hash_bool_flags::unique_keys_pos>
  67. #endif
  68. {
  69. /// @cond
  70. private:
  71. typedef hashtable_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual, BucketTraits, SizeType, BoolFlags|hash_bool_flags::unique_keys_pos> table_type;
  72. template<class Iterator, class MaybeConstThis, class KeyType, class KeyHasher, class KeyEqual>
  73. static std::pair<Iterator,Iterator> priv_equal_range(MaybeConstThis &c, const KeyType& key, KeyHasher hash_func, KeyEqual equal_func)
  74. {
  75. Iterator const it = c.find(key, hash_func, equal_func);
  76. std::pair<Iterator,Iterator> ret(it, it);
  77. if(it != c.end())
  78. ++ret.second;
  79. return ret;
  80. }
  81. //! This class is
  82. //! movable
  83. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_set_impl)
  84. typedef table_type implementation_defined;
  85. /// @endcond
  86. public:
  87. typedef typename implementation_defined::value_type value_type;
  88. typedef typename implementation_defined::key_type key_type;
  89. typedef typename implementation_defined::key_of_value key_of_value;
  90. typedef typename implementation_defined::value_traits value_traits;
  91. typedef typename implementation_defined::bucket_traits bucket_traits;
  92. typedef typename implementation_defined::pointer pointer;
  93. typedef typename implementation_defined::const_pointer const_pointer;
  94. typedef typename implementation_defined::reference reference;
  95. typedef typename implementation_defined::const_reference const_reference;
  96. typedef typename implementation_defined::difference_type difference_type;
  97. typedef typename implementation_defined::size_type size_type;
  98. typedef typename implementation_defined::key_equal key_equal;
  99. typedef typename implementation_defined::hasher hasher;
  100. typedef typename implementation_defined::bucket_type bucket_type;
  101. typedef typename implementation_defined::bucket_ptr bucket_ptr;
  102. typedef typename implementation_defined::iterator iterator;
  103. typedef typename implementation_defined::const_iterator const_iterator;
  104. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  105. typedef typename implementation_defined::local_iterator local_iterator;
  106. typedef typename implementation_defined::const_local_iterator const_local_iterator;
  107. typedef typename implementation_defined::node_traits node_traits;
  108. typedef typename implementation_defined::node node;
  109. typedef typename implementation_defined::node_ptr node_ptr;
  110. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  111. public:
  112. //! @copydoc ::boost::intrusive::hashtable::hashtable(const bucket_traits &,const hasher &,const key_equal &,const value_traits &)
  113. inline explicit unordered_set_impl( const bucket_traits &b_traits
  114. , const hasher & hash_func = hasher()
  115. , const key_equal &equal_func = key_equal()
  116. , const value_traits &v_traits = value_traits())
  117. : table_type(b_traits, hash_func, equal_func, v_traits)
  118. {}
  119. //! @copydoc ::boost::intrusive::hashtable::hashtable(bool,Iterator,Iterator,const bucket_traits &,const hasher &,const key_equal &,const value_traits &)
  120. template<class Iterator>
  121. inline unordered_set_impl( Iterator b
  122. , Iterator e
  123. , const bucket_traits &b_traits
  124. , const hasher & hash_func = hasher()
  125. , const key_equal &equal_func = key_equal()
  126. , const value_traits &v_traits = value_traits())
  127. : table_type(true, b, e, b_traits, hash_func, equal_func, v_traits)
  128. {}
  129. //! @copydoc ::boost::intrusive::hashtable::hashtable(hashtable&&)
  130. inline unordered_set_impl(BOOST_RV_REF(unordered_set_impl) x)
  131. : table_type(BOOST_MOVE_BASE(table_type, x))
  132. {}
  133. //! @copydoc ::boost::intrusive::hashtable::operator=(hashtable&&)
  134. inline unordered_set_impl& operator=(BOOST_RV_REF(unordered_set_impl) x)
  135. { return static_cast<unordered_set_impl&>(table_type::operator=(BOOST_MOVE_BASE(table_type, x))); }
  136. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  137. //! @copydoc ::boost::intrusive::hashtable::~hashtable()
  138. ~unordered_set_impl();
  139. //! @copydoc ::boost::intrusive::hashtable::begin()
  140. iterator begin() BOOST_NOEXCEPT;
  141. //! @copydoc ::boost::intrusive::hashtable::begin()const
  142. const_iterator begin() const BOOST_NOEXCEPT;
  143. //! @copydoc ::boost::intrusive::hashtable::cbegin()const
  144. const_iterator cbegin() const BOOST_NOEXCEPT;
  145. //! @copydoc ::boost::intrusive::hashtable::end()
  146. iterator end() BOOST_NOEXCEPT;
  147. //! @copydoc ::boost::intrusive::hashtable::end()const
  148. const_iterator end() const BOOST_NOEXCEPT;
  149. //! @copydoc ::boost::intrusive::hashtable::cend()const
  150. const_iterator cend() const BOOST_NOEXCEPT;
  151. //! @copydoc ::boost::intrusive::hashtable::hash_function()const
  152. hasher hash_function() const;
  153. //! @copydoc ::boost::intrusive::hashtable::key_eq()const
  154. key_equal key_eq() const;
  155. //! @copydoc ::boost::intrusive::hashtable::empty()const
  156. bool empty() const BOOST_NOEXCEPT;
  157. //! @copydoc ::boost::intrusive::hashtable::size()const
  158. size_type size() const BOOST_NOEXCEPT;
  159. //! @copydoc ::boost::intrusive::hashtable::hashtable
  160. void swap(unordered_set_impl& other);
  161. //! @copydoc ::boost::intrusive::hashtable::clone_from(const hashtable&,Cloner,Disposer)
  162. template <class Cloner, class Disposer>
  163. void clone_from(const unordered_set_impl &src, Cloner cloner, Disposer disposer);
  164. #else
  165. using table_type::clone_from;
  166. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  167. //! @copydoc ::boost::intrusive::hashtable::clone_from(hashtable&&,Cloner,Disposer)
  168. template <class Cloner, class Disposer>
  169. inline void clone_from(BOOST_RV_REF(unordered_set_impl) src, Cloner cloner, Disposer disposer)
  170. { table_type::clone_from(BOOST_MOVE_BASE(table_type, src), cloner, disposer); }
  171. //! @copydoc ::boost::intrusive::hashtable::insert_unique(reference)
  172. inline std::pair<iterator, bool> insert(reference value)
  173. { return table_type::insert_unique(value); }
  174. //! @copydoc ::boost::intrusive::hashtable::insert_unique(Iterator,Iterator)
  175. template<class Iterator>
  176. inline void insert(Iterator b, Iterator e)
  177. { table_type::insert_unique(b, e); }
  178. //! @copydoc ::boost::intrusive::hashtable::insert_unique_check(const key_type&,insert_commit_data&)
  179. inline std::pair<iterator, bool> insert_check(const key_type &key, insert_commit_data &commit_data)
  180. { return table_type::insert_unique_check(key, commit_data); }
  181. //! @copydoc ::boost::intrusive::hashtable::insert_unique_check(const KeyType&,KeyHasher,KeyEqual,insert_commit_data&)
  182. template<class KeyType, class KeyHasher, class KeyEqual>
  183. inline std::pair<iterator, bool> insert_check
  184. (const KeyType &key, KeyHasher hash_func, KeyEqual key_value_equal, insert_commit_data &commit_data)
  185. { return table_type::insert_unique_check(key, hash_func, key_value_equal, commit_data); }
  186. //! @copydoc ::boost::intrusive::hashtable::insert_unique_commit
  187. inline iterator insert_commit(reference value, const insert_commit_data &commit_data) BOOST_NOEXCEPT
  188. { return table_type::insert_unique_commit(value, commit_data); }
  189. //! @copydoc ::boost::intrusive::hashtable::insert_unique_fast_commit
  190. inline iterator insert_fast_commit(reference value, const insert_commit_data &commit_data) BOOST_NOEXCEPT
  191. { return table_type::insert_unique_fast_commit(value, commit_data); }
  192. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  193. //! @copydoc ::boost::intrusive::hashtable::erase(const_iterator)
  194. void erase(const_iterator i);
  195. //! @copydoc ::boost::intrusive::hashtable::erase(const_iterator,const_iterator)
  196. void erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT;
  197. //! @copydoc ::boost::intrusive::hashtable::erase(const key_type &)
  198. size_type erase(const key_type &key);
  199. //! @copydoc ::boost::intrusive::hashtable::erase(const KeyType&,KeyHasher,KeyEqual)
  200. template<class KeyType, class KeyHasher, class KeyEqual>
  201. size_type erase(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func);
  202. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const_iterator,Disposer)
  203. template<class Disposer>
  204. BOOST_INTRUSIVE_DOC1ST(void
  205. , typename detail::disable_if_convertible<Disposer BOOST_INTRUSIVE_I const_iterator>::type)
  206. erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT;
  207. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const_iterator,const_iterator,Disposer)
  208. template<class Disposer>
  209. void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT;
  210. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const key_type &,Disposer)
  211. template<class Disposer>
  212. size_type erase_and_dispose(const key_type &key, Disposer disposer);
  213. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const KeyType&,KeyHasher,KeyEqual,Disposer)
  214. template<class KeyType, class KeyHasher, class KeyEqual, class Disposer>
  215. size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func, Disposer disposer);
  216. //! @copydoc ::boost::intrusive::hashtable::clear
  217. void clear() BOOST_NOEXCEPT;
  218. //! @copydoc ::boost::intrusive::hashtable::clear_and_dispose
  219. template<class Disposer>
  220. void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT;
  221. //! @copydoc ::boost::intrusive::hashtable::count(const key_type &)const
  222. size_type count(const key_type &key) const;
  223. //! @copydoc ::boost::intrusive::hashtable::count(const KeyType&,KeyHasher,KeyEqual)const
  224. template<class KeyType, class KeyHasher, class KeyEqual>
  225. size_type count(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func) const;
  226. //! @copydoc ::boost::intrusive::hashtable::find(const key_type &)
  227. iterator find(const key_type &key);
  228. //! @copydoc ::boost::intrusive::hashtable::find(const KeyType &,KeyHasher,KeyEqual)
  229. template<class KeyType, class KeyHasher, class KeyEqual>
  230. iterator find(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func);
  231. //! @copydoc ::boost::intrusive::hashtable::find(const key_type &)const
  232. const_iterator find(const key_type &key) const;
  233. //! @copydoc ::boost::intrusive::hashtable::find(const KeyType &,KeyHasher,KeyEqual)const
  234. template<class KeyType, class KeyHasher, class KeyEqual>
  235. const_iterator find(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func) const;
  236. #endif
  237. //! @copydoc ::boost::intrusive::hashtable::equal_range(const key_type&)
  238. std::pair<iterator,iterator> equal_range(const key_type &key)
  239. { return this->equal_range(key, this->hash_function(), this->key_eq()); }
  240. //! @copydoc ::boost::intrusive::hashtable::equal_range(const KeyType &,KeyHasher,KeyEqual)
  241. template<class KeyType, class KeyHasher, class KeyEqual>
  242. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func)
  243. { return this->priv_equal_range<iterator>(*this, key, hash_func, equal_func); }
  244. //! @copydoc ::boost::intrusive::hashtable::equal_range(const key_type&)const
  245. std::pair<const_iterator, const_iterator>
  246. equal_range(const key_type &key) const
  247. { return this->equal_range(key, this->hash_function(), this->key_eq()); }
  248. //! @copydoc ::boost::intrusive::hashtable::equal_range(const KeyType &,KeyHasher,KeyEqual)const
  249. template<class KeyType, class KeyHasher, class KeyEqual>
  250. std::pair<const_iterator, const_iterator>
  251. equal_range(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func) const
  252. { return this->priv_equal_range<const_iterator>(*this, key, hash_func, equal_func); }
  253. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  254. //! @copydoc ::boost::intrusive::hashtable::iterator_to(reference)
  255. iterator iterator_to(reference value) BOOST_NOEXCEPT;
  256. //! @copydoc ::boost::intrusive::hashtable::iterator_to(const_reference)const
  257. const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT;
  258. //! @copydoc ::boost::intrusive::hashtable::s_local_iterator_to(reference)
  259. static local_iterator s_local_iterator_to(reference value) BOOST_NOEXCEPT;
  260. //! @copydoc ::boost::intrusive::hashtable::s_local_iterator_to(const_reference)
  261. static const_local_iterator s_local_iterator_to(const_reference value) BOOST_NOEXCEPT;
  262. //! @copydoc ::boost::intrusive::hashtable::local_iterator_to(reference)
  263. local_iterator local_iterator_to(reference value) BOOST_NOEXCEPT;
  264. //! @copydoc ::boost::intrusive::hashtable::local_iterator_to(const_reference)
  265. const_local_iterator local_iterator_to(const_reference value) const BOOST_NOEXCEPT;
  266. //! @copydoc ::boost::intrusive::hashtable::bucket_count
  267. size_type bucket_count() const BOOST_NOEXCEPT;
  268. //! @copydoc ::boost::intrusive::hashtable::bucket_size
  269. size_type bucket_size(size_type n) const BOOST_NOEXCEPT;
  270. //! @copydoc ::boost::intrusive::hashtable::bucket(const key_type&)const
  271. size_type bucket(const key_type& k) const;
  272. //! @copydoc ::boost::intrusive::hashtable::bucket(const KeyType&,KeyHasher)const
  273. template<class KeyType, class KeyHasher>
  274. size_type bucket(const KeyType& k, KeyHasher hash_func) const;
  275. //! @copydoc ::boost::intrusive::hashtable::bucket_pointer
  276. bucket_ptr bucket_pointer() const BOOST_NOEXCEPT;
  277. //! @copydoc ::boost::intrusive::hashtable::begin(size_type)
  278. local_iterator begin(size_type n) BOOST_NOEXCEPT;
  279. //! @copydoc ::boost::intrusive::hashtable::begin(size_type)const
  280. const_local_iterator begin(size_type n) const BOOST_NOEXCEPT;
  281. //! @copydoc ::boost::intrusive::hashtable::cbegin(size_type)const
  282. const_local_iterator cbegin(size_type n) const BOOST_NOEXCEPT;
  283. //! @copydoc ::boost::intrusive::hashtable::end(size_type)
  284. local_iterator end(size_type n) BOOST_NOEXCEPT;
  285. //! @copydoc ::boost::intrusive::hashtable::end(size_type)const
  286. const_local_iterator end(size_type n) const BOOST_NOEXCEPT;
  287. //! @copydoc ::boost::intrusive::hashtable::cend(size_type)const
  288. const_local_iterator cend(size_type n) const BOOST_NOEXCEPT;
  289. //! @copydoc ::boost::intrusive::hashtable::rehash(const bucket_traits &)
  290. void rehash(const bucket_traits &new_bucket_traits);
  291. //! @copydoc ::boost::intrusive::hashtable::full_rehash
  292. void full_rehash();
  293. //! @copydoc ::boost::intrusive::hashtable::incremental_rehash(bool)
  294. bool incremental_rehash(bool grow = true);
  295. //! @copydoc ::boost::intrusive::hashtable::incremental_rehash(const bucket_traits &)
  296. bool incremental_rehash(const bucket_traits &new_bucket_traits);
  297. //! @copydoc ::boost::intrusive::hashtable::split_count
  298. size_type split_count() const BOOST_NOEXCEPT;
  299. //! @copydoc ::boost::intrusive::hashtable::suggested_upper_bucket_count
  300. static size_type suggested_upper_bucket_count(size_type n) BOOST_NOEXCEPT;
  301. //! @copydoc ::boost::intrusive::hashtable::suggested_lower_bucket_count
  302. static size_type suggested_lower_bucket_count(size_type n) BOOST_NOEXCEPT;
  303. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  304. friend bool operator==(const unordered_set_impl &x, const unordered_set_impl &y)
  305. {
  306. if(table_type::constant_time_size && x.size() != y.size()){
  307. return false;
  308. }
  309. //Find each element of x in y
  310. for (const_iterator ix = x.cbegin(), ex = x.cend(), ey = y.cend(); ix != ex; ++ix){
  311. const_iterator iy = y.find(key_of_value()(*ix));
  312. if (iy == ey || !(*ix == *iy))
  313. return false;
  314. }
  315. return true;
  316. }
  317. friend bool operator!=(const unordered_set_impl &x, const unordered_set_impl &y)
  318. { return !(x == y); }
  319. friend bool operator<(const unordered_set_impl &x, const unordered_set_impl &y)
  320. { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  321. friend bool operator>(const unordered_set_impl &x, const unordered_set_impl &y)
  322. { return y < x; }
  323. friend bool operator<=(const unordered_set_impl &x, const unordered_set_impl &y)
  324. { return !(y < x); }
  325. friend bool operator>=(const unordered_set_impl &x, const unordered_set_impl &y)
  326. { return !(x < y); }
  327. };
  328. //! Helper metafunction to define an \c unordered_set that yields to the same type when the
  329. //! same options (either explicitly or implicitly) are used.
  330. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  331. template<class T, class ...Options>
  332. #else
  333. template<class T, class O1 = void, class O2 = void
  334. , class O3 = void, class O4 = void
  335. , class O5 = void, class O6 = void
  336. , class O7 = void, class O8 = void
  337. , class O9 = void, class O10= void
  338. , class O11 = void
  339. >
  340. #endif
  341. struct make_unordered_set
  342. {
  343. /// @cond
  344. typedef typename pack_options
  345. < hashtable_defaults,
  346. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  347. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11
  348. #else
  349. Options...
  350. #endif
  351. >::type packed_options;
  352. typedef typename detail::get_value_traits
  353. <T, typename packed_options::proto_value_traits>::type value_traits;
  354. typedef typename make_bucket_traits
  355. <T, packed_options>::type bucket_traits;
  356. typedef unordered_set_impl
  357. < value_traits
  358. , typename packed_options::key_of_value
  359. , typename packed_options::hash
  360. , typename packed_options::equal
  361. , typename packed_options::size_type
  362. , bucket_traits
  363. , (std::size_t(true)*hash_bool_flags::unique_keys_pos)
  364. | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
  365. | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
  366. | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
  367. | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
  368. | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
  369. | (std::size_t(packed_options::linear_buckets)*hash_bool_flags::linear_buckets_pos)
  370. | (std::size_t(packed_options::fastmod_buckets)*hash_bool_flags::fastmod_buckets_pos)
  371. > implementation_defined;
  372. /// @endcond
  373. typedef implementation_defined type;
  374. };
  375. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  376. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  377. template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10, class O11>
  378. #else
  379. template<class T, class ...Options>
  380. #endif
  381. class unordered_set
  382. : public make_unordered_set<T,
  383. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  384. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11
  385. #else
  386. Options...
  387. #endif
  388. >::type
  389. {
  390. typedef typename make_unordered_set<T,
  391. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  392. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11
  393. #else
  394. Options...
  395. #endif
  396. >::type Base;
  397. //Assert if passed value traits are compatible with the type
  398. BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
  399. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_set)
  400. public:
  401. typedef typename Base::value_traits value_traits;
  402. typedef typename Base::bucket_traits bucket_traits;
  403. typedef typename Base::iterator iterator;
  404. typedef typename Base::const_iterator const_iterator;
  405. typedef typename Base::bucket_ptr bucket_ptr;
  406. typedef typename Base::size_type size_type;
  407. typedef typename Base::hasher hasher;
  408. typedef typename Base::key_equal key_equal;
  409. inline
  410. explicit unordered_set ( const bucket_traits &b_traits
  411. , const hasher & hash_func = hasher()
  412. , const key_equal &equal_func = key_equal()
  413. , const value_traits &v_traits = value_traits())
  414. : Base(b_traits, hash_func, equal_func, v_traits)
  415. {}
  416. template<class Iterator>
  417. inline
  418. unordered_set
  419. ( Iterator b, Iterator e
  420. , const bucket_traits &b_traits
  421. , const hasher & hash_func = hasher()
  422. , const key_equal &equal_func = key_equal()
  423. , const value_traits &v_traits = value_traits())
  424. : Base(b, e, b_traits, hash_func, equal_func, v_traits)
  425. {}
  426. inline unordered_set(BOOST_RV_REF(unordered_set) x)
  427. : Base(BOOST_MOVE_BASE(Base, x))
  428. {}
  429. inline unordered_set& operator=(BOOST_RV_REF(unordered_set) x)
  430. { return static_cast<unordered_set&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
  431. template <class Cloner, class Disposer>
  432. inline void clone_from(const unordered_set &src, Cloner cloner, Disposer disposer)
  433. { this->Base::clone_from(src, cloner, disposer); }
  434. template <class Cloner, class Disposer>
  435. inline void clone_from(BOOST_RV_REF(unordered_set) src, Cloner cloner, Disposer disposer)
  436. { this->Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
  437. };
  438. #endif
  439. //! The class template unordered_multiset is an intrusive container, that mimics most of
  440. //! the interface of std::tr1::unordered_multiset as described in the C++ TR1.
  441. //!
  442. //! unordered_multiset is a semi-intrusive container: each object to be stored in the
  443. //! container must contain a proper hook, but the container also needs
  444. //! additional auxiliary memory to work: unordered_multiset needs a pointer to an array
  445. //! of type `bucket_type` to be passed in the constructor. This bucket array must
  446. //! have at least the same lifetime as the container. This makes the use of
  447. //! unordered_multiset more complicated than purely intrusive containers.
  448. //! `bucket_type` is default-constructible, copyable and assignable
  449. //!
  450. //! The template parameter \c T is the type to be managed by the container.
  451. //! The user can specify additional options and if no options are provided
  452. //! default options are used.
  453. //!
  454. //! The container supports the following options:
  455. //! \c base_hook<>/member_hook<>/value_traits<>,
  456. //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
  457. //! \c bucket_traits<>, \c power_2_buckets<> and \c cache_begin<>.
  458. //!
  459. //! unordered_multiset only provides forward iterators but it provides 4 iterator types:
  460. //! iterator and const_iterator to navigate through the whole container and
  461. //! local_iterator and const_local_iterator to navigate through the values
  462. //! stored in a single bucket. Local iterators are faster and smaller.
  463. //!
  464. //! It's not recommended to use non constant-time size unordered_multisets because several
  465. //! key functions, like "empty()", become non-constant time functions. Non
  466. //! constant-time size unordered_multisets are mainly provided to support auto-unlink hooks.
  467. //!
  468. //! unordered_multiset, unlike std::unordered_set, does not make automatic rehashings nor
  469. //! offers functions related to a load factor. Rehashing can be explicitly requested
  470. //! and the user must provide a new bucket array that will be used from that moment.
  471. //!
  472. //! Since no automatic rehashing is done, iterators are never invalidated when
  473. //! inserting or erasing elements. Iterators are only invalidated when rehasing.
  474. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  475. template<class T, class ...Options>
  476. #else
  477. template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyHash, class VoidOrKeyEqual, class SizeType, class BucketTraits, std::size_t BoolFlags>
  478. #endif
  479. class unordered_multiset_impl
  480. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  481. : public hashtable_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual, BucketTraits, SizeType, BoolFlags>
  482. #endif
  483. {
  484. /// @cond
  485. private:
  486. typedef hashtable_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyHash, VoidOrKeyEqual, BucketTraits, SizeType, BoolFlags> table_type;
  487. /// @endcond
  488. //Movable
  489. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_multiset_impl)
  490. typedef table_type implementation_defined;
  491. public:
  492. typedef typename implementation_defined::value_type value_type;
  493. typedef typename implementation_defined::key_type key_type;
  494. typedef typename implementation_defined::value_traits value_traits;
  495. typedef typename implementation_defined::bucket_traits bucket_traits;
  496. typedef typename implementation_defined::pointer pointer;
  497. typedef typename implementation_defined::const_pointer const_pointer;
  498. typedef typename implementation_defined::reference reference;
  499. typedef typename implementation_defined::const_reference const_reference;
  500. typedef typename implementation_defined::difference_type difference_type;
  501. typedef typename implementation_defined::size_type size_type;
  502. typedef typename implementation_defined::key_equal key_equal;
  503. typedef typename implementation_defined::hasher hasher;
  504. typedef typename implementation_defined::bucket_type bucket_type;
  505. typedef typename implementation_defined::bucket_ptr bucket_ptr;
  506. typedef typename implementation_defined::iterator iterator;
  507. typedef typename implementation_defined::const_iterator const_iterator;
  508. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  509. typedef typename implementation_defined::local_iterator local_iterator;
  510. typedef typename implementation_defined::const_local_iterator const_local_iterator;
  511. typedef typename implementation_defined::node_traits node_traits;
  512. typedef typename implementation_defined::node node;
  513. typedef typename implementation_defined::node_ptr node_ptr;
  514. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  515. public:
  516. //! @copydoc ::boost::intrusive::hashtable::hashtable(const bucket_traits &,const hasher &,const key_equal &,const value_traits &)
  517. inline explicit unordered_multiset_impl ( const bucket_traits &b_traits
  518. , const hasher & hash_func = hasher()
  519. , const key_equal &equal_func = key_equal()
  520. , const value_traits &v_traits = value_traits())
  521. : table_type(b_traits, hash_func, equal_func, v_traits)
  522. {}
  523. //! @copydoc ::boost::intrusive::hashtable::hashtable(bool,Iterator,Iterator,const bucket_traits &,const hasher &,const key_equal &,const value_traits &)
  524. template<class Iterator>
  525. inline unordered_multiset_impl ( Iterator b
  526. , Iterator e
  527. , const bucket_traits &b_traits
  528. , const hasher & hash_func = hasher()
  529. , const key_equal &equal_func = key_equal()
  530. , const value_traits &v_traits = value_traits())
  531. : table_type(false, b, e, b_traits, hash_func, equal_func, v_traits)
  532. {}
  533. //! <b>Effects</b>: to-do
  534. //!
  535. inline unordered_multiset_impl(BOOST_RV_REF(unordered_multiset_impl) x)
  536. : table_type(BOOST_MOVE_BASE(table_type, x))
  537. {}
  538. //! <b>Effects</b>: to-do
  539. //!
  540. inline unordered_multiset_impl& operator=(BOOST_RV_REF(unordered_multiset_impl) x)
  541. { return static_cast<unordered_multiset_impl&>(table_type::operator=(BOOST_MOVE_BASE(table_type, x))); }
  542. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  543. //! @copydoc ::boost::intrusive::hashtable::~hashtable()
  544. ~unordered_multiset_impl();
  545. //! @copydoc ::boost::intrusive::hashtable::begin()
  546. iterator begin() BOOST_NOEXCEPT;
  547. //! @copydoc ::boost::intrusive::hashtable::begin()const
  548. const_iterator begin() const BOOST_NOEXCEPT;
  549. //! @copydoc ::boost::intrusive::hashtable::cbegin()const
  550. const_iterator cbegin() const BOOST_NOEXCEPT;
  551. //! @copydoc ::boost::intrusive::hashtable::end()
  552. iterator end() BOOST_NOEXCEPT;
  553. //! @copydoc ::boost::intrusive::hashtable::end()const
  554. const_iterator end() const BOOST_NOEXCEPT;
  555. //! @copydoc ::boost::intrusive::hashtable::cend()const
  556. const_iterator cend() const BOOST_NOEXCEPT;
  557. //! @copydoc ::boost::intrusive::hashtable::hash_function()const
  558. hasher hash_function() const;
  559. //! @copydoc ::boost::intrusive::hashtable::key_eq()const
  560. key_equal key_eq() const;
  561. //! @copydoc ::boost::intrusive::hashtable::empty()const
  562. bool empty() const BOOST_NOEXCEPT;
  563. //! @copydoc ::boost::intrusive::hashtable::size()const
  564. size_type size() const BOOST_NOEXCEPT;
  565. //! @copydoc ::boost::intrusive::hashtable::hashtable
  566. void swap(unordered_multiset_impl& other);
  567. //! @copydoc ::boost::intrusive::hashtable::clone_from(const hashtable&,Cloner,Disposer)
  568. template <class Cloner, class Disposer>
  569. void clone_from(const unordered_multiset_impl &src, Cloner cloner, Disposer disposer);
  570. #else
  571. using table_type::clone_from;
  572. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  573. //! @copydoc ::boost::intrusive::hashtable::clone_from(hashtable&&,Cloner,Disposer)
  574. template <class Cloner, class Disposer>
  575. inline void clone_from(BOOST_RV_REF(unordered_multiset_impl) src, Cloner cloner, Disposer disposer)
  576. { table_type::clone_from(BOOST_MOVE_BASE(table_type, src), cloner, disposer); }
  577. //! @copydoc ::boost::intrusive::hashtable::insert_equal(reference)
  578. inline iterator insert(reference value)
  579. { return table_type::insert_equal(value); }
  580. //! @copydoc ::boost::intrusive::hashtable::insert_equal(Iterator,Iterator)
  581. template<class Iterator>
  582. inline void insert(Iterator b, Iterator e)
  583. { table_type::insert_equal(b, e); }
  584. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  585. //! @copydoc ::boost::intrusive::hashtable::erase(const_iterator)
  586. void erase(const_iterator i);
  587. //! @copydoc ::boost::intrusive::hashtable::erase(const_iterator,const_iterator)
  588. void erase(const_iterator b, const_iterator e) BOOST_NOEXCEPT;
  589. //! @copydoc ::boost::intrusive::hashtable::erase(const key_type &)
  590. size_type erase(const key_type &key);
  591. //! @copydoc ::boost::intrusive::hashtable::erase(const KeyType&,KeyHasher,KeyEqual)
  592. template<class KeyType, class KeyHasher, class KeyEqual>
  593. size_type erase(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func);
  594. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const_iterator,Disposer)
  595. template<class Disposer>
  596. BOOST_INTRUSIVE_DOC1ST(void
  597. , typename detail::disable_if_convertible<Disposer BOOST_INTRUSIVE_I const_iterator>::type)
  598. erase_and_dispose(const_iterator i, Disposer disposer) BOOST_NOEXCEPT;
  599. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const_iterator,const_iterator,Disposer)
  600. template<class Disposer>
  601. void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) BOOST_NOEXCEPT;
  602. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const key_type &,Disposer)
  603. template<class Disposer>
  604. size_type erase_and_dispose(const key_type &key, Disposer disposer);
  605. //! @copydoc ::boost::intrusive::hashtable::erase_and_dispose(const KeyType&,KeyHasher,KeyEqual,Disposer)
  606. template<class KeyType, class KeyHasher, class KeyEqual, class Disposer>
  607. size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func, Disposer disposer);
  608. //! @copydoc ::boost::intrusive::hashtable::clear
  609. void clear() BOOST_NOEXCEPT;
  610. //! @copydoc ::boost::intrusive::hashtable::clear_and_dispose
  611. template<class Disposer>
  612. void clear_and_dispose(Disposer disposer) BOOST_NOEXCEPT;
  613. //! @copydoc ::boost::intrusive::hashtable::count(const key_type &)const
  614. size_type count(const key_type &key) const;
  615. //! @copydoc ::boost::intrusive::hashtable::count(const KeyType&,KeyHasher,KeyEqual)const
  616. template<class KeyType, class KeyHasher, class KeyEqual>
  617. size_type count(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func) const;
  618. //! @copydoc ::boost::intrusive::hashtable::find(const key_type &)
  619. iterator find(const key_type &key);
  620. //! @copydoc ::boost::intrusive::hashtable::find(const KeyType &,KeyHasher,KeyEqual)
  621. template<class KeyType, class KeyHasher, class KeyEqual>
  622. iterator find(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func);
  623. //! @copydoc ::boost::intrusive::hashtable::find(const key_type &)const
  624. const_iterator find(const key_type &key) const;
  625. //! @copydoc ::boost::intrusive::hashtable::find(const KeyType &,KeyHasher,KeyEqual)const
  626. template<class KeyType, class KeyHasher, class KeyEqual>
  627. const_iterator find(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func) const;
  628. //! @copydoc ::boost::intrusive::hashtable::equal_range(const key_type&)
  629. std::pair<iterator,iterator> equal_range(const key_type &key);
  630. //! @copydoc ::boost::intrusive::hashtable::equal_range(const KeyType &,KeyHasher,KeyEqual)
  631. template<class KeyType, class KeyHasher, class KeyEqual>
  632. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func);
  633. //! @copydoc ::boost::intrusive::hashtable::equal_range(const key_type&)const
  634. std::pair<const_iterator, const_iterator>
  635. equal_range(const key_type &key) const;
  636. //! @copydoc ::boost::intrusive::hashtable::equal_range(const KeyType &,KeyHasher,KeyEqual)const
  637. template<class KeyType, class KeyHasher, class KeyEqual>
  638. std::pair<const_iterator, const_iterator>
  639. equal_range(const KeyType& key, KeyHasher hash_func, KeyEqual equal_func) const;
  640. //! @copydoc ::boost::intrusive::hashtable::iterator_to(reference)
  641. iterator iterator_to(reference value) BOOST_NOEXCEPT;
  642. //! @copydoc ::boost::intrusive::hashtable::iterator_to(const_reference)const
  643. const_iterator iterator_to(const_reference value) const BOOST_NOEXCEPT;
  644. //! @copydoc ::boost::intrusive::hashtable::s_local_iterator_to(reference)
  645. static local_iterator s_local_iterator_to(reference value) BOOST_NOEXCEPT;
  646. //! @copydoc ::boost::intrusive::hashtable::s_local_iterator_to(const_reference)
  647. static const_local_iterator s_local_iterator_to(const_reference value) BOOST_NOEXCEPT;
  648. //! @copydoc ::boost::intrusive::hashtable::local_iterator_to(reference)
  649. local_iterator local_iterator_to(reference value) BOOST_NOEXCEPT;
  650. //! @copydoc ::boost::intrusive::hashtable::local_iterator_to(const_reference)
  651. const_local_iterator local_iterator_to(const_reference value) const BOOST_NOEXCEPT;
  652. //! @copydoc ::boost::intrusive::hashtable::bucket_count
  653. size_type bucket_count() const BOOST_NOEXCEPT;
  654. //! @copydoc ::boost::intrusive::hashtable::bucket_size
  655. size_type bucket_size(size_type n) const BOOST_NOEXCEPT;
  656. //! @copydoc ::boost::intrusive::hashtable::bucket(const key_type&)const
  657. size_type bucket(const key_type& k) const;
  658. //! @copydoc ::boost::intrusive::hashtable::bucket(const KeyType&,KeyHasher)const
  659. template<class KeyType, class KeyHasher>
  660. size_type bucket(const KeyType& k, KeyHasher hash_func) const;
  661. //! @copydoc ::boost::intrusive::hashtable::bucket_pointer
  662. bucket_ptr bucket_pointer() const BOOST_NOEXCEPT;
  663. //! @copydoc ::boost::intrusive::hashtable::begin(size_type)
  664. local_iterator begin(size_type n) BOOST_NOEXCEPT;
  665. //! @copydoc ::boost::intrusive::hashtable::begin(size_type)const
  666. const_local_iterator begin(size_type n) const BOOST_NOEXCEPT;
  667. //! @copydoc ::boost::intrusive::hashtable::cbegin(size_type)const
  668. const_local_iterator cbegin(size_type n) const BOOST_NOEXCEPT;
  669. //! @copydoc ::boost::intrusive::hashtable::end(size_type)
  670. local_iterator end(size_type n) BOOST_NOEXCEPT;
  671. //! @copydoc ::boost::intrusive::hashtable::end(size_type)const
  672. const_local_iterator end(size_type n) const BOOST_NOEXCEPT;
  673. //! @copydoc ::boost::intrusive::hashtable::cend(size_type)const
  674. const_local_iterator cend(size_type n) const BOOST_NOEXCEPT;
  675. //! @copydoc ::boost::intrusive::hashtable::rehash(const bucket_traits &)
  676. void rehash(const bucket_traits &new_bucket_traits);
  677. //! @copydoc ::boost::intrusive::hashtable::full_rehash
  678. void full_rehash();
  679. //! @copydoc ::boost::intrusive::hashtable::incremental_rehash(bool)
  680. bool incremental_rehash(bool grow = true);
  681. //! @copydoc ::boost::intrusive::hashtable::incremental_rehash(const bucket_traits &)
  682. bool incremental_rehash(const bucket_traits &new_bucket_traits);
  683. //! @copydoc ::boost::intrusive::hashtable::split_count
  684. size_type split_count() const BOOST_NOEXCEPT;
  685. //! @copydoc ::boost::intrusive::hashtable::suggested_upper_bucket_count
  686. static size_type suggested_upper_bucket_count(size_type n) BOOST_NOEXCEPT;
  687. //! @copydoc ::boost::intrusive::hashtable::suggested_lower_bucket_count
  688. static size_type suggested_lower_bucket_count(size_type n) BOOST_NOEXCEPT;
  689. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  690. };
  691. //! Helper metafunction to define an \c unordered_multiset that yields to the same type when the
  692. //! same options (either explicitly or implicitly) are used.
  693. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  694. template<class T, class ...Options>
  695. #else
  696. template<class T, class O1 = void, class O2 = void
  697. , class O3 = void, class O4 = void
  698. , class O5 = void, class O6 = void
  699. , class O7 = void, class O8 = void
  700. , class O9 = void, class O10= void
  701. , class O11 = void
  702. >
  703. #endif
  704. struct make_unordered_multiset
  705. {
  706. /// @cond
  707. typedef typename pack_options
  708. < hashtable_defaults,
  709. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  710. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11
  711. #else
  712. Options...
  713. #endif
  714. >::type packed_options;
  715. typedef typename detail::get_value_traits
  716. <T, typename packed_options::proto_value_traits>::type value_traits;
  717. typedef typename make_bucket_traits
  718. <T, packed_options>::type bucket_traits;
  719. typedef unordered_multiset_impl
  720. < value_traits
  721. , typename packed_options::key_of_value
  722. , typename packed_options::hash
  723. , typename packed_options::equal
  724. , typename packed_options::size_type
  725. , bucket_traits
  726. , (std::size_t(false)*hash_bool_flags::unique_keys_pos)
  727. | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
  728. | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
  729. | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
  730. | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
  731. | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
  732. | (std::size_t(packed_options::linear_buckets)*hash_bool_flags::linear_buckets_pos)
  733. | (std::size_t(packed_options::fastmod_buckets)*hash_bool_flags::fastmod_buckets_pos)
  734. > implementation_defined;
  735. /// @endcond
  736. typedef implementation_defined type;
  737. };
  738. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  739. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  740. template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10, class O11>
  741. #else
  742. template<class T, class ...Options>
  743. #endif
  744. class unordered_multiset
  745. : public make_unordered_multiset<T,
  746. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  747. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10, O11
  748. #else
  749. Options...
  750. #endif
  751. >::type
  752. {
  753. typedef typename make_unordered_multiset
  754. <T,
  755. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  756. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  757. #else
  758. Options...
  759. #endif
  760. >::type Base;
  761. //Assert if passed value traits are compatible with the type
  762. BOOST_INTRUSIVE_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
  763. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_multiset)
  764. public:
  765. typedef typename Base::value_traits value_traits;
  766. typedef typename Base::bucket_traits bucket_traits;
  767. typedef typename Base::iterator iterator;
  768. typedef typename Base::const_iterator const_iterator;
  769. typedef typename Base::bucket_ptr bucket_ptr;
  770. typedef typename Base::size_type size_type;
  771. typedef typename Base::hasher hasher;
  772. typedef typename Base::key_equal key_equal;
  773. inline
  774. explicit unordered_multiset( const bucket_traits &b_traits
  775. , const hasher & hash_func = hasher()
  776. , const key_equal &equal_func = key_equal()
  777. , const value_traits &v_traits = value_traits())
  778. : Base(b_traits, hash_func, equal_func, v_traits)
  779. {}
  780. template<class Iterator>
  781. inline
  782. unordered_multiset( Iterator b
  783. , Iterator e
  784. , const bucket_traits &b_traits
  785. , const hasher & hash_func = hasher()
  786. , const key_equal &equal_func = key_equal()
  787. , const value_traits &v_traits = value_traits())
  788. : Base(b, e, b_traits, hash_func, equal_func, v_traits)
  789. {}
  790. inline unordered_multiset(BOOST_RV_REF(unordered_multiset) x)
  791. : Base(BOOST_MOVE_BASE(Base, x))
  792. {}
  793. inline unordered_multiset& operator=(BOOST_RV_REF(unordered_multiset) x)
  794. { return static_cast<unordered_multiset&>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
  795. template <class Cloner, class Disposer>
  796. inline void clone_from(const unordered_multiset &src, Cloner cloner, Disposer disposer)
  797. { this->Base::clone_from(src, cloner, disposer); }
  798. template <class Cloner, class Disposer>
  799. inline void clone_from(BOOST_RV_REF(unordered_multiset) src, Cloner cloner, Disposer disposer)
  800. { this->Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
  801. };
  802. #endif
  803. } //namespace intrusive
  804. } //namespace boost
  805. #include <boost/intrusive/detail/config_end.hpp>
  806. #endif //BOOST_INTRUSIVE_UNORDERED_SET_HPP