sg_set.hpp 38 KB

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