sg_set.hpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2007-2014
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_SG_SET_HPP
  13. #define BOOST_INTRUSIVE_SG_SET_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <boost/intrusive/intrusive_fwd.hpp>
  16. #include <boost/intrusive/detail/mpl.hpp>
  17. #include <boost/intrusive/sgtree.hpp>
  18. #include <boost/static_assert.hpp>
  19. #include <boost/move/utility_core.hpp>
  20. #if defined(BOOST_HAS_PRAGMA_ONCE)
  21. # pragma once
  22. #endif
  23. namespace boost {
  24. namespace intrusive {
  25. #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  26. template<class ValueTraits, class VoidOrKeyOfValue, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
  27. class sg_multiset_impl;
  28. #endif
  29. //! The class template sg_set is an intrusive container, that mimics most of
  30. //! the interface of std::sg_set as described in the C++ standard.
  31. //!
  32. //! The template parameter \c T is the type to be managed by the container.
  33. //! The user can specify additional options and if no options are provided
  34. //! default options are used.
  35. //!
  36. //! The container supports the following options:
  37. //! \c base_hook<>/member_hook<>/value_traits<>,
  38. //! \c floating_point<>, \c size_type<> and
  39. //! \c compare<>.
  40. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  41. template<class T, class ...Options>
  42. #else
  43. template<class ValueTraits, class VoidOrKeyOfValue, class Compare, class SizeType, bool FloatingPoint, typename HeaderHolder>
  44. #endif
  45. class sg_set_impl
  46. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  47. : public sgtree_impl<ValueTraits, VoidOrKeyOfValue, Compare, SizeType, FloatingPoint, HeaderHolder>
  48. #endif
  49. {
  50. /// @cond
  51. typedef sgtree_impl<ValueTraits, VoidOrKeyOfValue, Compare, SizeType, FloatingPoint, HeaderHolder> tree_type;
  52. BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_set_impl)
  53. typedef tree_type implementation_defined;
  54. /// @endcond
  55. public:
  56. typedef typename implementation_defined::value_type value_type;
  57. typedef typename implementation_defined::key_type key_type;
  58. typedef typename implementation_defined::key_of_value key_of_value;
  59. typedef typename implementation_defined::value_traits value_traits;
  60. typedef typename implementation_defined::pointer pointer;
  61. typedef typename implementation_defined::const_pointer const_pointer;
  62. typedef typename implementation_defined::reference reference;
  63. typedef typename implementation_defined::const_reference const_reference;
  64. typedef typename implementation_defined::difference_type difference_type;
  65. typedef typename implementation_defined::size_type size_type;
  66. typedef typename implementation_defined::value_compare value_compare;
  67. typedef typename implementation_defined::key_compare key_compare;
  68. typedef typename implementation_defined::iterator iterator;
  69. typedef typename implementation_defined::const_iterator const_iterator;
  70. typedef typename implementation_defined::reverse_iterator reverse_iterator;
  71. typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
  72. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  73. typedef typename implementation_defined::node_traits node_traits;
  74. typedef typename implementation_defined::node node;
  75. typedef typename implementation_defined::node_ptr node_ptr;
  76. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  77. typedef typename implementation_defined::node_algorithms node_algorithms;
  78. static const bool constant_time_size = tree_type::constant_time_size;
  79. public:
  80. //! @copydoc ::boost::intrusive::sgtree::sgtree()
  81. sg_set_impl()
  82. : tree_type()
  83. {}
  84. //! @copydoc ::boost::intrusive::sgtree::sgtree(const key_compare &,const value_traits &)
  85. explicit sg_set_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
  86. : tree_type(cmp, v_traits)
  87. {}
  88. //! @copydoc ::boost::intrusive::sgtree::sgtree(bool,Iterator,Iterator,const key_compare &,const value_traits &)
  89. template<class Iterator>
  90. sg_set_impl( Iterator b, Iterator e
  91. , const key_compare &cmp = key_compare()
  92. , const value_traits &v_traits = value_traits())
  93. : tree_type(true, b, e, cmp, v_traits)
  94. {}
  95. //! @copydoc ::boost::intrusive::sgtree::sgtree(sgtree &&)
  96. sg_set_impl(BOOST_RV_REF(sg_set_impl) x)
  97. : tree_type(BOOST_MOVE_BASE(tree_type, x))
  98. {}
  99. //! @copydoc ::boost::intrusive::sgtree::operator=(sgtree &&)
  100. sg_set_impl& operator=(BOOST_RV_REF(sg_set_impl) x)
  101. { return static_cast<sg_set_impl&>(tree_type::operator=(BOOST_MOVE_BASE(tree_type, x))); }
  102. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  103. //! @copydoc ::boost::intrusive::sgtree::~sgtree()
  104. ~sg_set_impl();
  105. //! @copydoc ::boost::intrusive::sgtree::begin()
  106. iterator begin();
  107. //! @copydoc ::boost::intrusive::sgtree::begin()const
  108. const_iterator begin() const;
  109. //! @copydoc ::boost::intrusive::sgtree::cbegin()const
  110. const_iterator cbegin() const;
  111. //! @copydoc ::boost::intrusive::sgtree::end()
  112. iterator end();
  113. //! @copydoc ::boost::intrusive::sgtree::end()const
  114. const_iterator end() const;
  115. //! @copydoc ::boost::intrusive::sgtree::cend()const
  116. const_iterator cend() const;
  117. //! @copydoc ::boost::intrusive::sgtree::rbegin()
  118. reverse_iterator rbegin();
  119. //! @copydoc ::boost::intrusive::sgtree::rbegin()const
  120. const_reverse_iterator rbegin() const;
  121. //! @copydoc ::boost::intrusive::sgtree::crbegin()const
  122. const_reverse_iterator crbegin() const;
  123. //! @copydoc ::boost::intrusive::sgtree::rend()
  124. reverse_iterator rend();
  125. //! @copydoc ::boost::intrusive::sgtree::rend()const
  126. const_reverse_iterator rend() const;
  127. //! @copydoc ::boost::intrusive::sgtree::crend()const
  128. const_reverse_iterator crend() const;
  129. //! @copydoc ::boost::intrusive::sgtree::root()
  130. iterator root();
  131. //! @copydoc ::boost::intrusive::sgtree::root()const
  132. const_iterator root() const;
  133. //! @copydoc ::boost::intrusive::sgtree::croot()const
  134. const_iterator croot() const;
  135. //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(iterator)
  136. static sg_set_impl &container_from_end_iterator(iterator end_iterator);
  137. //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(const_iterator)
  138. static const sg_set_impl &container_from_end_iterator(const_iterator end_iterator);
  139. //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(iterator)
  140. static sg_set_impl &container_from_iterator(iterator it);
  141. //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(const_iterator)
  142. static const sg_set_impl &container_from_iterator(const_iterator it);
  143. //! @copydoc ::boost::intrusive::sgtree::key_comp()const
  144. key_compare key_comp() const;
  145. //! @copydoc ::boost::intrusive::sgtree::value_comp()const
  146. value_compare value_comp() const;
  147. //! @copydoc ::boost::intrusive::sgtree::empty()const
  148. bool empty() const;
  149. //! @copydoc ::boost::intrusive::sgtree::size()const
  150. size_type size() const;
  151. //! @copydoc ::boost::intrusive::sgtree::swap
  152. void swap(sg_set_impl& other);
  153. //! @copydoc ::boost::intrusive::sgtree::clone_from(const sgtree&,Cloner,Disposer)
  154. template <class Cloner, class Disposer>
  155. void clone_from(const sg_set_impl &src, Cloner cloner, Disposer disposer);
  156. #else
  157. using tree_type::clone_from;
  158. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  159. //! @copydoc ::boost::intrusive::sgtree::clone_from(sgtree&&,Cloner,Disposer)
  160. template <class Cloner, class Disposer>
  161. void clone_from(BOOST_RV_REF(sg_set_impl) src, Cloner cloner, Disposer disposer)
  162. { tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer); }
  163. //! @copydoc ::boost::intrusive::sgtree::insert_unique(reference)
  164. std::pair<iterator, bool> insert(reference value)
  165. { return tree_type::insert_unique(value); }
  166. //! @copydoc ::boost::intrusive::sgtree::insert_unique(const_iterator,reference)
  167. iterator insert(const_iterator hint, reference value)
  168. { return tree_type::insert_unique(hint, value); }
  169. //! @copydoc ::boost::intrusive::sgtree::insert_unique_check(const key_type&,insert_commit_data&)
  170. std::pair<iterator, bool> insert_check
  171. (const key_type &key, insert_commit_data &commit_data)
  172. { return tree_type::insert_unique_check(key, commit_data); }
  173. //! @copydoc ::boost::intrusive::sgtree::insert_unique_check(const_iterator,const key_type&,insert_commit_data&)
  174. std::pair<iterator, bool> insert_check
  175. (const_iterator hint, const key_type &key
  176. ,insert_commit_data &commit_data)
  177. { return tree_type::insert_unique_check(hint, key, commit_data); }
  178. //! @copydoc ::boost::intrusive::sgtree::insert_unique_check(const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
  179. template<class KeyType, class KeyTypeKeyCompare>
  180. std::pair<iterator, bool> insert_check
  181. (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data)
  182. { return tree_type::insert_unique_check(key, comp, commit_data); }
  183. //! @copydoc ::boost::intrusive::sgtree::insert_unique_check(const_iterator,const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
  184. template<class KeyType, class KeyTypeKeyCompare>
  185. std::pair<iterator, bool> insert_check
  186. (const_iterator hint, const KeyType &key
  187. ,KeyTypeKeyCompare comp, insert_commit_data &commit_data)
  188. { return tree_type::insert_unique_check(hint, key, comp, commit_data); }
  189. //! @copydoc ::boost::intrusive::sgtree::insert_unique(Iterator,Iterator)
  190. template<class Iterator>
  191. void insert(Iterator b, Iterator e)
  192. { tree_type::insert_unique(b, e); }
  193. //! @copydoc ::boost::intrusive::sgtree::insert_unique_commit
  194. iterator insert_commit(reference value, const insert_commit_data &commit_data)
  195. { return tree_type::insert_unique_commit(value, commit_data); }
  196. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  197. //! @copydoc ::boost::intrusive::sgtree::insert_before
  198. iterator insert_before(const_iterator pos, reference value);
  199. //! @copydoc ::boost::intrusive::sgtree::push_back
  200. void push_back(reference value);
  201. //! @copydoc ::boost::intrusive::sgtree::push_front
  202. void push_front(reference value);
  203. //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator)
  204. iterator erase(const_iterator i);
  205. //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator,const_iterator)
  206. iterator erase(const_iterator b, const_iterator e);
  207. //! @copydoc ::boost::intrusive::sgtree::erase(const key_type &)
  208. size_type erase(const key_type &key);
  209. //! @copydoc ::boost::intrusive::sgtree::erase(const KeyType&,KeyTypeKeyCompare)
  210. template<class KeyType, class KeyTypeKeyCompare>
  211. size_type erase(const KeyType& key, KeyTypeKeyCompare comp);
  212. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,Disposer)
  213. template<class Disposer>
  214. iterator erase_and_dispose(const_iterator i, Disposer disposer);
  215. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,const_iterator,Disposer)
  216. template<class Disposer>
  217. iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer);
  218. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const key_type &, Disposer)
  219. template<class Disposer>
  220. size_type erase_and_dispose(const key_type &key, Disposer disposer);
  221. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const KeyType&,KeyTypeKeyCompare,Disposer)
  222. template<class KeyType, class KeyTypeKeyCompare, class Disposer>
  223. size_type erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer);
  224. //! @copydoc ::boost::intrusive::sgtree::clear
  225. void clear();
  226. //! @copydoc ::boost::intrusive::sgtree::clear_and_dispose
  227. template<class Disposer>
  228. void clear_and_dispose(Disposer disposer);
  229. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  230. //! @copydoc ::boost::intrusive::sgtree::count(const key_type &)const
  231. size_type count(const key_type &key) const
  232. { return static_cast<size_type>(this->tree_type::find(key) != this->tree_type::cend()); }
  233. //! @copydoc ::boost::intrusive::sgtree::count(const KeyType&,KeyTypeKeyCompare)const
  234. template<class KeyType, class KeyTypeKeyCompare>
  235. size_type count(const KeyType& key, KeyTypeKeyCompare comp) const
  236. { return static_cast<size_type>(this->tree_type::find(key, comp) != this->tree_type::cend()); }
  237. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  238. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const key_type &)
  239. iterator lower_bound(const key_type &key);
  240. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyTypeKeyCompare)
  241. template<class KeyType, class KeyTypeKeyCompare>
  242. iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
  243. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const key_type &)const
  244. const_iterator lower_bound(const key_type &key) const;
  245. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyTypeKeyCompare)const
  246. template<class KeyType, class KeyTypeKeyCompare>
  247. const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  248. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const key_type &)
  249. iterator upper_bound(const key_type &key);
  250. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyTypeKeyCompare)
  251. template<class KeyType, class KeyTypeKeyCompare>
  252. iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
  253. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const key_type &)const
  254. const_iterator upper_bound(const key_type &key) const;
  255. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyTypeKeyCompare)const
  256. template<class KeyType, class KeyTypeKeyCompare>
  257. const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  258. //! @copydoc ::boost::intrusive::sgtree::find(const key_type &)
  259. iterator find(const key_type &key);
  260. //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyTypeKeyCompare)
  261. template<class KeyType, class KeyTypeKeyCompare>
  262. iterator find(const KeyType& key, KeyTypeKeyCompare comp);
  263. //! @copydoc ::boost::intrusive::sgtree::find(const key_type &)const
  264. const_iterator find(const key_type &key) const;
  265. //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyTypeKeyCompare)const
  266. template<class KeyType, class KeyTypeKeyCompare>
  267. const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
  268. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  269. //! @copydoc ::boost::intrusive::sgtree::equal_range(const key_type &)
  270. std::pair<iterator,iterator> equal_range(const key_type &key)
  271. { return this->tree_type::lower_bound_range(key); }
  272. //! @copydoc ::boost::intrusive::sgtree::equal_range(const KeyType&,KeyTypeKeyCompare)
  273. template<class KeyType, class KeyTypeKeyCompare>
  274. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp)
  275. { return this->tree_type::equal_range(key, comp); }
  276. //! @copydoc ::boost::intrusive::sgtree::equal_range(const key_type &)const
  277. std::pair<const_iterator, const_iterator>
  278. equal_range(const key_type &key) const
  279. { return this->tree_type::lower_bound_range(key); }
  280. //! @copydoc ::boost::intrusive::sgtree::equal_range(const KeyType&,KeyTypeKeyCompare)const
  281. template<class KeyType, class KeyTypeKeyCompare>
  282. std::pair<const_iterator, const_iterator>
  283. equal_range(const KeyType& key, KeyTypeKeyCompare comp) const
  284. { return this->tree_type::equal_range(key, comp); }
  285. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  286. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const key_type &,const key_type &,bool,bool)
  287. std::pair<iterator,iterator> bounded_range
  288. (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed);
  289. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
  290. template<class KeyType, class KeyTypeKeyCompare>
  291. std::pair<iterator,iterator> bounded_range
  292. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
  293. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const key_type &,const key_type &,bool,bool)const
  294. std::pair<const_iterator, const_iterator>
  295. bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
  296. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)const
  297. template<class KeyType, class KeyTypeKeyCompare>
  298. std::pair<const_iterator, const_iterator> bounded_range
  299. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
  300. //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(reference)
  301. static iterator s_iterator_to(reference value);
  302. //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(const_reference)
  303. static const_iterator s_iterator_to(const_reference value);
  304. //! @copydoc ::boost::intrusive::sgtree::iterator_to(reference)
  305. iterator iterator_to(reference value);
  306. //! @copydoc ::boost::intrusive::sgtree::iterator_to(const_reference)const
  307. const_iterator iterator_to(const_reference value) const;
  308. //! @copydoc ::boost::intrusive::sgtree::init_node(reference)
  309. static void init_node(reference value);
  310. //! @copydoc ::boost::intrusive::sgtree::unlink_leftmost_without_rebalance
  311. pointer unlink_leftmost_without_rebalance();
  312. //! @copydoc ::boost::intrusive::sgtree::replace_node
  313. void replace_node(iterator replace_this, reference with_this);
  314. //! @copydoc ::boost::intrusive::sgtree::remove_node
  315. void remove_node(reference value);
  316. //! @copydoc ::boost::intrusive::sgtree::rebalance
  317. void rebalance();
  318. //! @copydoc ::boost::intrusive::sgtree::rebalance_subtree
  319. iterator rebalance_subtree(iterator root);
  320. //! @copydoc ::boost::intrusive::sgtree::balance_factor()
  321. float balance_factor() const;
  322. //! @copydoc ::boost::intrusive::sgtree::balance_factor(float)
  323. void balance_factor(float new_alpha);
  324. //! @copydoc ::boost::intrusive::rbtree::merge_unique
  325. template<class ...Options2>
  326. void merge(sg_set<T, Options2...> &source);
  327. //! @copydoc ::boost::intrusive::rbtree::merge_unique
  328. template<class ...Options2>
  329. void merge(sg_multiset<T, Options2...> &source);
  330. #else
  331. template<class Compare2>
  332. void merge(sg_set_impl<ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, FloatingPoint, HeaderHolder> &source)
  333. { return tree_type::merge_unique(source); }
  334. template<class Compare2>
  335. void merge(sg_multiset_impl<ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, FloatingPoint, HeaderHolder> &source)
  336. { return tree_type::merge_unique(source); }
  337. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  338. };
  339. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  340. template<class T, class ...Options>
  341. bool operator!= (const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y);
  342. template<class T, class ...Options>
  343. bool operator>(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y);
  344. template<class T, class ...Options>
  345. bool operator<=(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y);
  346. template<class T, class ...Options>
  347. bool operator>=(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y);
  348. template<class T, class ...Options>
  349. void swap(sg_set_impl<T, Options...> &x, sg_set_impl<T, Options...> &y);
  350. #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  351. //! Helper metafunction to define a \c sg_set that yields to the same type when the
  352. //! same options (either explicitly or implicitly) are used.
  353. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  354. template<class T, class ...Options>
  355. #else
  356. template<class T, class O1 = void, class O2 = void
  357. , class O3 = void, class O4 = void
  358. , class O5 = void, class O6 = void>
  359. #endif
  360. struct make_sg_set
  361. {
  362. /// @cond
  363. typedef typename pack_options
  364. < sgtree_defaults,
  365. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  366. O1, O2, O3, O4, O5, O6
  367. #else
  368. Options...
  369. #endif
  370. >::type packed_options;
  371. typedef typename detail::get_value_traits
  372. <T, typename packed_options::proto_value_traits>::type value_traits;
  373. typedef sg_set_impl
  374. < value_traits
  375. , typename packed_options::key_of_value
  376. , typename packed_options::compare
  377. , typename packed_options::size_type
  378. , packed_options::floating_point
  379. , typename packed_options::header_holder_type
  380. > implementation_defined;
  381. /// @endcond
  382. typedef implementation_defined type;
  383. };
  384. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  385. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  386. template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
  387. #else
  388. template<class T, class ...Options>
  389. #endif
  390. class sg_set
  391. : public make_sg_set<T,
  392. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  393. O1, O2, O3, O4, O5, O6
  394. #else
  395. Options...
  396. #endif
  397. >::type
  398. {
  399. typedef typename make_sg_set
  400. <T,
  401. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  402. O1, O2, O3, O4, O5, O6
  403. #else
  404. Options...
  405. #endif
  406. >::type Base;
  407. BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_set)
  408. public:
  409. typedef typename Base::key_compare key_compare;
  410. typedef typename Base::value_traits value_traits;
  411. typedef typename Base::iterator iterator;
  412. typedef typename Base::const_iterator const_iterator;
  413. //Assert if passed value traits are compatible with the type
  414. BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
  415. BOOST_INTRUSIVE_FORCEINLINE sg_set()
  416. : Base()
  417. {}
  418. BOOST_INTRUSIVE_FORCEINLINE explicit sg_set( const key_compare &cmp, const value_traits &v_traits = value_traits())
  419. : Base(cmp, v_traits)
  420. {}
  421. template<class Iterator>
  422. BOOST_INTRUSIVE_FORCEINLINE sg_set( Iterator b, Iterator e
  423. , const key_compare &cmp = key_compare()
  424. , const value_traits &v_traits = value_traits())
  425. : Base(b, e, cmp, v_traits)
  426. {}
  427. BOOST_INTRUSIVE_FORCEINLINE sg_set(BOOST_RV_REF(sg_set) x)
  428. : Base(BOOST_MOVE_BASE(Base, x))
  429. {}
  430. BOOST_INTRUSIVE_FORCEINLINE sg_set& operator=(BOOST_RV_REF(sg_set) x)
  431. { return static_cast<sg_set &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
  432. template <class Cloner, class Disposer>
  433. BOOST_INTRUSIVE_FORCEINLINE void clone_from(const sg_set &src, Cloner cloner, Disposer disposer)
  434. { Base::clone_from(src, cloner, disposer); }
  435. template <class Cloner, class Disposer>
  436. BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(sg_set) src, Cloner cloner, Disposer disposer)
  437. { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
  438. BOOST_INTRUSIVE_FORCEINLINE static sg_set &container_from_end_iterator(iterator end_iterator)
  439. { return static_cast<sg_set &>(Base::container_from_end_iterator(end_iterator)); }
  440. BOOST_INTRUSIVE_FORCEINLINE static const sg_set &container_from_end_iterator(const_iterator end_iterator)
  441. { return static_cast<const sg_set &>(Base::container_from_end_iterator(end_iterator)); }
  442. BOOST_INTRUSIVE_FORCEINLINE static sg_set &container_from_iterator(iterator it)
  443. { return static_cast<sg_set &>(Base::container_from_iterator(it)); }
  444. BOOST_INTRUSIVE_FORCEINLINE static const sg_set &container_from_iterator(const_iterator it)
  445. { return static_cast<const sg_set &>(Base::container_from_iterator(it)); }
  446. };
  447. #endif
  448. //! The class template sg_multiset is an intrusive container, that mimics most of
  449. //! the interface of std::sg_multiset as described in the C++ standard.
  450. //!
  451. //! The template parameter \c T is the type to be managed by the container.
  452. //! The user can specify additional options and if no options are provided
  453. //! default options are used.
  454. //!
  455. //! The container supports the following options:
  456. //! \c base_hook<>/member_hook<>/value_traits<>,
  457. //! \c floating_point<>, \c size_type<> and
  458. //! \c compare<>.
  459. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  460. template<class T, class ...Options>
  461. #else
  462. template<class ValueTraits, class VoidOrKeyOfValue, class Compare, class SizeType, bool FloatingPoint, typename HeaderHolder>
  463. #endif
  464. class sg_multiset_impl
  465. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  466. : public sgtree_impl<ValueTraits, VoidOrKeyOfValue, Compare, SizeType, FloatingPoint, HeaderHolder>
  467. #endif
  468. {
  469. /// @cond
  470. typedef sgtree_impl<ValueTraits, VoidOrKeyOfValue, Compare, SizeType, FloatingPoint, HeaderHolder> tree_type;
  471. BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_multiset_impl)
  472. typedef tree_type implementation_defined;
  473. /// @endcond
  474. public:
  475. typedef typename implementation_defined::value_type value_type;
  476. typedef typename implementation_defined::key_type key_type;
  477. typedef typename implementation_defined::key_of_value key_of_value;
  478. typedef typename implementation_defined::value_traits value_traits;
  479. typedef typename implementation_defined::pointer pointer;
  480. typedef typename implementation_defined::const_pointer const_pointer;
  481. typedef typename implementation_defined::reference reference;
  482. typedef typename implementation_defined::const_reference const_reference;
  483. typedef typename implementation_defined::difference_type difference_type;
  484. typedef typename implementation_defined::size_type size_type;
  485. typedef typename implementation_defined::value_compare value_compare;
  486. typedef typename implementation_defined::key_compare key_compare;
  487. typedef typename implementation_defined::iterator iterator;
  488. typedef typename implementation_defined::const_iterator const_iterator;
  489. typedef typename implementation_defined::reverse_iterator reverse_iterator;
  490. typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
  491. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  492. typedef typename implementation_defined::node_traits node_traits;
  493. typedef typename implementation_defined::node node;
  494. typedef typename implementation_defined::node_ptr node_ptr;
  495. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  496. typedef typename implementation_defined::node_algorithms node_algorithms;
  497. static const bool constant_time_size = tree_type::constant_time_size;
  498. public:
  499. //! @copydoc ::boost::intrusive::sgtree::sgtree()
  500. sg_multiset_impl()
  501. : tree_type()
  502. {}
  503. //! @copydoc ::boost::intrusive::sgtree::sgtree(const key_compare &,const value_traits &)
  504. explicit sg_multiset_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
  505. : tree_type(cmp, v_traits)
  506. {}
  507. //! @copydoc ::boost::intrusive::sgtree::sgtree(bool,Iterator,Iterator,const key_compare &,const value_traits &)
  508. template<class Iterator>
  509. sg_multiset_impl( Iterator b, Iterator e
  510. , const key_compare &cmp = key_compare()
  511. , const value_traits &v_traits = value_traits())
  512. : tree_type(false, b, e, cmp, v_traits)
  513. {}
  514. //! @copydoc ::boost::intrusive::sgtree::sgtree(sgtree &&)
  515. sg_multiset_impl(BOOST_RV_REF(sg_multiset_impl) x)
  516. : tree_type(BOOST_MOVE_BASE(tree_type, x))
  517. {}
  518. //! @copydoc ::boost::intrusive::sgtree::operator=(sgtree &&)
  519. sg_multiset_impl& operator=(BOOST_RV_REF(sg_multiset_impl) x)
  520. { return static_cast<sg_multiset_impl&>(tree_type::operator=(BOOST_MOVE_BASE(tree_type, x))); }
  521. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  522. //! @copydoc ::boost::intrusive::sgtree::~sgtree()
  523. ~sg_multiset_impl();
  524. //! @copydoc ::boost::intrusive::sgtree::begin()
  525. iterator begin();
  526. //! @copydoc ::boost::intrusive::sgtree::begin()const
  527. const_iterator begin() const;
  528. //! @copydoc ::boost::intrusive::sgtree::cbegin()const
  529. const_iterator cbegin() const;
  530. //! @copydoc ::boost::intrusive::sgtree::end()
  531. iterator end();
  532. //! @copydoc ::boost::intrusive::sgtree::end()const
  533. const_iterator end() const;
  534. //! @copydoc ::boost::intrusive::sgtree::cend()const
  535. const_iterator cend() const;
  536. //! @copydoc ::boost::intrusive::sgtree::rbegin()
  537. reverse_iterator rbegin();
  538. //! @copydoc ::boost::intrusive::sgtree::rbegin()const
  539. const_reverse_iterator rbegin() const;
  540. //! @copydoc ::boost::intrusive::sgtree::crbegin()const
  541. const_reverse_iterator crbegin() const;
  542. //! @copydoc ::boost::intrusive::sgtree::rend()
  543. reverse_iterator rend();
  544. //! @copydoc ::boost::intrusive::sgtree::rend()const
  545. const_reverse_iterator rend() const;
  546. //! @copydoc ::boost::intrusive::sgtree::crend()const
  547. const_reverse_iterator crend() const;
  548. //! @copydoc ::boost::intrusive::sgtree::root()
  549. iterator root();
  550. //! @copydoc ::boost::intrusive::sgtree::root()const
  551. const_iterator root() const;
  552. //! @copydoc ::boost::intrusive::sgtree::croot()const
  553. const_iterator croot() const;
  554. //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(iterator)
  555. static sg_multiset_impl &container_from_end_iterator(iterator end_iterator);
  556. //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(const_iterator)
  557. static const sg_multiset_impl &container_from_end_iterator(const_iterator end_iterator);
  558. //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(iterator)
  559. static sg_multiset_impl &container_from_iterator(iterator it);
  560. //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(const_iterator)
  561. static const sg_multiset_impl &container_from_iterator(const_iterator it);
  562. //! @copydoc ::boost::intrusive::sgtree::key_comp()const
  563. key_compare key_comp() const;
  564. //! @copydoc ::boost::intrusive::sgtree::value_comp()const
  565. value_compare value_comp() const;
  566. //! @copydoc ::boost::intrusive::sgtree::empty()const
  567. bool empty() const;
  568. //! @copydoc ::boost::intrusive::sgtree::size()const
  569. size_type size() const;
  570. //! @copydoc ::boost::intrusive::sgtree::swap
  571. void swap(sg_multiset_impl& other);
  572. //! @copydoc ::boost::intrusive::sgtree::clone_from(const sgtree&,Cloner,Disposer)
  573. template <class Cloner, class Disposer>
  574. void clone_from(const sg_multiset_impl &src, Cloner cloner, Disposer disposer);
  575. #else
  576. using tree_type::clone_from;
  577. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  578. //! @copydoc ::boost::intrusive::sgtree::clone_from(sgtree&&,Cloner,Disposer)
  579. template <class Cloner, class Disposer>
  580. void clone_from(BOOST_RV_REF(sg_multiset_impl) src, Cloner cloner, Disposer disposer)
  581. { tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer); }
  582. //! @copydoc ::boost::intrusive::sgtree::insert_equal(reference)
  583. iterator insert(reference value)
  584. { return tree_type::insert_equal(value); }
  585. //! @copydoc ::boost::intrusive::sgtree::insert_equal(const_iterator,reference)
  586. iterator insert(const_iterator hint, reference value)
  587. { return tree_type::insert_equal(hint, value); }
  588. //! @copydoc ::boost::intrusive::sgtree::insert_equal(Iterator,Iterator)
  589. template<class Iterator>
  590. void insert(Iterator b, Iterator e)
  591. { tree_type::insert_equal(b, e); }
  592. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  593. //! @copydoc ::boost::intrusive::sgtree::insert_before
  594. iterator insert_before(const_iterator pos, reference value);
  595. //! @copydoc ::boost::intrusive::sgtree::push_back
  596. void push_back(reference value);
  597. //! @copydoc ::boost::intrusive::sgtree::push_front
  598. void push_front(reference value);
  599. //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator)
  600. iterator erase(const_iterator i);
  601. //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator,const_iterator)
  602. iterator erase(const_iterator b, const_iterator e);
  603. //! @copydoc ::boost::intrusive::sgtree::erase(const key_type &)
  604. size_type erase(const key_type &key);
  605. //! @copydoc ::boost::intrusive::sgtree::erase(const KeyType&,KeyTypeKeyCompare)
  606. template<class KeyType, class KeyTypeKeyCompare>
  607. size_type erase(const KeyType& key, KeyTypeKeyCompare comp);
  608. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,Disposer)
  609. template<class Disposer>
  610. iterator erase_and_dispose(const_iterator i, Disposer disposer);
  611. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,const_iterator,Disposer)
  612. template<class Disposer>
  613. iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer);
  614. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const key_type &, Disposer)
  615. template<class Disposer>
  616. size_type erase_and_dispose(const key_type &key, Disposer disposer);
  617. //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const KeyType&,KeyTypeKeyCompare,Disposer)
  618. template<class KeyType, class KeyTypeKeyCompare, class Disposer>
  619. size_type erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer);
  620. //! @copydoc ::boost::intrusive::sgtree::clear
  621. void clear();
  622. //! @copydoc ::boost::intrusive::sgtree::clear_and_dispose
  623. template<class Disposer>
  624. void clear_and_dispose(Disposer disposer);
  625. //! @copydoc ::boost::intrusive::sgtree::count(const key_type &)const
  626. size_type count(const key_type &key) const;
  627. //! @copydoc ::boost::intrusive::sgtree::count(const KeyType&,KeyTypeKeyCompare)const
  628. template<class KeyType, class KeyTypeKeyCompare>
  629. size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
  630. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const key_type &)
  631. iterator lower_bound(const key_type &key);
  632. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyTypeKeyCompare)
  633. template<class KeyType, class KeyTypeKeyCompare>
  634. iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
  635. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const key_type &)const
  636. const_iterator lower_bound(const key_type &key) const;
  637. //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyTypeKeyCompare)const
  638. template<class KeyType, class KeyTypeKeyCompare>
  639. const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  640. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const key_type &)
  641. iterator upper_bound(const key_type &key);
  642. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyTypeKeyCompare)
  643. template<class KeyType, class KeyTypeKeyCompare>
  644. iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
  645. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const key_type &)const
  646. const_iterator upper_bound(const key_type &key) const;
  647. //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyTypeKeyCompare)const
  648. template<class KeyType, class KeyTypeKeyCompare>
  649. const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  650. //! @copydoc ::boost::intrusive::sgtree::find(const key_type &)
  651. iterator find(const key_type &key);
  652. //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyTypeKeyCompare)
  653. template<class KeyType, class KeyTypeKeyCompare>
  654. iterator find(const KeyType& key, KeyTypeKeyCompare comp);
  655. //! @copydoc ::boost::intrusive::sgtree::find(const key_type &)const
  656. const_iterator find(const key_type &key) const;
  657. //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyTypeKeyCompare)const
  658. template<class KeyType, class KeyTypeKeyCompare>
  659. const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
  660. //! @copydoc ::boost::intrusive::sgtree::equal_range(const key_type &)
  661. std::pair<iterator,iterator> equal_range(const key_type &key);
  662. //! @copydoc ::boost::intrusive::sgtree::equal_range(const KeyType&,KeyTypeKeyCompare)
  663. template<class KeyType, class KeyTypeKeyCompare>
  664. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
  665. //! @copydoc ::boost::intrusive::sgtree::equal_range(const key_type &)const
  666. std::pair<const_iterator, const_iterator>
  667. equal_range(const key_type &key) const;
  668. //! @copydoc ::boost::intrusive::sgtree::equal_range(const KeyType&,KeyTypeKeyCompare)const
  669. template<class KeyType, class KeyTypeKeyCompare>
  670. std::pair<const_iterator, const_iterator>
  671. equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
  672. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const key_type &,const key_type &,bool,bool)
  673. std::pair<iterator,iterator> bounded_range
  674. (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed);
  675. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
  676. template<class KeyType, class KeyTypeKeyCompare>
  677. std::pair<iterator,iterator> bounded_range
  678. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
  679. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const key_type &,const key_type &,bool,bool)const
  680. std::pair<const_iterator, const_iterator>
  681. bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
  682. //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)const
  683. template<class KeyType, class KeyTypeKeyCompare>
  684. std::pair<const_iterator, const_iterator> bounded_range
  685. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
  686. //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(reference)
  687. static iterator s_iterator_to(reference value);
  688. //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(const_reference)
  689. static const_iterator s_iterator_to(const_reference value);
  690. //! @copydoc ::boost::intrusive::sgtree::iterator_to(reference)
  691. iterator iterator_to(reference value);
  692. //! @copydoc ::boost::intrusive::sgtree::iterator_to(const_reference)const
  693. const_iterator iterator_to(const_reference value) const;
  694. //! @copydoc ::boost::intrusive::sgtree::init_node(reference)
  695. static void init_node(reference value);
  696. //! @copydoc ::boost::intrusive::sgtree::unlink_leftmost_without_rebalance
  697. pointer unlink_leftmost_without_rebalance();
  698. //! @copydoc ::boost::intrusive::sgtree::replace_node
  699. void replace_node(iterator replace_this, reference with_this);
  700. //! @copydoc ::boost::intrusive::sgtree::remove_node
  701. void remove_node(reference value);
  702. //! @copydoc ::boost::intrusive::sgtree::rebalance
  703. void rebalance();
  704. //! @copydoc ::boost::intrusive::sgtree::rebalance_subtree
  705. iterator rebalance_subtree(iterator root);
  706. //! @copydoc ::boost::intrusive::sgtree::balance_factor()
  707. float balance_factor() const;
  708. //! @copydoc ::boost::intrusive::sgtree::balance_factor(float)
  709. void balance_factor(float new_alpha);
  710. //! @copydoc ::boost::intrusive::treap::merge_unique
  711. template<class ...Options2>
  712. void merge(sg_multiset<T, Options2...> &source);
  713. //! @copydoc ::boost::intrusive::treap::merge_unique
  714. template<class ...Options2>
  715. void merge(sg_set<T, Options2...> &source);
  716. #else
  717. template<class Compare2>
  718. void merge(sg_multiset_impl<ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, FloatingPoint, HeaderHolder> &source)
  719. { return tree_type::merge_equal(source); }
  720. template<class Compare2>
  721. void merge(sg_set_impl<ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, FloatingPoint, HeaderHolder> &source)
  722. { return tree_type::merge_equal(source); }
  723. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  724. };
  725. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  726. template<class T, class ...Options>
  727. bool operator!= (const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y);
  728. template<class T, class ...Options>
  729. bool operator>(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y);
  730. template<class T, class ...Options>
  731. bool operator<=(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y);
  732. template<class T, class ...Options>
  733. bool operator>=(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y);
  734. template<class T, class ...Options>
  735. void swap(sg_multiset_impl<T, Options...> &x, sg_multiset_impl<T, Options...> &y);
  736. #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  737. //! Helper metafunction to define a \c sg_multiset that yields to the same type when the
  738. //! same options (either explicitly or implicitly) are used.
  739. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  740. template<class T, class ...Options>
  741. #else
  742. template<class T, class O1 = void, class O2 = void
  743. , class O3 = void, class O4 = void
  744. , class O5 = void, class O6 = void>
  745. #endif
  746. struct make_sg_multiset
  747. {
  748. /// @cond
  749. typedef typename pack_options
  750. < sgtree_defaults,
  751. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  752. O1, O2, O3, O4, O5, O6
  753. #else
  754. Options...
  755. #endif
  756. >::type packed_options;
  757. typedef typename detail::get_value_traits
  758. <T, typename packed_options::proto_value_traits>::type value_traits;
  759. typedef sg_multiset_impl
  760. < value_traits
  761. , typename packed_options::key_of_value
  762. , typename packed_options::compare
  763. , typename packed_options::size_type
  764. , packed_options::floating_point
  765. , typename packed_options::header_holder_type
  766. > implementation_defined;
  767. /// @endcond
  768. typedef implementation_defined type;
  769. };
  770. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  771. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  772. template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
  773. #else
  774. template<class T, class ...Options>
  775. #endif
  776. class sg_multiset
  777. : public make_sg_multiset<T,
  778. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  779. O1, O2, O3, O4, O5, O6
  780. #else
  781. Options...
  782. #endif
  783. >::type
  784. {
  785. typedef typename make_sg_multiset<T,
  786. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  787. O1, O2, O3, O4, O5, O6
  788. #else
  789. Options...
  790. #endif
  791. >::type Base;
  792. BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_multiset)
  793. public:
  794. typedef typename Base::key_compare key_compare;
  795. typedef typename Base::value_traits value_traits;
  796. typedef typename Base::iterator iterator;
  797. typedef typename Base::const_iterator const_iterator;
  798. //Assert if passed value traits are compatible with the type
  799. BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
  800. BOOST_INTRUSIVE_FORCEINLINE sg_multiset()
  801. : Base()
  802. {}
  803. BOOST_INTRUSIVE_FORCEINLINE explicit sg_multiset( const key_compare &cmp, const value_traits &v_traits = value_traits())
  804. : Base(cmp, v_traits)
  805. {}
  806. template<class Iterator>
  807. BOOST_INTRUSIVE_FORCEINLINE sg_multiset( Iterator b, Iterator e
  808. , const key_compare &cmp = key_compare()
  809. , const value_traits &v_traits = value_traits())
  810. : Base(b, e, cmp, v_traits)
  811. {}
  812. BOOST_INTRUSIVE_FORCEINLINE sg_multiset(BOOST_RV_REF(sg_multiset) x)
  813. : Base(BOOST_MOVE_BASE(Base, x))
  814. {}
  815. BOOST_INTRUSIVE_FORCEINLINE sg_multiset& operator=(BOOST_RV_REF(sg_multiset) x)
  816. { return static_cast<sg_multiset &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
  817. template <class Cloner, class Disposer>
  818. BOOST_INTRUSIVE_FORCEINLINE void clone_from(const sg_multiset &src, Cloner cloner, Disposer disposer)
  819. { Base::clone_from(src, cloner, disposer); }
  820. template <class Cloner, class Disposer>
  821. BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(sg_multiset) src, Cloner cloner, Disposer disposer)
  822. { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
  823. BOOST_INTRUSIVE_FORCEINLINE static sg_multiset &container_from_end_iterator(iterator end_iterator)
  824. { return static_cast<sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
  825. BOOST_INTRUSIVE_FORCEINLINE static const sg_multiset &container_from_end_iterator(const_iterator end_iterator)
  826. { return static_cast<const sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
  827. BOOST_INTRUSIVE_FORCEINLINE static sg_multiset &container_from_iterator(iterator it)
  828. { return static_cast<sg_multiset &>(Base::container_from_iterator(it)); }
  829. BOOST_INTRUSIVE_FORCEINLINE static const sg_multiset &container_from_iterator(const_iterator it)
  830. { return static_cast<const sg_multiset &>(Base::container_from_iterator(it)); }
  831. };
  832. #endif
  833. } //namespace intrusive
  834. } //namespace boost
  835. #include <boost/intrusive/detail/config_end.hpp>
  836. #endif //BOOST_INTRUSIVE_SG_SET_HPP