tree.hpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_TREE_HPP
  11. #define BOOST_CONTAINER_TREE_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/container/detail/config_begin.hpp>
  19. #include <boost/container/detail/workaround.hpp>
  20. // container
  21. #include <boost/container/allocator_traits.hpp>
  22. #include <boost/container/container_fwd.hpp>
  23. #include <boost/container/options.hpp>
  24. // container/detail
  25. #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
  26. #include <boost/container/detail/compare_functors.hpp>
  27. #include <boost/container/detail/destroyers.hpp>
  28. #include <boost/container/detail/iterator.hpp>
  29. #include <boost/container/detail/iterators.hpp>
  30. #include <boost/container/detail/node_alloc_holder.hpp>
  31. #include <boost/container/detail/pair.hpp>
  32. #include <boost/container/detail/type_traits.hpp>
  33. // intrusive
  34. #include <boost/intrusive/pointer_traits.hpp>
  35. #include <boost/intrusive/rbtree.hpp>
  36. #include <boost/intrusive/avltree.hpp>
  37. #include <boost/intrusive/splaytree.hpp>
  38. #include <boost/intrusive/sgtree.hpp>
  39. // intrusive/detail
  40. #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
  41. #include <boost/intrusive/detail/tree_value_compare.hpp> //tree_value_compare
  42. // move
  43. #include <boost/move/utility_core.hpp>
  44. // move/detail
  45. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  46. #include <boost/move/detail/fwd_macros.hpp>
  47. #endif
  48. #include <boost/move/detail/move_helpers.hpp>
  49. // other
  50. #include <boost/core/no_exceptions_support.hpp>
  51. #include <boost/container/detail/std_fwd.hpp>
  52. namespace boost {
  53. namespace container {
  54. namespace container_detail {
  55. using boost::intrusive::tree_value_compare;
  56. template<class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  57. struct intrusive_tree_hook;
  58. template<class VoidPointer, bool OptimizeSize>
  59. struct intrusive_tree_hook<VoidPointer, boost::container::red_black_tree, OptimizeSize>
  60. {
  61. typedef typename container_detail::bi::make_set_base_hook
  62. < container_detail::bi::void_pointer<VoidPointer>
  63. , container_detail::bi::link_mode<container_detail::bi::normal_link>
  64. , container_detail::bi::optimize_size<OptimizeSize>
  65. >::type type;
  66. };
  67. template<class VoidPointer, bool OptimizeSize>
  68. struct intrusive_tree_hook<VoidPointer, boost::container::avl_tree, OptimizeSize>
  69. {
  70. typedef typename container_detail::bi::make_avl_set_base_hook
  71. < container_detail::bi::void_pointer<VoidPointer>
  72. , container_detail::bi::link_mode<container_detail::bi::normal_link>
  73. , container_detail::bi::optimize_size<OptimizeSize>
  74. >::type type;
  75. };
  76. template<class VoidPointer, bool OptimizeSize>
  77. struct intrusive_tree_hook<VoidPointer, boost::container::scapegoat_tree, OptimizeSize>
  78. {
  79. typedef typename container_detail::bi::make_bs_set_base_hook
  80. < container_detail::bi::void_pointer<VoidPointer>
  81. , container_detail::bi::link_mode<container_detail::bi::normal_link>
  82. >::type type;
  83. };
  84. template<class VoidPointer, bool OptimizeSize>
  85. struct intrusive_tree_hook<VoidPointer, boost::container::splay_tree, OptimizeSize>
  86. {
  87. typedef typename container_detail::bi::make_bs_set_base_hook
  88. < container_detail::bi::void_pointer<VoidPointer>
  89. , container_detail::bi::link_mode<container_detail::bi::normal_link>
  90. >::type type;
  91. };
  92. //This trait is used to type-pun std::pair because in C++03
  93. //compilers std::pair is useless for C++11 features
  94. template<class T>
  95. struct tree_internal_data_type
  96. {
  97. typedef T type;
  98. };
  99. template<class T1, class T2>
  100. struct tree_internal_data_type< std::pair<T1, T2> >
  101. {
  102. typedef pair<typename boost::move_detail::remove_const<T1>::type, T2> type;
  103. };
  104. //The node to be store in the tree
  105. template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  106. struct tree_node
  107. : public intrusive_tree_hook<VoidPointer, tree_type_value, OptimizeSize>::type
  108. {
  109. private:
  110. //BOOST_COPYABLE_AND_MOVABLE(tree_node)
  111. tree_node();
  112. public:
  113. typedef typename intrusive_tree_hook
  114. <VoidPointer, tree_type_value, OptimizeSize>::type hook_type;
  115. typedef T value_type;
  116. typedef typename tree_internal_data_type<T>::type internal_type;
  117. typedef tree_node< T, VoidPointer
  118. , tree_type_value, OptimizeSize> node_type;
  119. BOOST_CONTAINER_FORCEINLINE T &get_data()
  120. {
  121. T* ptr = reinterpret_cast<T*>(&this->m_data);
  122. return *ptr;
  123. }
  124. BOOST_CONTAINER_FORCEINLINE const T &get_data() const
  125. {
  126. const T* ptr = reinterpret_cast<const T*>(&this->m_data);
  127. return *ptr;
  128. }
  129. internal_type m_data;
  130. template<class T1, class T2>
  131. BOOST_CONTAINER_FORCEINLINE void do_assign(const std::pair<const T1, T2> &p)
  132. {
  133. const_cast<T1&>(m_data.first) = p.first;
  134. m_data.second = p.second;
  135. }
  136. template<class T1, class T2>
  137. BOOST_CONTAINER_FORCEINLINE void do_assign(const pair<const T1, T2> &p)
  138. {
  139. const_cast<T1&>(m_data.first) = p.first;
  140. m_data.second = p.second;
  141. }
  142. template<class V>
  143. BOOST_CONTAINER_FORCEINLINE void do_assign(const V &v)
  144. { m_data = v; }
  145. template<class T1, class T2>
  146. BOOST_CONTAINER_FORCEINLINE void do_move_assign(std::pair<const T1, T2> &p)
  147. {
  148. const_cast<T1&>(m_data.first) = ::boost::move(p.first);
  149. m_data.second = ::boost::move(p.second);
  150. }
  151. template<class T1, class T2>
  152. BOOST_CONTAINER_FORCEINLINE void do_move_assign(pair<const T1, T2> &p)
  153. {
  154. const_cast<T1&>(m_data.first) = ::boost::move(p.first);
  155. m_data.second = ::boost::move(p.second);
  156. }
  157. template<class V>
  158. BOOST_CONTAINER_FORCEINLINE void do_move_assign(V &v)
  159. { m_data = ::boost::move(v); }
  160. };
  161. template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  162. struct iiterator_node_value_type< tree_node<T, VoidPointer, tree_type_value, OptimizeSize> > {
  163. typedef T type;
  164. };
  165. template<class Node, class Icont>
  166. class insert_equal_end_hint_functor
  167. {
  168. Icont &icont_;
  169. public:
  170. insert_equal_end_hint_functor(Icont &icont)
  171. : icont_(icont)
  172. {}
  173. void operator()(Node &n)
  174. { this->icont_.insert_equal(this->icont_.cend(), n); }
  175. };
  176. template<class Node, class Icont>
  177. class push_back_functor
  178. {
  179. Icont &icont_;
  180. public:
  181. push_back_functor(Icont &icont)
  182. : icont_(icont)
  183. {}
  184. void operator()(Node &n)
  185. { this->icont_.push_back(n); }
  186. };
  187. }//namespace container_detail {
  188. namespace container_detail {
  189. template< class NodeType, class NodeCompareType
  190. , class SizeType, class HookType
  191. , boost::container::tree_type_enum tree_type_value>
  192. struct intrusive_tree_dispatch;
  193. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  194. struct intrusive_tree_dispatch
  195. <NodeType, NodeCompareType, SizeType, HookType, boost::container::red_black_tree>
  196. {
  197. typedef typename container_detail::bi::make_rbtree
  198. <NodeType
  199. ,container_detail::bi::compare<NodeCompareType>
  200. ,container_detail::bi::base_hook<HookType>
  201. ,container_detail::bi::constant_time_size<true>
  202. ,container_detail::bi::size_type<SizeType>
  203. >::type type;
  204. };
  205. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  206. struct intrusive_tree_dispatch
  207. <NodeType, NodeCompareType, SizeType, HookType, boost::container::avl_tree>
  208. {
  209. typedef typename container_detail::bi::make_avltree
  210. <NodeType
  211. ,container_detail::bi::compare<NodeCompareType>
  212. ,container_detail::bi::base_hook<HookType>
  213. ,container_detail::bi::constant_time_size<true>
  214. ,container_detail::bi::size_type<SizeType>
  215. >::type type;
  216. };
  217. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  218. struct intrusive_tree_dispatch
  219. <NodeType, NodeCompareType, SizeType, HookType, boost::container::scapegoat_tree>
  220. {
  221. typedef typename container_detail::bi::make_sgtree
  222. <NodeType
  223. ,container_detail::bi::compare<NodeCompareType>
  224. ,container_detail::bi::base_hook<HookType>
  225. ,container_detail::bi::floating_point<true>
  226. ,container_detail::bi::size_type<SizeType>
  227. >::type type;
  228. };
  229. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  230. struct intrusive_tree_dispatch
  231. <NodeType, NodeCompareType, SizeType, HookType, boost::container::splay_tree>
  232. {
  233. typedef typename container_detail::bi::make_splaytree
  234. <NodeType
  235. ,container_detail::bi::compare<NodeCompareType>
  236. ,container_detail::bi::base_hook<HookType>
  237. ,container_detail::bi::constant_time_size<true>
  238. ,container_detail::bi::size_type<SizeType>
  239. >::type type;
  240. };
  241. template<class Allocator, class ValueCompare, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  242. struct intrusive_tree_type
  243. {
  244. private:
  245. typedef typename boost::container::
  246. allocator_traits<Allocator>::value_type value_type;
  247. typedef typename boost::container::
  248. allocator_traits<Allocator>::void_pointer void_pointer;
  249. typedef typename boost::container::
  250. allocator_traits<Allocator>::size_type size_type;
  251. typedef typename container_detail::tree_node
  252. < value_type, void_pointer
  253. , tree_type_value, OptimizeSize> node_type;
  254. typedef value_to_node_compare
  255. <node_type, ValueCompare> node_compare_type;
  256. //Deducing the hook type from node_type (e.g. node_type::hook_type) would
  257. //provoke an early instantiation of node_type that could ruin recursive
  258. //tree definitions, so retype the complete type to avoid any problem.
  259. typedef typename intrusive_tree_hook
  260. <void_pointer, tree_type_value
  261. , OptimizeSize>::type hook_type;
  262. public:
  263. typedef typename intrusive_tree_dispatch
  264. < node_type, node_compare_type
  265. , size_type, hook_type
  266. , tree_type_value>::type type;
  267. };
  268. //Trait to detect manually rebalanceable tree types
  269. template<boost::container::tree_type_enum tree_type_value>
  270. struct is_manually_balanceable
  271. { static const bool value = true; };
  272. template<> struct is_manually_balanceable<red_black_tree>
  273. { static const bool value = false; };
  274. template<> struct is_manually_balanceable<avl_tree>
  275. { static const bool value = false; };
  276. //Proxy traits to implement different operations depending on the
  277. //is_manually_balanceable<>::value
  278. template< boost::container::tree_type_enum tree_type_value
  279. , bool IsManuallyRebalanceable = is_manually_balanceable<tree_type_value>::value>
  280. struct intrusive_tree_proxy
  281. {
  282. template<class Icont>
  283. static void rebalance(Icont &) {}
  284. };
  285. template<boost::container::tree_type_enum tree_type_value>
  286. struct intrusive_tree_proxy<tree_type_value, true>
  287. {
  288. template<class Icont>
  289. static void rebalance(Icont &c)
  290. { c.rebalance(); }
  291. };
  292. } //namespace container_detail {
  293. namespace container_detail {
  294. //This functor will be used with Intrusive clone functions to obtain
  295. //already allocated nodes from a intrusive container instead of
  296. //allocating new ones. When the intrusive container runs out of nodes
  297. //the node holder is used instead.
  298. template<class AllocHolder, bool DoMove>
  299. class RecyclingCloner
  300. {
  301. typedef typename AllocHolder::intrusive_container intrusive_container;
  302. typedef typename AllocHolder::Node node_type;
  303. typedef typename AllocHolder::NodePtr node_ptr_type;
  304. public:
  305. RecyclingCloner(AllocHolder &holder, intrusive_container &itree)
  306. : m_holder(holder), m_icont(itree)
  307. {}
  308. static void do_assign(node_ptr_type &p, const node_type &other, bool_<true>)
  309. { p->do_move_assign(const_cast<node_type &>(other).m_data); }
  310. static void do_assign(node_ptr_type &p, const node_type &other, bool_<false>)
  311. { p->do_assign(other.m_data); }
  312. node_ptr_type operator()(const node_type &other) const
  313. {
  314. if(node_ptr_type p = m_icont.unlink_leftmost_without_rebalance()){
  315. //First recycle a node (this can't throw)
  316. BOOST_TRY{
  317. //This can throw
  318. this->do_assign(p, other, bool_<DoMove>());
  319. return p;
  320. }
  321. BOOST_CATCH(...){
  322. //If there is an exception destroy the whole source
  323. m_holder.destroy_node(p);
  324. while((p = m_icont.unlink_leftmost_without_rebalance())){
  325. m_holder.destroy_node(p);
  326. }
  327. BOOST_RETHROW
  328. }
  329. BOOST_CATCH_END
  330. }
  331. else{
  332. return m_holder.create_node(other.m_data);
  333. }
  334. }
  335. AllocHolder &m_holder;
  336. intrusive_container &m_icont;
  337. };
  338. template<class KeyValueCompare, class Node>
  339. //where KeyValueCompare is tree_value_compare<Key, T, Compare, KeyOfValue>
  340. struct key_node_compare
  341. : private KeyValueCompare
  342. {
  343. explicit key_node_compare(const KeyValueCompare &comp)
  344. : KeyValueCompare(comp)
  345. {}
  346. template<class T>
  347. struct is_node
  348. {
  349. static const bool value = is_same<T, Node>::value;
  350. };
  351. template<class T>
  352. typename enable_if_c<is_node<T>::value, const typename KeyValueCompare::value_type &>::type
  353. key_forward(const T &node) const
  354. { return node.get_data(); }
  355. template<class T>
  356. #if defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
  357. const T &key_forward(const T &key, typename enable_if_c<!is_node<T>::value>::type* =0) const
  358. #else
  359. typename enable_if_c<!is_node<T>::value, const T &>::type key_forward(const T &key) const
  360. #endif
  361. { return key; }
  362. template<class KeyType, class KeyType2>
  363. bool operator()(const KeyType &key1, const KeyType2 &key2) const
  364. { return KeyValueCompare::operator()(this->key_forward(key1), this->key_forward(key2)); }
  365. };
  366. template <class Key, class T, class KeyOfValue,
  367. class Compare, class Allocator,
  368. class Options = tree_assoc_defaults>
  369. class tree
  370. : protected container_detail::node_alloc_holder
  371. < Allocator
  372. , typename container_detail::intrusive_tree_type
  373. < Allocator, tree_value_compare<Key, T, Compare, KeyOfValue> //ValComp
  374. , Options::tree_type, Options::optimize_size>::type
  375. >
  376. {
  377. typedef tree_value_compare
  378. <Key, T, Compare, KeyOfValue> ValComp;
  379. typedef typename container_detail::intrusive_tree_type
  380. < Allocator, ValComp, Options::tree_type
  381. , Options::optimize_size>::type Icont;
  382. typedef container_detail::node_alloc_holder
  383. <Allocator, Icont> AllocHolder;
  384. typedef typename AllocHolder::NodePtr NodePtr;
  385. typedef tree < Key, T, KeyOfValue
  386. , Compare, Allocator, Options> ThisType;
  387. typedef typename AllocHolder::NodeAlloc NodeAlloc;
  388. typedef boost::container::
  389. allocator_traits<NodeAlloc> allocator_traits_type;
  390. typedef typename AllocHolder::ValAlloc ValAlloc;
  391. typedef typename AllocHolder::Node Node;
  392. typedef typename Icont::iterator iiterator;
  393. typedef typename Icont::const_iterator iconst_iterator;
  394. typedef container_detail::allocator_destroyer<NodeAlloc> Destroyer;
  395. typedef typename AllocHolder::alloc_version alloc_version;
  396. typedef intrusive_tree_proxy<Options::tree_type> intrusive_tree_proxy_t;
  397. BOOST_COPYABLE_AND_MOVABLE(tree)
  398. public:
  399. typedef Key key_type;
  400. typedef T value_type;
  401. typedef Allocator allocator_type;
  402. typedef Compare key_compare;
  403. typedef ValComp value_compare;
  404. typedef typename boost::container::
  405. allocator_traits<Allocator>::pointer pointer;
  406. typedef typename boost::container::
  407. allocator_traits<Allocator>::const_pointer const_pointer;
  408. typedef typename boost::container::
  409. allocator_traits<Allocator>::reference reference;
  410. typedef typename boost::container::
  411. allocator_traits<Allocator>::const_reference const_reference;
  412. typedef typename boost::container::
  413. allocator_traits<Allocator>::size_type size_type;
  414. typedef typename boost::container::
  415. allocator_traits<Allocator>::difference_type difference_type;
  416. typedef difference_type tree_difference_type;
  417. typedef pointer tree_pointer;
  418. typedef const_pointer tree_const_pointer;
  419. typedef reference tree_reference;
  420. typedef const_reference tree_const_reference;
  421. typedef NodeAlloc stored_allocator_type;
  422. private:
  423. typedef key_node_compare<value_compare, Node> KeyNodeCompare;
  424. public:
  425. typedef container_detail::iterator_from_iiterator<iiterator, false> iterator;
  426. typedef container_detail::iterator_from_iiterator<iiterator, true > const_iterator;
  427. typedef boost::container::reverse_iterator<iterator> reverse_iterator;
  428. typedef boost::container::reverse_iterator<const_iterator> const_reverse_iterator;
  429. tree()
  430. : AllocHolder()
  431. {}
  432. explicit tree(const key_compare& comp, const allocator_type& a = allocator_type())
  433. : AllocHolder(ValComp(comp), a)
  434. {}
  435. explicit tree(const allocator_type& a)
  436. : AllocHolder(a)
  437. {}
  438. template <class InputIterator>
  439. tree(bool unique_insertion, InputIterator first, InputIterator last, const key_compare& comp,
  440. const allocator_type& a
  441. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  442. , typename container_detail::enable_if_or
  443. < void
  444. , container_detail::is_same<alloc_version, version_1>
  445. , container_detail::is_input_iterator<InputIterator>
  446. >::type * = 0
  447. #endif
  448. )
  449. : AllocHolder(value_compare(comp), a)
  450. {
  451. //Use cend() as hint to achieve linear time for
  452. //ordered ranges as required by the standard
  453. //for the constructor
  454. const const_iterator end_it(this->cend());
  455. if(unique_insertion){
  456. for ( ; first != last; ++first){
  457. this->insert_unique_convertible(end_it, *first);
  458. }
  459. }
  460. else{
  461. for ( ; first != last; ++first){
  462. this->insert_equal_convertible(end_it, *first);
  463. }
  464. }
  465. }
  466. template <class InputIterator>
  467. tree(bool unique_insertion, InputIterator first, InputIterator last, const key_compare& comp,
  468. const allocator_type& a
  469. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  470. , typename container_detail::disable_if_or
  471. < void
  472. , container_detail::is_same<alloc_version, version_1>
  473. , container_detail::is_input_iterator<InputIterator>
  474. >::type * = 0
  475. #endif
  476. )
  477. : AllocHolder(value_compare(comp), a)
  478. {
  479. if(unique_insertion){
  480. //Use cend() as hint to achieve linear time for
  481. //ordered ranges as required by the standard
  482. //for the constructor
  483. const const_iterator end_it(this->cend());
  484. for ( ; first != last; ++first){
  485. this->insert_unique_convertible(end_it, *first);
  486. }
  487. }
  488. else{
  489. //Optimized allocation and construction
  490. this->allocate_many_and_construct
  491. ( first, boost::container::iterator_distance(first, last)
  492. , insert_equal_end_hint_functor<Node, Icont>(this->icont()));
  493. }
  494. }
  495. template <class InputIterator>
  496. tree( ordered_range_t, InputIterator first, InputIterator last
  497. , const key_compare& comp = key_compare(), const allocator_type& a = allocator_type()
  498. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  499. , typename container_detail::enable_if_or
  500. < void
  501. , container_detail::is_same<alloc_version, version_1>
  502. , container_detail::is_input_iterator<InputIterator>
  503. >::type * = 0
  504. #endif
  505. )
  506. : AllocHolder(value_compare(comp), a)
  507. {
  508. for ( ; first != last; ++first){
  509. this->push_back_impl(*first);
  510. }
  511. }
  512. template <class InputIterator>
  513. tree( ordered_range_t, InputIterator first, InputIterator last
  514. , const key_compare& comp = key_compare(), const allocator_type& a = allocator_type()
  515. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  516. , typename container_detail::disable_if_or
  517. < void
  518. , container_detail::is_same<alloc_version, version_1>
  519. , container_detail::is_input_iterator<InputIterator>
  520. >::type * = 0
  521. #endif
  522. )
  523. : AllocHolder(value_compare(comp), a)
  524. {
  525. //Optimized allocation and construction
  526. this->allocate_many_and_construct
  527. ( first, boost::container::iterator_distance(first, last)
  528. , container_detail::push_back_functor<Node, Icont>(this->icont()));
  529. }
  530. tree(const tree& x)
  531. : AllocHolder(x.value_comp(), x)
  532. {
  533. this->icont().clone_from
  534. (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc()));
  535. }
  536. tree(BOOST_RV_REF(tree) x)
  537. : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x), x.value_comp())
  538. {}
  539. tree(const tree& x, const allocator_type &a)
  540. : AllocHolder(x.value_comp(), a)
  541. {
  542. this->icont().clone_from
  543. (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc()));
  544. }
  545. tree(BOOST_RV_REF(tree) x, const allocator_type &a)
  546. : AllocHolder(x.value_comp(), a)
  547. {
  548. if(this->node_alloc() == x.node_alloc()){
  549. this->icont().swap(x.icont());
  550. }
  551. else{
  552. this->icont().clone_from
  553. (boost::move(x.icont()), typename AllocHolder::move_cloner(*this), Destroyer(this->node_alloc()));
  554. }
  555. }
  556. ~tree()
  557. {} //AllocHolder clears the tree
  558. tree& operator=(BOOST_COPY_ASSIGN_REF(tree) x)
  559. {
  560. if (&x != this){
  561. NodeAlloc &this_alloc = this->get_stored_allocator();
  562. const NodeAlloc &x_alloc = x.get_stored_allocator();
  563. container_detail::bool_<allocator_traits<NodeAlloc>::
  564. propagate_on_container_copy_assignment::value> flag;
  565. if(flag && this_alloc != x_alloc){
  566. this->clear();
  567. }
  568. this->AllocHolder::copy_assign_alloc(x);
  569. //Transfer all the nodes to a temporary tree
  570. //If anything goes wrong, all the nodes will be destroyed
  571. //automatically
  572. Icont other_tree(::boost::move(this->icont()));
  573. //Now recreate the source tree reusing nodes stored by other_tree
  574. this->icont().clone_from
  575. (x.icont()
  576. , RecyclingCloner<AllocHolder, false>(*this, other_tree)
  577. , Destroyer(this->node_alloc()));
  578. //If there are remaining nodes, destroy them
  579. NodePtr p;
  580. while((p = other_tree.unlink_leftmost_without_rebalance())){
  581. AllocHolder::destroy_node(p);
  582. }
  583. }
  584. return *this;
  585. }
  586. tree& operator=(BOOST_RV_REF(tree) x)
  587. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  588. && boost::container::container_detail::is_nothrow_move_assignable<Compare>::value )
  589. {
  590. BOOST_ASSERT(this != &x);
  591. NodeAlloc &this_alloc = this->node_alloc();
  592. NodeAlloc &x_alloc = x.node_alloc();
  593. const bool propagate_alloc = allocator_traits<NodeAlloc>::
  594. propagate_on_container_move_assignment::value;
  595. const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
  596. //Resources can be transferred if both allocators are
  597. //going to be equal after this function (either propagated or already equal)
  598. if(propagate_alloc || allocators_equal){
  599. //Destroy
  600. this->clear();
  601. //Move allocator if needed
  602. this->AllocHolder::move_assign_alloc(x);
  603. //Obtain resources
  604. this->icont() = boost::move(x.icont());
  605. }
  606. //Else do a one by one move
  607. else{
  608. //Transfer all the nodes to a temporary tree
  609. //If anything goes wrong, all the nodes will be destroyed
  610. //automatically
  611. Icont other_tree(::boost::move(this->icont()));
  612. //Now recreate the source tree reusing nodes stored by other_tree
  613. this->icont().clone_from
  614. (::boost::move(x.icont())
  615. , RecyclingCloner<AllocHolder, true>(*this, other_tree)
  616. , Destroyer(this->node_alloc()));
  617. //If there are remaining nodes, destroy them
  618. NodePtr p;
  619. while((p = other_tree.unlink_leftmost_without_rebalance())){
  620. AllocHolder::destroy_node(p);
  621. }
  622. }
  623. return *this;
  624. }
  625. public:
  626. // accessors:
  627. value_compare value_comp() const
  628. { return this->icont().value_comp().predicate(); }
  629. key_compare key_comp() const
  630. { return this->icont().value_comp().predicate().key_comp(); }
  631. allocator_type get_allocator() const
  632. { return allocator_type(this->node_alloc()); }
  633. const stored_allocator_type &get_stored_allocator() const
  634. { return this->node_alloc(); }
  635. stored_allocator_type &get_stored_allocator()
  636. { return this->node_alloc(); }
  637. iterator begin()
  638. { return iterator(this->icont().begin()); }
  639. const_iterator begin() const
  640. { return this->cbegin(); }
  641. iterator end()
  642. { return iterator(this->icont().end()); }
  643. const_iterator end() const
  644. { return this->cend(); }
  645. reverse_iterator rbegin()
  646. { return reverse_iterator(end()); }
  647. const_reverse_iterator rbegin() const
  648. { return this->crbegin(); }
  649. reverse_iterator rend()
  650. { return reverse_iterator(begin()); }
  651. const_reverse_iterator rend() const
  652. { return this->crend(); }
  653. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  654. //!
  655. //! <b>Throws</b>: Nothing.
  656. //!
  657. //! <b>Complexity</b>: Constant.
  658. const_iterator cbegin() const
  659. { return const_iterator(this->non_const_icont().begin()); }
  660. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  661. //!
  662. //! <b>Throws</b>: Nothing.
  663. //!
  664. //! <b>Complexity</b>: Constant.
  665. const_iterator cend() const
  666. { return const_iterator(this->non_const_icont().end()); }
  667. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  668. //! of the reversed container.
  669. //!
  670. //! <b>Throws</b>: Nothing.
  671. //!
  672. //! <b>Complexity</b>: Constant.
  673. const_reverse_iterator crbegin() const
  674. { return const_reverse_iterator(cend()); }
  675. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  676. //! of the reversed container.
  677. //!
  678. //! <b>Throws</b>: Nothing.
  679. //!
  680. //! <b>Complexity</b>: Constant.
  681. const_reverse_iterator crend() const
  682. { return const_reverse_iterator(cbegin()); }
  683. bool empty() const
  684. { return !this->size(); }
  685. size_type size() const
  686. { return this->icont().size(); }
  687. size_type max_size() const
  688. { return AllocHolder::max_size(); }
  689. void swap(ThisType& x)
  690. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  691. && boost::container::container_detail::is_nothrow_swappable<Compare>::value )
  692. { AllocHolder::swap(x); }
  693. public:
  694. typedef typename Icont::insert_commit_data insert_commit_data;
  695. // insert/erase
  696. std::pair<iterator,bool> insert_unique_check
  697. (const key_type& key, insert_commit_data &data)
  698. {
  699. std::pair<iiterator, bool> ret =
  700. this->icont().insert_unique_check(key, KeyNodeCompare(value_comp()), data);
  701. return std::pair<iterator, bool>(iterator(ret.first), ret.second);
  702. }
  703. std::pair<iterator,bool> insert_unique_check
  704. (const_iterator hint, const key_type& key, insert_commit_data &data)
  705. {
  706. BOOST_ASSERT((priv_is_linked)(hint));
  707. std::pair<iiterator, bool> ret =
  708. this->icont().insert_unique_check(hint.get(), key, KeyNodeCompare(value_comp()), data);
  709. return std::pair<iterator, bool>(iterator(ret.first), ret.second);
  710. }
  711. iterator insert_unique_commit(const value_type& v, insert_commit_data &data)
  712. {
  713. NodePtr tmp = AllocHolder::create_node(v);
  714. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  715. iterator ret(this->icont().insert_unique_commit(*tmp, data));
  716. destroy_deallocator.release();
  717. return ret;
  718. }
  719. template<class MovableConvertible>
  720. iterator insert_unique_commit
  721. (BOOST_FWD_REF(MovableConvertible) v, insert_commit_data &data)
  722. {
  723. NodePtr tmp = AllocHolder::create_node(boost::forward<MovableConvertible>(v));
  724. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  725. iterator ret(this->icont().insert_unique_commit(*tmp, data));
  726. destroy_deallocator.release();
  727. return ret;
  728. }
  729. std::pair<iterator,bool> insert_unique(const value_type& v)
  730. {
  731. insert_commit_data data;
  732. std::pair<iterator,bool> ret =
  733. this->insert_unique_check(KeyOfValue()(v), data);
  734. if(ret.second){
  735. ret.first = this->insert_unique_commit(v, data);
  736. }
  737. return ret;
  738. }
  739. template<class MovableConvertible>
  740. std::pair<iterator,bool> insert_unique(BOOST_FWD_REF(MovableConvertible) v)
  741. {
  742. insert_commit_data data;
  743. std::pair<iterator,bool> ret =
  744. this->insert_unique_check(KeyOfValue()(v), data);
  745. if(ret.second){
  746. ret.first = this->insert_unique_commit(boost::forward<MovableConvertible>(v), data);
  747. }
  748. return ret;
  749. }
  750. private:
  751. bool priv_is_linked(const_iterator const position) const
  752. {
  753. iiterator const cur(position.get());
  754. return cur == this->icont().end() ||
  755. cur == this->icont().root() ||
  756. iiterator(cur).go_parent().go_left() == cur ||
  757. iiterator(cur).go_parent().go_right() == cur;
  758. }
  759. template<class MovableConvertible>
  760. void push_back_impl(BOOST_FWD_REF(MovableConvertible) v)
  761. {
  762. NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
  763. //push_back has no-throw guarantee so avoid any deallocator/destroyer
  764. this->icont().push_back(*tmp);
  765. }
  766. std::pair<iterator, bool> emplace_unique_impl(NodePtr p)
  767. {
  768. value_type &v = p->get_data();
  769. insert_commit_data data;
  770. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(p, this->node_alloc());
  771. std::pair<iterator,bool> ret =
  772. this->insert_unique_check(KeyOfValue()(v), data);
  773. if(!ret.second){
  774. return ret;
  775. }
  776. //No throw insertion part, release rollback
  777. destroy_deallocator.release();
  778. return std::pair<iterator,bool>
  779. ( iterator(iiterator(this->icont().insert_unique_commit(*p, data)))
  780. , true );
  781. }
  782. iterator emplace_unique_hint_impl(const_iterator hint, NodePtr p)
  783. {
  784. BOOST_ASSERT((priv_is_linked)(hint));
  785. value_type &v = p->get_data();
  786. insert_commit_data data;
  787. std::pair<iterator,bool> ret =
  788. this->insert_unique_check(hint, KeyOfValue()(v), data);
  789. if(!ret.second){
  790. Destroyer(this->node_alloc())(p);
  791. return ret.first;
  792. }
  793. return iterator(iiterator(this->icont().insert_unique_commit(*p, data)));
  794. }
  795. public:
  796. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  797. template <class... Args>
  798. std::pair<iterator, bool> emplace_unique(BOOST_FWD_REF(Args)... args)
  799. { return this->emplace_unique_impl(AllocHolder::create_node(boost::forward<Args>(args)...)); }
  800. template <class... Args>
  801. iterator emplace_hint_unique(const_iterator hint, BOOST_FWD_REF(Args)... args)
  802. { return this->emplace_unique_hint_impl(hint, AllocHolder::create_node(boost::forward<Args>(args)...)); }
  803. template <class... Args>
  804. iterator emplace_equal(BOOST_FWD_REF(Args)... args)
  805. {
  806. NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
  807. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  808. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
  809. destroy_deallocator.release();
  810. return ret;
  811. }
  812. template <class... Args>
  813. iterator emplace_hint_equal(const_iterator hint, BOOST_FWD_REF(Args)... args)
  814. {
  815. BOOST_ASSERT((priv_is_linked)(hint));
  816. NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
  817. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  818. iterator ret(this->icont().insert_equal(hint.get(), *tmp));
  819. destroy_deallocator.release();
  820. return ret;
  821. }
  822. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  823. #define BOOST_CONTAINER_TREE_EMPLACE_CODE(N) \
  824. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  825. std::pair<iterator, bool> emplace_unique(BOOST_MOVE_UREF##N)\
  826. { return this->emplace_unique_impl(AllocHolder::create_node(BOOST_MOVE_FWD##N)); }\
  827. \
  828. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  829. iterator emplace_hint_unique(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  830. { return this->emplace_unique_hint_impl(hint, AllocHolder::create_node(BOOST_MOVE_FWD##N)); }\
  831. \
  832. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  833. iterator emplace_equal(BOOST_MOVE_UREF##N)\
  834. {\
  835. NodePtr tmp(AllocHolder::create_node(BOOST_MOVE_FWD##N));\
  836. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
  837. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));\
  838. destroy_deallocator.release();\
  839. return ret;\
  840. }\
  841. \
  842. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  843. iterator emplace_hint_equal(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  844. {\
  845. BOOST_ASSERT((priv_is_linked)(hint));\
  846. NodePtr tmp(AllocHolder::create_node(BOOST_MOVE_FWD##N));\
  847. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
  848. iterator ret(this->icont().insert_equal(hint.get(), *tmp));\
  849. destroy_deallocator.release();\
  850. return ret;\
  851. }\
  852. //
  853. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_TREE_EMPLACE_CODE)
  854. #undef BOOST_CONTAINER_TREE_EMPLACE_CODE
  855. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  856. template<class MovableConvertible>
  857. iterator insert_unique_convertible(const_iterator hint, BOOST_FWD_REF(MovableConvertible) v)
  858. {
  859. BOOST_ASSERT((priv_is_linked)(hint));
  860. insert_commit_data data;
  861. std::pair<iterator,bool> ret =
  862. this->insert_unique_check(hint, KeyOfValue()(v), data);
  863. if(!ret.second)
  864. return ret.first;
  865. return this->insert_unique_commit(boost::forward<MovableConvertible>(v), data);
  866. }
  867. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_unique, value_type, iterator, this->insert_unique_convertible, const_iterator, const_iterator)
  868. template <class InputIterator>
  869. void insert_unique(InputIterator first, InputIterator last)
  870. {
  871. for( ; first != last; ++first)
  872. this->insert_unique(*first);
  873. }
  874. iterator insert_equal(const value_type& v)
  875. {
  876. NodePtr tmp(AllocHolder::create_node(v));
  877. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  878. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
  879. destroy_deallocator.release();
  880. return ret;
  881. }
  882. template<class MovableConvertible>
  883. iterator insert_equal(BOOST_FWD_REF(MovableConvertible) v)
  884. {
  885. NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
  886. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  887. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
  888. destroy_deallocator.release();
  889. return ret;
  890. }
  891. template<class MovableConvertible>
  892. iterator insert_equal_convertible(const_iterator hint, BOOST_FWD_REF(MovableConvertible) v)
  893. {
  894. BOOST_ASSERT((priv_is_linked)(hint));
  895. NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
  896. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  897. iterator ret(this->icont().insert_equal(hint.get(), *tmp));
  898. destroy_deallocator.release();
  899. return ret;
  900. }
  901. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_equal, value_type, iterator, this->insert_equal_convertible, const_iterator, const_iterator)
  902. template <class InputIterator>
  903. void insert_equal(InputIterator first, InputIterator last)
  904. {
  905. for( ; first != last; ++first)
  906. this->insert_equal(*first);
  907. }
  908. template<class KeyConvertible>
  909. iterator insert_from_key(BOOST_FWD_REF(KeyConvertible) key)
  910. {
  911. insert_commit_data data;
  912. const key_type & k = key; //Support emulated rvalue references
  913. std::pair<iiterator, bool> ret =
  914. this->icont().insert_unique_check(k, KeyNodeCompare(value_comp()), data);
  915. return ret.second
  916. ? this->insert_unique_key_commit(boost::forward<KeyConvertible>(key), data)
  917. : iterator(ret.first);
  918. }
  919. template<class KeyConvertible>
  920. iterator insert_unique_key_commit
  921. (BOOST_FWD_REF(KeyConvertible) key, insert_commit_data &data)
  922. {
  923. NodePtr tmp = AllocHolder::create_node_from_key(boost::forward<KeyConvertible>(key));
  924. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  925. iterator ret(this->icont().insert_unique_commit(*tmp, data));
  926. destroy_deallocator.release();
  927. return ret;
  928. }
  929. iterator erase(const_iterator position)
  930. {
  931. BOOST_ASSERT(position != this->cend() && (priv_is_linked)(position));
  932. return iterator(this->icont().erase_and_dispose(position.get(), Destroyer(this->node_alloc())));
  933. }
  934. size_type erase(const key_type& k)
  935. { return AllocHolder::erase_key(k, KeyNodeCompare(value_comp()), alloc_version()); }
  936. iterator erase(const_iterator first, const_iterator last)
  937. {
  938. BOOST_ASSERT(first == last || (first != this->cend() && (priv_is_linked)(first)));
  939. BOOST_ASSERT(first == last || (priv_is_linked)(last));
  940. return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version()));
  941. }
  942. void clear()
  943. { AllocHolder::clear(alloc_version()); }
  944. // search operations. Const and non-const overloads even if no iterator is returned
  945. // so splay implementations can to their rebalancing when searching in non-const versions
  946. iterator find(const key_type& k)
  947. { return iterator(this->icont().find(k, KeyNodeCompare(value_comp()))); }
  948. const_iterator find(const key_type& k) const
  949. { return const_iterator(this->non_const_icont().find(k, KeyNodeCompare(value_comp()))); }
  950. size_type count(const key_type& k) const
  951. { return size_type(this->icont().count(k, KeyNodeCompare(value_comp()))); }
  952. iterator lower_bound(const key_type& k)
  953. { return iterator(this->icont().lower_bound(k, KeyNodeCompare(value_comp()))); }
  954. const_iterator lower_bound(const key_type& k) const
  955. { return const_iterator(this->non_const_icont().lower_bound(k, KeyNodeCompare(value_comp()))); }
  956. iterator upper_bound(const key_type& k)
  957. { return iterator(this->icont().upper_bound(k, KeyNodeCompare(value_comp()))); }
  958. const_iterator upper_bound(const key_type& k) const
  959. { return const_iterator(this->non_const_icont().upper_bound(k, KeyNodeCompare(value_comp()))); }
  960. std::pair<iterator,iterator> equal_range(const key_type& k)
  961. {
  962. std::pair<iiterator, iiterator> ret =
  963. this->icont().equal_range(k, KeyNodeCompare(value_comp()));
  964. return std::pair<iterator,iterator>(iterator(ret.first), iterator(ret.second));
  965. }
  966. std::pair<const_iterator, const_iterator> equal_range(const key_type& k) const
  967. {
  968. std::pair<iiterator, iiterator> ret =
  969. this->non_const_icont().equal_range(k, KeyNodeCompare(value_comp()));
  970. return std::pair<const_iterator,const_iterator>
  971. (const_iterator(ret.first), const_iterator(ret.second));
  972. }
  973. std::pair<iterator,iterator> lower_bound_range(const key_type& k)
  974. {
  975. std::pair<iiterator, iiterator> ret =
  976. this->icont().lower_bound_range(k, KeyNodeCompare(value_comp()));
  977. return std::pair<iterator,iterator>(iterator(ret.first), iterator(ret.second));
  978. }
  979. std::pair<const_iterator, const_iterator> lower_bound_range(const key_type& k) const
  980. {
  981. std::pair<iiterator, iiterator> ret =
  982. this->non_const_icont().lower_bound_range(k, KeyNodeCompare(value_comp()));
  983. return std::pair<const_iterator,const_iterator>
  984. (const_iterator(ret.first), const_iterator(ret.second));
  985. }
  986. void rebalance()
  987. { intrusive_tree_proxy_t::rebalance(this->icont()); }
  988. friend bool operator==(const tree& x, const tree& y)
  989. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  990. friend bool operator<(const tree& x, const tree& y)
  991. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  992. friend bool operator!=(const tree& x, const tree& y)
  993. { return !(x == y); }
  994. friend bool operator>(const tree& x, const tree& y)
  995. { return y < x; }
  996. friend bool operator<=(const tree& x, const tree& y)
  997. { return !(y < x); }
  998. friend bool operator>=(const tree& x, const tree& y)
  999. { return !(x < y); }
  1000. friend void swap(tree& x, tree& y)
  1001. { x.swap(y); }
  1002. };
  1003. } //namespace container_detail {
  1004. } //namespace container {
  1005. template <class T>
  1006. struct has_trivial_destructor_after_move;
  1007. //!has_trivial_destructor_after_move<> == true_type
  1008. //!specialization for optimizations
  1009. template <class Key, class T, class KeyOfValue, class Compare, class Allocator, class Options>
  1010. struct has_trivial_destructor_after_move
  1011. <
  1012. ::boost::container::container_detail::tree
  1013. <Key, T, KeyOfValue, Compare, Allocator, Options>
  1014. >
  1015. {
  1016. typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
  1017. static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
  1018. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  1019. ::boost::has_trivial_destructor_after_move<Compare>::value;
  1020. };
  1021. } //namespace boost {
  1022. #include <boost/container/detail/config_end.hpp>
  1023. #endif //BOOST_CONTAINER_TREE_HPP