unordered_set.hpp 45 KB

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