rbtree.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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::container_from_end_iterator(iterator)
  156. static rbtree_impl &container_from_end_iterator(iterator end_iterator);
  157. //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator)
  158. static const rbtree_impl &container_from_end_iterator(const_iterator end_iterator);
  159. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator)
  160. static rbtree_impl &container_from_iterator(iterator it);
  161. //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator)
  162. static const rbtree_impl &container_from_iterator(const_iterator it);
  163. //! @copydoc ::boost::intrusive::bstree::key_comp()const
  164. key_compare key_comp() const;
  165. //! @copydoc ::boost::intrusive::bstree::value_comp()const
  166. value_compare value_comp() const;
  167. //! @copydoc ::boost::intrusive::bstree::empty()const
  168. bool empty() const;
  169. //! @copydoc ::boost::intrusive::bstree::size()const
  170. size_type size() const;
  171. //! @copydoc ::boost::intrusive::bstree::swap
  172. void swap(rbtree_impl& other);
  173. //! @copydoc ::boost::intrusive::bstree::clone_from(const bstree&,Cloner,Disposer)
  174. template <class Cloner, class Disposer>
  175. void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer);
  176. #else //BOOST_INTRUSIVE_DOXYGEN_INVOKED
  177. using tree_type::clone_from;
  178. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  179. //! @copydoc ::boost::intrusive::bstree::clone_from(bstree&&,Cloner,Disposer)
  180. template <class Cloner, class Disposer>
  181. void clone_from(BOOST_RV_REF(rbtree_impl) src, Cloner cloner, Disposer disposer)
  182. { tree_type::clone_from(BOOST_MOVE_BASE(tree_type, src), cloner, disposer); }
  183. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  184. //! @copydoc ::boost::intrusive::bstree::clone_from(bstree&&,Cloner,Disposer)
  185. template <class Cloner, class Disposer>
  186. void clone_from(rbtree_impl &&src, Cloner cloner, Disposer disposer);
  187. //! @copydoc ::boost::intrusive::bstree::insert_equal(reference)
  188. iterator insert_equal(reference value);
  189. //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference)
  190. iterator insert_equal(const_iterator hint, reference value);
  191. //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator)
  192. template<class Iterator>
  193. void insert_equal(Iterator b, Iterator e);
  194. //! @copydoc ::boost::intrusive::bstree::insert_unique(reference)
  195. std::pair<iterator, bool> insert_unique(reference value);
  196. //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference)
  197. iterator insert_unique(const_iterator hint, reference value);
  198. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
  199. template<class KeyType, class KeyTypeKeyCompare>
  200. std::pair<iterator, bool> insert_unique_check
  201. (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data);
  202. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyTypeKeyCompare,insert_commit_data&)
  203. template<class KeyType, class KeyTypeKeyCompare>
  204. std::pair<iterator, bool> insert_unique_check
  205. (const_iterator hint, const KeyType &key
  206. ,KeyTypeKeyCompare comp, insert_commit_data &commit_data);
  207. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const key_type&,insert_commit_data&)
  208. std::pair<iterator, bool> insert_unique_check
  209. (const key_type &key, insert_commit_data &commit_data);
  210. //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const key_type&,insert_commit_data&)
  211. std::pair<iterator, bool> insert_unique_check
  212. (const_iterator hint, const key_type &key, insert_commit_data &commit_data);
  213. //! @copydoc ::boost::intrusive::bstree::insert_unique_commit
  214. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data);
  215. //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator)
  216. template<class Iterator>
  217. void insert_unique(Iterator b, Iterator e);
  218. //! @copydoc ::boost::intrusive::bstree::insert_before
  219. iterator insert_before(const_iterator pos, reference value);
  220. //! @copydoc ::boost::intrusive::bstree::push_back
  221. void push_back(reference value);
  222. //! @copydoc ::boost::intrusive::bstree::push_front
  223. void push_front(reference value);
  224. //! @copydoc ::boost::intrusive::bstree::erase(const_iterator)
  225. iterator erase(const_iterator i);
  226. //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator)
  227. iterator erase(const_iterator b, const_iterator e);
  228. //! @copydoc ::boost::intrusive::bstree::erase(const key_type &key)
  229. size_type erase(const key_type &key);
  230. //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyTypeKeyCompare)
  231. template<class KeyType, class KeyTypeKeyCompare>
  232. size_type erase(const KeyType& key, KeyTypeKeyCompare comp);
  233. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer)
  234. template<class Disposer>
  235. iterator erase_and_dispose(const_iterator i, Disposer disposer);
  236. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer)
  237. template<class Disposer>
  238. iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer);
  239. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const key_type &, Disposer)
  240. template<class Disposer>
  241. size_type erase_and_dispose(const key_type &key, Disposer disposer);
  242. //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyTypeKeyCompare,Disposer)
  243. template<class KeyType, class KeyTypeKeyCompare, class Disposer>
  244. size_type erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer);
  245. //! @copydoc ::boost::intrusive::bstree::clear
  246. void clear();
  247. //! @copydoc ::boost::intrusive::bstree::clear_and_dispose
  248. template<class Disposer>
  249. void clear_and_dispose(Disposer disposer);
  250. //! @copydoc ::boost::intrusive::bstree::count(const key_type &)const
  251. size_type count(const key_type &key) const;
  252. //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyTypeKeyCompare)const
  253. template<class KeyType, class KeyTypeKeyCompare>
  254. size_type count(const KeyType& key, KeyTypeKeyCompare comp) const;
  255. //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)
  256. iterator lower_bound(const key_type &key);
  257. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)
  258. template<class KeyType, class KeyTypeKeyCompare>
  259. iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp);
  260. //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)const
  261. const_iterator lower_bound(const key_type &key) const;
  262. //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)const
  263. template<class KeyType, class KeyTypeKeyCompare>
  264. const_iterator lower_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  265. //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)
  266. iterator upper_bound(const key_type &key);
  267. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)
  268. template<class KeyType, class KeyTypeKeyCompare>
  269. iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp);
  270. //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)const
  271. const_iterator upper_bound(const key_type &key) const;
  272. //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)const
  273. template<class KeyType, class KeyTypeKeyCompare>
  274. const_iterator upper_bound(const KeyType& key, KeyTypeKeyCompare comp) const;
  275. //! @copydoc ::boost::intrusive::bstree::find(const key_type &)
  276. iterator find(const key_type &key);
  277. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)
  278. template<class KeyType, class KeyTypeKeyCompare>
  279. iterator find(const KeyType& key, KeyTypeKeyCompare comp);
  280. //! @copydoc ::boost::intrusive::bstree::find(const key_type &)const
  281. const_iterator find(const key_type &key) const;
  282. //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)const
  283. template<class KeyType, class KeyTypeKeyCompare>
  284. const_iterator find(const KeyType& key, KeyTypeKeyCompare comp) const;
  285. //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)
  286. std::pair<iterator,iterator> equal_range(const key_type &key);
  287. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)
  288. template<class KeyType, class KeyTypeKeyCompare>
  289. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyTypeKeyCompare comp);
  290. //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)const
  291. std::pair<const_iterator, const_iterator>
  292. equal_range(const key_type &key) const;
  293. //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)const
  294. template<class KeyType, class KeyTypeKeyCompare>
  295. std::pair<const_iterator, const_iterator>
  296. equal_range(const KeyType& key, KeyTypeKeyCompare comp) const;
  297. //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)
  298. std::pair<iterator,iterator> bounded_range
  299. (const key_type &lower, const key_type &upper_key, bool left_closed, bool right_closed);
  300. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
  301. template<class KeyType, class KeyTypeKeyCompare>
  302. std::pair<iterator,iterator> bounded_range
  303. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
  304. //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)const
  305. std::pair<const_iterator, const_iterator>
  306. bounded_range(const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
  307. //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)const
  308. template<class KeyType, class KeyTypeKeyCompare>
  309. std::pair<const_iterator, const_iterator> bounded_range
  310. (const KeyType& lower_key, const KeyType& upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
  311. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference)
  312. static iterator s_iterator_to(reference value);
  313. //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference)
  314. static const_iterator s_iterator_to(const_reference value);
  315. //! @copydoc ::boost::intrusive::bstree::iterator_to(reference)
  316. iterator iterator_to(reference value);
  317. //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const
  318. const_iterator iterator_to(const_reference value) const;
  319. //! @copydoc ::boost::intrusive::bstree::init_node(reference)
  320. static void init_node(reference value);
  321. //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance
  322. pointer unlink_leftmost_without_rebalance();
  323. //! @copydoc ::boost::intrusive::bstree::replace_node
  324. void replace_node(iterator replace_this, reference with_this);
  325. //! @copydoc ::boost::intrusive::bstree::remove_node
  326. void remove_node(reference value);
  327. friend bool operator< (const rbtree_impl &x, const rbtree_impl &y);
  328. friend bool operator==(const rbtree_impl &x, const rbtree_impl &y);
  329. friend bool operator!= (const rbtree_impl &x, const rbtree_impl &y);
  330. friend bool operator>(const rbtree_impl &x, const rbtree_impl &y);
  331. friend bool operator<=(const rbtree_impl &x, const rbtree_impl &y);
  332. friend bool operator>=(const rbtree_impl &x, const rbtree_impl &y);
  333. friend void swap(rbtree_impl &x, rbtree_impl &y);
  334. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  335. };
  336. //! Helper metafunction to define a \c rbtree that yields to the same type when the
  337. //! same options (either explicitly or implicitly) are used.
  338. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  339. template<class T, class ...Options>
  340. #else
  341. template<class T, class O1 = void, class O2 = void
  342. , class O3 = void, class O4 = void
  343. , class O5 = void, class O6 = void>
  344. #endif
  345. struct make_rbtree
  346. {
  347. /// @cond
  348. typedef typename pack_options
  349. < rbtree_defaults,
  350. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  351. O1, O2, O3, O4, O5, O6
  352. #else
  353. Options...
  354. #endif
  355. >::type packed_options;
  356. typedef typename detail::get_value_traits
  357. <T, typename packed_options::proto_value_traits>::type value_traits;
  358. typedef rbtree_impl
  359. < value_traits
  360. , typename packed_options::key_of_value
  361. , typename packed_options::compare
  362. , typename packed_options::size_type
  363. , packed_options::constant_time_size
  364. , typename packed_options::header_holder_type
  365. > implementation_defined;
  366. /// @endcond
  367. typedef implementation_defined type;
  368. };
  369. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  370. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  371. template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
  372. #else
  373. template<class T, class ...Options>
  374. #endif
  375. class rbtree
  376. : public make_rbtree<T,
  377. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  378. O1, O2, O3, O4, O5, O6
  379. #else
  380. Options...
  381. #endif
  382. >::type
  383. {
  384. typedef typename make_rbtree
  385. <T,
  386. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  387. O1, O2, O3, O4, O5, O6
  388. #else
  389. Options...
  390. #endif
  391. >::type Base;
  392. BOOST_MOVABLE_BUT_NOT_COPYABLE(rbtree)
  393. public:
  394. typedef typename Base::key_compare key_compare;
  395. typedef typename Base::value_traits value_traits;
  396. typedef typename Base::iterator iterator;
  397. typedef typename Base::const_iterator const_iterator;
  398. typedef typename Base::reverse_iterator reverse_iterator;
  399. typedef typename Base::const_reverse_iterator const_reverse_iterator;
  400. //Assert if passed value traits are compatible with the type
  401. BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
  402. rbtree()
  403. : Base()
  404. {}
  405. explicit rbtree( const key_compare &cmp, const value_traits &v_traits = value_traits())
  406. : Base(cmp, v_traits)
  407. {}
  408. template<class Iterator>
  409. rbtree( bool unique, Iterator b, Iterator e
  410. , const key_compare &cmp = key_compare()
  411. , const value_traits &v_traits = value_traits())
  412. : Base(unique, b, e, cmp, v_traits)
  413. {}
  414. rbtree(BOOST_RV_REF(rbtree) x)
  415. : Base(BOOST_MOVE_BASE(Base, x))
  416. {}
  417. rbtree& operator=(BOOST_RV_REF(rbtree) x)
  418. { return static_cast<rbtree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
  419. template <class Cloner, class Disposer>
  420. void clone_from(const rbtree &src, Cloner cloner, Disposer disposer)
  421. { Base::clone_from(src, cloner, disposer); }
  422. template <class Cloner, class Disposer>
  423. void clone_from(BOOST_RV_REF(rbtree) src, Cloner cloner, Disposer disposer)
  424. { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
  425. static rbtree &container_from_end_iterator(iterator end_iterator)
  426. { return static_cast<rbtree &>(Base::container_from_end_iterator(end_iterator)); }
  427. static const rbtree &container_from_end_iterator(const_iterator end_iterator)
  428. { return static_cast<const rbtree &>(Base::container_from_end_iterator(end_iterator)); }
  429. static rbtree &container_from_iterator(iterator it)
  430. { return static_cast<rbtree &>(Base::container_from_iterator(it)); }
  431. static const rbtree &container_from_iterator(const_iterator it)
  432. { return static_cast<const rbtree &>(Base::container_from_iterator(it)); }
  433. };
  434. #endif
  435. } //namespace intrusive
  436. } //namespace boost
  437. #include <boost/intrusive/detail/config_end.hpp>
  438. #endif //BOOST_INTRUSIVE_RBTREE_HPP