rbtree.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-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_RBTREE_HPP
  13. #define BOOST_INTRUSIVE_RBTREE_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <boost/intrusive/intrusive_fwd.hpp>
  16. #include <cstddef>
  17. #include <boost/intrusive/detail/minimal_less_equal_header.hpp>
  18. #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
  19. #include <boost/intrusive/set_hook.hpp>
  20. #include <boost/intrusive/detail/rbtree_node.hpp>
  21. #include <boost/intrusive/bstree.hpp>
  22. #include <boost/intrusive/detail/tree_node.hpp>
  23. #include <boost/intrusive/detail/mpl.hpp>
  24. #include <boost/intrusive/pointer_traits.hpp>
  25. #include <boost/intrusive/detail/get_value_traits.hpp>
  26. #include <boost/intrusive/rbtree_algorithms.hpp>
  27. #include <boost/intrusive/link_mode.hpp>
  28. #include <boost/move/utility_core.hpp>
  29. #include <boost/static_assert.hpp>
  30. #if defined(BOOST_HAS_PRAGMA_ONCE)
  31. # pragma once
  32. #endif
  33. namespace boost {
  34. namespace intrusive {
  35. /// @cond
  36. struct default_rbtree_hook_applier
  37. { template <class T> struct apply{ typedef typename T::default_rbtree_hook type; }; };
  38. template<>
  39. struct is_default_hook_tag<default_rbtree_hook_applier>
  40. { static const bool value = true; };
  41. struct rbtree_defaults
  42. : bstree_defaults
  43. {
  44. typedef default_rbtree_hook_applier proto_value_traits;
  45. };
  46. /// @endcond
  47. //! The class template rbtree is an intrusive red-black tree container, that
  48. //! is used to construct intrusive set and multiset containers. The no-throw
  49. //! guarantee holds only, if the key_compare object
  50. //! doesn't throw.
  51. //!
  52. //! The template parameter \c T is the type to be managed by the container.
  53. //! The user can specify additional options and if no options are provided
  54. //! default options are used.
  55. //!
  56. //! The container supports the following options:
  57. //! \c base_hook<>/member_hook<>/value_traits<>,
  58. //! \c constant_time_size<>, \c size_type<> and
  59. //! \c compare<>.
  60. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  61. template<class T, class ...Options>
  62. #else
  63. template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder>
  64. #endif
  65. class rbtree_impl
  66. /// @cond
  67. : public bstree_impl<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder>
  68. /// @endcond
  69. {
  70. public:
  71. typedef ValueTraits value_traits;
  72. /// @cond
  73. typedef bstree_impl< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, SizeType
  74. , ConstantTimeSize, RbTreeAlgorithms
  75. , HeaderHolder> tree_type;
  76. typedef tree_type implementation_defined;
  77. /// @endcond
  78. typedef typename implementation_defined::pointer pointer;
  79. typedef typename implementation_defined::const_pointer const_pointer;
  80. typedef typename implementation_defined::value_type value_type;
  81. typedef typename implementation_defined::key_type key_type;
  82. typedef typename implementation_defined::key_of_value key_of_value;
  83. typedef typename implementation_defined::reference reference;
  84. typedef typename implementation_defined::const_reference const_reference;
  85. typedef typename implementation_defined::difference_type difference_type;
  86. typedef typename implementation_defined::size_type size_type;
  87. typedef typename implementation_defined::value_compare value_compare;
  88. typedef typename implementation_defined::key_compare key_compare;
  89. typedef typename implementation_defined::iterator iterator;
  90. typedef typename implementation_defined::const_iterator const_iterator;
  91. typedef typename implementation_defined::reverse_iterator reverse_iterator;
  92. typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;
  93. typedef typename implementation_defined::node_traits node_traits;
  94. typedef typename implementation_defined::node node;
  95. typedef typename implementation_defined::node_ptr node_ptr;
  96. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  97. typedef typename implementation_defined::node_algorithms node_algorithms;
  98. static const bool constant_time_size = implementation_defined::constant_time_size;
  99. /// @cond
  100. private:
  101. //noncopyable
  102. BOOST_MOVABLE_BUT_NOT_COPYABLE(rbtree_impl)
  103. /// @endcond
  104. public:
  105. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  106. //! @copydoc ::boost::intrusive::bstree::bstree()
  107. rbtree_impl()
  108. : tree_type()
  109. {}
  110. //! @copydoc ::boost::intrusive::bstree::bstree(const key_compare &,const value_traits &)
  111. explicit rbtree_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
  112. : tree_type(cmp, v_traits)
  113. {}
  114. //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const key_compare &,const value_traits &)
  115. template<class Iterator>
  116. rbtree_impl( bool unique, Iterator b, Iterator e
  117. , const key_compare &cmp = key_compare()
  118. , const value_traits &v_traits = value_traits())
  119. : tree_type(unique, b, e, cmp, v_traits)
  120. {}
  121. //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&)
  122. rbtree_impl(BOOST_RV_REF(rbtree_impl) x)
  123. : tree_type(BOOST_MOVE_BASE(tree_type, x))
  124. {}
  125. //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&)
  126. rbtree_impl& operator=(BOOST_RV_REF(rbtree_impl) x)
  127. { return static_cast<rbtree_impl&>(tree_type::operator=(BOOST_MOVE_BASE(tree_type, x))); }
  128. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  129. //! @copydoc ::boost::intrusive::bstree::~bstree()
  130. ~rbtree_impl();
  131. //! @copydoc ::boost::intrusive::bstree::begin()
  132. iterator begin();
  133. //! @copydoc ::boost::intrusive::bstree::begin()const
  134. const_iterator begin() const;
  135. //! @copydoc ::boost::intrusive::bstree::cbegin()const
  136. const_iterator cbegin() const;
  137. //! @copydoc ::boost::intrusive::bstree::end()
  138. iterator end();
  139. //! @copydoc ::boost::intrusive::bstree::end()const
  140. const_iterator end() const;
  141. //! @copydoc ::boost::intrusive::bstree::cend()const
  142. const_iterator cend() const;
  143. //! @copydoc ::boost::intrusive::bstree::rbegin()
  144. reverse_iterator rbegin();
  145. //! @copydoc ::boost::intrusive::bstree::rbegin()const
  146. const_reverse_iterator rbegin() const;
  147. //! @copydoc ::boost::intrusive::bstree::crbegin()const
  148. const_reverse_iterator crbegin() const;
  149. //! @copydoc ::boost::intrusive::bstree::rend()
  150. reverse_iterator rend();
  151. //! @copydoc ::boost::intrusive::bstree::rend()const
  152. const_reverse_iterator rend() const;
  153. //! @copydoc ::boost::intrusive::bstree::crend()const
  154. const_reverse_iterator crend() const;
  155. //! @copydoc ::boost::intrusive::bstree::root()
  156. iterator root();
  157. //! @copydoc ::boost::intrusive::bstree::root()const
  158. const_iterator root() const;
  159. //! @copydoc ::boost::intrusive::bstree::croot()const
  160. const_iterator croot() const;
  161. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator)
  162. static rbtree_impl &container_from_end_iterator(iterator end_iterator);
  163. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
  164. static const rbtree_impl &container_from_end_iterator(const_iterator end_iterator);
  165. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
  166. static rbtree_impl &container_from_iterator(iterator it);
  167. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
  168. static const rbtree_impl &container_from_iterator(const_iterator it);
  169. //! @copydoc ::boost::intrusive::bstree::key_comp()const
  170. key_compare key_comp() const;
  171. //! @copydoc ::boost::intrusive::bstree::value_comp()const
  172. value_compare value_comp() const;
  173. //! @copydoc ::boost::intrusive::bstree::empty()const
  174. bool empty() const;
  175. //! @copydoc ::boost::intrusive::bstree::size()const
  176. size_type size() const;
  177. //! @copydoc ::boost::intrusive::bstree::swap
  178. void swap(rbtree_impl& other);
  179. //! @copydoc ::boost::intrusive::bstree::clone_from(const bstree&,Cloner,Disposer)
  180. template <class Cloner, class Disposer>
  181. void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer);
  182. #else //BOOST_INTRUSIVE_DOXYGEN_INVOKED
  183. using tree_type::clone_from;
  184. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  185. //! @copydoc ::boost::intrusive::bstree::clone_from(bstree&&,Cloner,Disposer)
  186. template <class Cloner, class Disposer>
  187. void clone_from(BOOST_RV_REF(rbtree_impl) src, Cloner cloner, Disposer disposer)
  188. { tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer); }
  189. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  190. //! @copydoc ::boost::intrusive::bstree::clone_from(bstree&&,Cloner,Disposer)
  191. template <class Cloner, class Disposer>
  192. void clone_from(rbtree_impl &&src, Cloner cloner, Disposer disposer);
  193. //! @copydoc ::boost::intrusive::bstree::insert_equal(reference)
  194. iterator insert_equal(reference value);
  195. //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference)
  196. iterator insert_equal(const_iterator hint, reference value);
  197. //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator)
  198. template<class Iterator>
  199. void insert_equal(Iterator b, Iterator e);
  200. //! @copydoc ::boost::intrusive::bstree::insert_unique(reference)
  201. std::pair<iterator, bool> insert_unique(reference value);
  202. //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference)
  203. iterator insert_unique(const_iterator hint, reference value);
  204. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
  205. template<class KeyType, class KeyTypeKeyCompare>
  206. std::pair<iterator, bool> insert_unique_check
  207. (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data);
  208. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
  209. template<class KeyType, class KeyTypeKeyCompare>
  210. std::pair<iterator, bool> insert_unique_check
  211. (const_iterator hint, const KeyType &key
  212. ,KeyTypeKeyCompare comp, insert_commit_data &commit_data);
  213. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const key_type&,insert_commit_data&)
  214. std::pair<iterator, bool> insert_unique_check
  215. (const key_type &key, insert_commit_data &commit_data);
  216. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const key_type&,insert_commit_data&)
  217. std::pair<iterator, bool> insert_unique_check
  218. (const_iterator hint, const key_type &key, insert_commit_data &commit_data);
  219. //! @copydoc ::boost::intrusive::bstree::insert_unique_commit
  220. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data);
  221. //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator)
  222. template<class Iterator>
  223. void insert_unique(Iterator b, Iterator e);
  224. //! @copydoc ::boost::intrusive::bstree::insert_before
  225. iterator insert_before(const_iterator pos, reference value);
  226. //! @copydoc ::boost::intrusive::bstree::push_back
  227. void push_back(reference value);
  228. //! @copydoc ::boost::intrusive::bstree::push_front
  229. void push_front(reference value);
  230. //! @copydoc ::boost::intrusive::bstree::erase(const_iterator)
  231. iterator erase(const_iterator i);
  232. //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator)
  233. iterator erase(const_iterator b, const_iterator e);
  234. //! @copydoc ::boost::intrusive::bstree::erase(const key_type &key)
  235. size_type erase(const key_type &key);
  236. //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyTypeKeyCompare)
  237. template<class KeyType, class KeyTypeKeyCompare>
  238. size_type erase(const KeyType& key, KeyTypeKeyCompare comp);
  239. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer)
  240. template<class Disposer>
  241. iterator erase_and_dispose(const_iterator i, Disposer disposer);
  242. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer)
  243. template<class Disposer>
  244. iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer);
  245. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const key_type &, Disposer)
  246. template<class Disposer>
  247. size_type erase_and_dispose(const key_type &key, Disposer disposer);
  248. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyTypeKeyCompare,Disposer)
  249. template<class KeyType, class KeyTypeKeyCompare, class Disposer>
  250. size_type erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer);
  251. //! @copydoc ::boost::intrusive::bstree::clear
  252. void clear();
  253. //! @copydoc ::boost::intrusive::bstree::clear_and_dispose
  254. template<class Disposer>
  255. void clear_and_dispose(Disposer disposer);
  256. //! @copydoc ::boost::intrusive::bstree::count(const key_type &)const
  257. size_type count(const key_type &key) const;
  258. //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyTypeKeyCompare)const
  259. template<class KeyType, class KeyTypeKeyCompare>
  260. size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
  261. //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)
  262. iterator lower_bound(const key_type &key);
  263. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)
  264. template<class KeyType, class KeyTypeKeyCompare>
  265. iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
  266. //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)const
  267. const_iterator lower_bound(const key_type &key) const;
  268. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)const
  269. template<class KeyType, class KeyTypeKeyCompare>
  270. const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  271. //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)
  272. iterator upper_bound(const key_type &key);
  273. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)
  274. template<class KeyType, class KeyTypeKeyCompare>
  275. iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
  276. //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)const
  277. const_iterator upper_bound(const key_type &key) const;
  278. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)const
  279. template<class KeyType, class KeyTypeKeyCompare>
  280. const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  281. //! @copydoc ::boost::intrusive::bstree::find(const key_type &)
  282. iterator find(const key_type &key);
  283. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)
  284. template<class KeyType, class KeyTypeKeyCompare>
  285. iterator find(const KeyType& key, KeyTypeKeyCompare comp);
  286. //! @copydoc ::boost::intrusive::bstree::find(const key_type &)const
  287. const_iterator find(const key_type &key) const;
  288. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)const
  289. template<class KeyType, class KeyTypeKeyCompare>
  290. const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
  291. //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)
  292. std::pair<iterator,iterator> equal_range(const key_type &key);
  293. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)
  294. template<class KeyType, class KeyTypeKeyCompare>
  295. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
  296. //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)const
  297. std::pair<const_iterator, const_iterator>
  298. equal_range(const key_type &key) const;
  299. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)const
  300. template<class KeyType, class KeyTypeKeyCompare>
  301. std::pair<const_iterator, const_iterator>
  302. equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
  303. //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)
  304. std::pair<iterator,iterator> bounded_range
  305. (const key_type &lower, const key_type &upper_key, bool left_closed, bool right_closed);
  306. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
  307. template<class KeyType, class KeyTypeKeyCompare>
  308. std::pair<iterator,iterator> bounded_range
  309. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
  310. //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)const
  311. std::pair<const_iterator, const_iterator>
  312. bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
  313. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)const
  314. template<class KeyType, class KeyTypeKeyCompare>
  315. std::pair<const_iterator, const_iterator> bounded_range
  316. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
  317. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
  318. static iterator s_iterator_to(reference value);
  319. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
  320. static const_iterator s_iterator_to(const_reference value);
  321. //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
  322. iterator iterator_to(reference value);
  323. //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
  324. const_iterator iterator_to(const_reference value) const;
  325. //! @copydoc ::boost::intrusive::bstree::init_node(reference)
  326. static void init_node(reference value);
  327. //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
  328. pointer unlink_leftmost_without_rebalance();
  329. //! @copydoc ::boost::intrusive::bstree::replace_node
  330. void replace_node(iterator replace_this, reference with_this);
  331. //! @copydoc ::boost::intrusive::bstree::remove_node
  332. void remove_node(reference value);
  333. //! @copydoc ::boost::intrusive::bstree::merge_unique(bstree<T, Options2...>&)
  334. template<class T, class ...Options2>
  335. void merge_unique(rbtree<T, Options2...> &);
  336. //! @copydoc ::boost::intrusive::bstree::merge_equal(bstree<T, Options2...>&)
  337. template<class T, class ...Options2>
  338. void merge_equal(rbtree<T, Options2...> &);
  339. friend bool operator< (const rbtree_impl &x, const rbtree_impl &y);
  340. friend bool operator==(const rbtree_impl &x, const rbtree_impl &y);
  341. friend bool operator!= (const rbtree_impl &x, const rbtree_impl &y);
  342. friend bool operator>(const rbtree_impl &x, const rbtree_impl &y);
  343. friend bool operator<=(const rbtree_impl &x, const rbtree_impl &y);
  344. friend bool operator>=(const rbtree_impl &x, const rbtree_impl &y);
  345. friend void swap(rbtree_impl &x, rbtree_impl &y);
  346. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  347. };
  348. //! Helper metafunction to define a \c rbtree that yields to the same type when the
  349. //! same options (either explicitly or implicitly) are used.
  350. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  351. template<class T, class ...Options>
  352. #else
  353. template<class T, class O1 = void, class O2 = void
  354. , class O3 = void, class O4 = void
  355. , class O5 = void, class O6 = void>
  356. #endif
  357. struct make_rbtree
  358. {
  359. /// @cond
  360. typedef typename pack_options
  361. < rbtree_defaults,
  362. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  363. O1, O2, O3, O4, O5, O6
  364. #else
  365. Options...
  366. #endif
  367. >::type packed_options;
  368. typedef typename detail::get_value_traits
  369. <T, typename packed_options::proto_value_traits>::type value_traits;
  370. typedef rbtree_impl
  371. < value_traits
  372. , typename packed_options::key_of_value
  373. , typename packed_options::compare
  374. , typename packed_options::size_type
  375. , packed_options::constant_time_size
  376. , typename packed_options::header_holder_type
  377. > implementation_defined;
  378. /// @endcond
  379. typedef implementation_defined type;
  380. };
  381. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  382. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  383. template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
  384. #else
  385. template<class T, class ...Options>
  386. #endif
  387. class rbtree
  388. : public make_rbtree<T,
  389. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  390. O1, O2, O3, O4, O5, O6
  391. #else
  392. Options...
  393. #endif
  394. >::type
  395. {
  396. typedef typename make_rbtree
  397. <T,
  398. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  399. O1, O2, O3, O4, O5, O6
  400. #else
  401. Options...
  402. #endif
  403. >::type Base;
  404. BOOST_MOVABLE_BUT_NOT_COPYABLE(rbtree)
  405. public:
  406. typedef typename Base::key_compare key_compare;
  407. typedef typename Base::value_traits value_traits;
  408. typedef typename Base::iterator iterator;
  409. typedef typename Base::const_iterator const_iterator;
  410. typedef typename Base::reverse_iterator reverse_iterator;
  411. typedef typename Base::const_reverse_iterator const_reverse_iterator;
  412. //Assert if passed value traits are compatible with the type
  413. BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
  414. BOOST_INTRUSIVE_FORCEINLINE rbtree()
  415. : Base()
  416. {}
  417. BOOST_INTRUSIVE_FORCEINLINE explicit rbtree( const key_compare &cmp, const value_traits &v_traits = value_traits())
  418. : Base(cmp, v_traits)
  419. {}
  420. template<class Iterator>
  421. BOOST_INTRUSIVE_FORCEINLINE rbtree( bool unique, Iterator b, Iterator e
  422. , const key_compare &cmp = key_compare()
  423. , const value_traits &v_traits = value_traits())
  424. : Base(unique, b, e, cmp, v_traits)
  425. {}
  426. BOOST_INTRUSIVE_FORCEINLINE rbtree(BOOST_RV_REF(rbtree) x)
  427. : Base(BOOST_MOVE_BASE(Base, x))
  428. {}
  429. BOOST_INTRUSIVE_FORCEINLINE rbtree& operator=(BOOST_RV_REF(rbtree) x)
  430. { return static_cast<rbtree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
  431. template <class Cloner, class Disposer>
  432. BOOST_INTRUSIVE_FORCEINLINE void clone_from(const rbtree &src, Cloner cloner, Disposer disposer)
  433. { Base::clone_from(src, cloner, disposer); }
  434. template <class Cloner, class Disposer>
  435. BOOST_INTRUSIVE_FORCEINLINE void clone_from(BOOST_RV_REF(rbtree) src, Cloner cloner, Disposer disposer)
  436. { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
  437. BOOST_INTRUSIVE_FORCEINLINE static rbtree &container_from_end_iterator(iterator end_iterator)
  438. { return static_cast<rbtree &>(Base::container_from_end_iterator(end_iterator)); }
  439. BOOST_INTRUSIVE_FORCEINLINE static const rbtree &container_from_end_iterator(const_iterator end_iterator)
  440. { return static_cast<const rbtree &>(Base::container_from_end_iterator(end_iterator)); }
  441. BOOST_INTRUSIVE_FORCEINLINE static rbtree &container_from_iterator(iterator it)
  442. { return static_cast<rbtree &>(Base::container_from_iterator(it)); }
  443. BOOST_INTRUSIVE_FORCEINLINE static const rbtree &container_from_iterator(const_iterator it)
  444. { return static_cast<const rbtree &>(Base::container_from_iterator(it)); }
  445. };
  446. #endif
  447. } //namespace intrusive
  448. } //namespace boost
  449. #include <boost/intrusive/detail/config_end.hpp>
  450. #endif //BOOST_INTRUSIVE_RBTREE_HPP