tree.hpp 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  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. #include <boost/container/node_handle.hpp>
  25. // container/detail
  26. #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
  27. #include <boost/container/detail/compare_functors.hpp>
  28. #include <boost/container/detail/destroyers.hpp>
  29. #include <boost/container/detail/iterator.hpp>
  30. #include <boost/container/detail/iterators.hpp>
  31. #include <boost/container/detail/node_alloc_holder.hpp>
  32. #include <boost/container/detail/pair.hpp>
  33. #include <boost/container/detail/type_traits.hpp>
  34. // intrusive
  35. #include <boost/intrusive/pointer_traits.hpp>
  36. #include <boost/intrusive/rbtree.hpp>
  37. #include <boost/intrusive/avltree.hpp>
  38. #include <boost/intrusive/splaytree.hpp>
  39. #include <boost/intrusive/sgtree.hpp>
  40. // intrusive/detail
  41. #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
  42. #include <boost/intrusive/detail/tree_value_compare.hpp> //tree_value_compare
  43. // move
  44. #include <boost/move/utility_core.hpp>
  45. // move/detail
  46. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  47. #include <boost/move/detail/fwd_macros.hpp>
  48. #endif
  49. #include <boost/move/detail/move_helpers.hpp>
  50. // other
  51. #include <boost/core/no_exceptions_support.hpp>
  52. #include <boost/container/detail/std_fwd.hpp>
  53. namespace boost {
  54. namespace container {
  55. namespace dtl {
  56. using boost::intrusive::tree_value_compare;
  57. template<class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  58. struct intrusive_tree_hook;
  59. template<class VoidPointer, bool OptimizeSize>
  60. struct intrusive_tree_hook<VoidPointer, boost::container::red_black_tree, OptimizeSize>
  61. {
  62. typedef typename dtl::bi::make_set_base_hook
  63. < dtl::bi::void_pointer<VoidPointer>
  64. , dtl::bi::link_mode<dtl::bi::normal_link>
  65. , dtl::bi::optimize_size<OptimizeSize>
  66. >::type type;
  67. };
  68. template<class VoidPointer, bool OptimizeSize>
  69. struct intrusive_tree_hook<VoidPointer, boost::container::avl_tree, OptimizeSize>
  70. {
  71. typedef typename dtl::bi::make_avl_set_base_hook
  72. < dtl::bi::void_pointer<VoidPointer>
  73. , dtl::bi::link_mode<dtl::bi::normal_link>
  74. , dtl::bi::optimize_size<OptimizeSize>
  75. >::type type;
  76. };
  77. template<class VoidPointer, bool OptimizeSize>
  78. struct intrusive_tree_hook<VoidPointer, boost::container::scapegoat_tree, OptimizeSize>
  79. {
  80. typedef typename dtl::bi::make_bs_set_base_hook
  81. < dtl::bi::void_pointer<VoidPointer>
  82. , dtl::bi::link_mode<dtl::bi::normal_link>
  83. >::type type;
  84. };
  85. template<class VoidPointer, bool OptimizeSize>
  86. struct intrusive_tree_hook<VoidPointer, boost::container::splay_tree, OptimizeSize>
  87. {
  88. typedef typename dtl::bi::make_bs_set_base_hook
  89. < dtl::bi::void_pointer<VoidPointer>
  90. , dtl::bi::link_mode<dtl::bi::normal_link>
  91. >::type type;
  92. };
  93. //This trait is used to type-pun std::pair because in C++03
  94. //compilers std::pair is useless for C++11 features
  95. template<class T>
  96. struct tree_internal_data_type
  97. {
  98. typedef T type;
  99. };
  100. template<class T1, class T2>
  101. struct tree_internal_data_type< std::pair<T1, T2> >
  102. {
  103. typedef pair<typename boost::move_detail::remove_const<T1>::type, T2> type;
  104. };
  105. //The node to be store in the tree
  106. template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  107. struct tree_node
  108. : public intrusive_tree_hook<VoidPointer, tree_type_value, OptimizeSize>::type
  109. {
  110. public:
  111. typedef typename intrusive_tree_hook
  112. <VoidPointer, tree_type_value, OptimizeSize>::type hook_type;
  113. typedef T value_type;
  114. typedef typename tree_internal_data_type<T>::type internal_type;
  115. typedef tree_node< T, VoidPointer
  116. , tree_type_value, OptimizeSize> node_t;
  117. typedef typename boost::container::dtl::aligned_storage
  118. <sizeof(T), boost::container::dtl::alignment_of<T>::value>::type storage_t;
  119. storage_t m_storage;
  120. #if defined(BOOST_GCC) && (BOOST_GCC >= 40600) && (BOOST_GCC < 80000)
  121. #pragma GCC diagnostic push
  122. #pragma GCC diagnostic ignored "-Wstrict-aliasing"
  123. #define BOOST_CONTAINER_DISABLE_ALIASING_WARNING
  124. # endif
  125. BOOST_CONTAINER_FORCEINLINE T &get_data()
  126. { return *reinterpret_cast<T*>(this->m_storage.data); }
  127. BOOST_CONTAINER_FORCEINLINE const T &get_data() const
  128. { return *reinterpret_cast<const T*>(this->m_storage.data); }
  129. BOOST_CONTAINER_FORCEINLINE T *get_data_ptr()
  130. { return reinterpret_cast<T*>(this->m_storage.data); }
  131. BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const
  132. { return reinterpret_cast<T*>(this->m_storage.data); }
  133. BOOST_CONTAINER_FORCEINLINE internal_type &get_real_data()
  134. { return *reinterpret_cast<internal_type*>(this->m_storage.data); }
  135. BOOST_CONTAINER_FORCEINLINE const internal_type &get_real_data() const
  136. { return *reinterpret_cast<const internal_type*>(this->m_storage.data); }
  137. BOOST_CONTAINER_FORCEINLINE internal_type *get_real_data_ptr()
  138. { return reinterpret_cast<internal_type*>(this->m_storage.data); }
  139. BOOST_CONTAINER_FORCEINLINE const internal_type *get_real_data_ptr() const
  140. { return reinterpret_cast<internal_type*>(this->m_storage.data); }
  141. BOOST_CONTAINER_FORCEINLINE ~tree_node()
  142. { reinterpret_cast<internal_type*>(this->m_storage.data)->~internal_type(); }
  143. #if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING)
  144. #pragma GCC diagnostic pop
  145. #undef BOOST_CONTAINER_DISABLE_ALIASING_WARNING
  146. # endif
  147. BOOST_CONTAINER_FORCEINLINE void destroy_header()
  148. { static_cast<hook_type*>(this)->~hook_type(); }
  149. template<class T1, class T2>
  150. BOOST_CONTAINER_FORCEINLINE void do_assign(const std::pair<const T1, T2> &p)
  151. {
  152. const_cast<T1&>(this->get_real_data().first) = p.first;
  153. this->get_real_data().second = p.second;
  154. }
  155. template<class T1, class T2>
  156. BOOST_CONTAINER_FORCEINLINE void do_assign(const pair<const T1, T2> &p)
  157. {
  158. const_cast<T1&>(this->get_real_data().first) = p.first;
  159. this->get_real_data().second = p.second;
  160. }
  161. template<class V>
  162. BOOST_CONTAINER_FORCEINLINE void do_assign(const V &v)
  163. { this->get_real_data() = v; }
  164. template<class T1, class T2>
  165. BOOST_CONTAINER_FORCEINLINE void do_move_assign(std::pair<const T1, T2> &p)
  166. {
  167. const_cast<T1&>(this->get_real_data().first) = ::boost::move(p.first);
  168. this->get_real_data().second = ::boost::move(p.second);
  169. }
  170. template<class T1, class T2>
  171. BOOST_CONTAINER_FORCEINLINE void do_move_assign(pair<const T1, T2> &p)
  172. {
  173. const_cast<T1&>(this->get_real_data().first) = ::boost::move(p.first);
  174. this->get_real_data().second = ::boost::move(p.second);
  175. }
  176. template<class V>
  177. BOOST_CONTAINER_FORCEINLINE void do_move_assign(V &v)
  178. { this->get_real_data() = ::boost::move(v); }
  179. };
  180. template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  181. struct iiterator_node_value_type< tree_node<T, VoidPointer, tree_type_value, OptimizeSize> > {
  182. typedef T type;
  183. };
  184. template<class Node, class Icont>
  185. class insert_equal_end_hint_functor
  186. {
  187. Icont &icont_;
  188. public:
  189. BOOST_CONTAINER_FORCEINLINE insert_equal_end_hint_functor(Icont &icont)
  190. : icont_(icont)
  191. {}
  192. BOOST_CONTAINER_FORCEINLINE void operator()(Node &n)
  193. { this->icont_.insert_equal(this->icont_.cend(), n); }
  194. };
  195. template<class Node, class Icont>
  196. class push_back_functor
  197. {
  198. Icont &icont_;
  199. public:
  200. BOOST_CONTAINER_FORCEINLINE push_back_functor(Icont &icont)
  201. : icont_(icont)
  202. {}
  203. BOOST_CONTAINER_FORCEINLINE void operator()(Node &n)
  204. { this->icont_.push_back(n); }
  205. };
  206. }//namespace dtl {
  207. namespace dtl {
  208. template< class NodeType, class NodeCompareType
  209. , class SizeType, class HookType
  210. , boost::container::tree_type_enum tree_type_value>
  211. struct intrusive_tree_dispatch;
  212. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  213. struct intrusive_tree_dispatch
  214. <NodeType, NodeCompareType, SizeType, HookType, boost::container::red_black_tree>
  215. {
  216. typedef typename dtl::bi::make_rbtree
  217. <NodeType
  218. ,dtl::bi::compare<NodeCompareType>
  219. ,dtl::bi::base_hook<HookType>
  220. ,dtl::bi::constant_time_size<true>
  221. ,dtl::bi::size_type<SizeType>
  222. >::type type;
  223. };
  224. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  225. struct intrusive_tree_dispatch
  226. <NodeType, NodeCompareType, SizeType, HookType, boost::container::avl_tree>
  227. {
  228. typedef typename dtl::bi::make_avltree
  229. <NodeType
  230. ,dtl::bi::compare<NodeCompareType>
  231. ,dtl::bi::base_hook<HookType>
  232. ,dtl::bi::constant_time_size<true>
  233. ,dtl::bi::size_type<SizeType>
  234. >::type type;
  235. };
  236. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  237. struct intrusive_tree_dispatch
  238. <NodeType, NodeCompareType, SizeType, HookType, boost::container::scapegoat_tree>
  239. {
  240. typedef typename dtl::bi::make_sgtree
  241. <NodeType
  242. ,dtl::bi::compare<NodeCompareType>
  243. ,dtl::bi::base_hook<HookType>
  244. ,dtl::bi::floating_point<true>
  245. ,dtl::bi::size_type<SizeType>
  246. >::type type;
  247. };
  248. template<class NodeType, class NodeCompareType, class SizeType, class HookType>
  249. struct intrusive_tree_dispatch
  250. <NodeType, NodeCompareType, SizeType, HookType, boost::container::splay_tree>
  251. {
  252. typedef typename dtl::bi::make_splaytree
  253. <NodeType
  254. ,dtl::bi::compare<NodeCompareType>
  255. ,dtl::bi::base_hook<HookType>
  256. ,dtl::bi::constant_time_size<true>
  257. ,dtl::bi::size_type<SizeType>
  258. >::type type;
  259. };
  260. template<class Allocator, class ValueCompare, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  261. struct intrusive_tree_type
  262. {
  263. private:
  264. typedef typename boost::container::
  265. allocator_traits<Allocator>::value_type value_type;
  266. typedef typename boost::container::
  267. allocator_traits<Allocator>::void_pointer void_pointer;
  268. typedef typename boost::container::
  269. allocator_traits<Allocator>::size_type size_type;
  270. typedef typename dtl::tree_node
  271. < value_type, void_pointer
  272. , tree_type_value, OptimizeSize> node_t;
  273. typedef value_to_node_compare
  274. <node_t, ValueCompare> node_compare_type;
  275. //Deducing the hook type from node_t (e.g. node_t::hook_type) would
  276. //provoke an early instantiation of node_t that could ruin recursive
  277. //tree definitions, so retype the complete type to avoid any problem.
  278. typedef typename intrusive_tree_hook
  279. <void_pointer, tree_type_value
  280. , OptimizeSize>::type hook_type;
  281. public:
  282. typedef typename intrusive_tree_dispatch
  283. < node_t, node_compare_type
  284. , size_type, hook_type
  285. , tree_type_value>::type type;
  286. };
  287. //Trait to detect manually rebalanceable tree types
  288. template<boost::container::tree_type_enum tree_type_value>
  289. struct is_manually_balanceable
  290. { static const bool value = true; };
  291. template<> struct is_manually_balanceable<red_black_tree>
  292. { static const bool value = false; };
  293. template<> struct is_manually_balanceable<avl_tree>
  294. { static const bool value = false; };
  295. //Proxy traits to implement different operations depending on the
  296. //is_manually_balanceable<>::value
  297. template< boost::container::tree_type_enum tree_type_value
  298. , bool IsManuallyRebalanceable = is_manually_balanceable<tree_type_value>::value>
  299. struct intrusive_tree_proxy
  300. {
  301. template<class Icont>
  302. BOOST_CONTAINER_FORCEINLINE static void rebalance(Icont &) {}
  303. };
  304. template<boost::container::tree_type_enum tree_type_value>
  305. struct intrusive_tree_proxy<tree_type_value, true>
  306. {
  307. template<class Icont>
  308. BOOST_CONTAINER_FORCEINLINE static void rebalance(Icont &c)
  309. { c.rebalance(); }
  310. };
  311. } //namespace dtl {
  312. namespace dtl {
  313. //This functor will be used with Intrusive clone functions to obtain
  314. //already allocated nodes from a intrusive container instead of
  315. //allocating new ones. When the intrusive container runs out of nodes
  316. //the node holder is used instead.
  317. template<class AllocHolder, bool DoMove>
  318. class RecyclingCloner
  319. {
  320. typedef typename AllocHolder::intrusive_container intrusive_container;
  321. typedef typename AllocHolder::Node node_t;
  322. typedef typename AllocHolder::NodePtr node_ptr_type;
  323. public:
  324. RecyclingCloner(AllocHolder &holder, intrusive_container &itree)
  325. : m_holder(holder), m_icont(itree)
  326. {}
  327. BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type &p, node_t &other, bool_<true>)
  328. { p->do_move_assign(other.get_real_data()); }
  329. BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type &p, const node_t &other, bool_<false>)
  330. { p->do_assign(other.get_real_data()); }
  331. node_ptr_type operator()
  332. (typename dtl::if_c<DoMove, node_t &, const node_t&>::type other) const
  333. {
  334. if(node_ptr_type p = m_icont.unlink_leftmost_without_rebalance()){
  335. //First recycle a node (this can't throw)
  336. BOOST_TRY{
  337. //This can throw
  338. this->do_assign(p, other, bool_<DoMove>());
  339. return p;
  340. }
  341. BOOST_CATCH(...){
  342. //If there is an exception destroy the whole source
  343. m_holder.destroy_node(p);
  344. while((p = m_icont.unlink_leftmost_without_rebalance())){
  345. m_holder.destroy_node(p);
  346. }
  347. BOOST_RETHROW
  348. }
  349. BOOST_CATCH_END
  350. }
  351. else{
  352. return m_holder.create_node(boost::move(other.get_real_data()));
  353. }
  354. }
  355. AllocHolder &m_holder;
  356. intrusive_container &m_icont;
  357. };
  358. template<class KeyCompare, class KeyOfValue>
  359. struct key_node_compare
  360. : public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
  361. {
  362. BOOST_CONTAINER_FORCEINLINE explicit key_node_compare(const KeyCompare &comp)
  363. : base_t(comp)
  364. {}
  365. typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
  366. typedef KeyCompare key_compare;
  367. typedef KeyOfValue key_of_value;
  368. typedef typename KeyOfValue::type key_type;
  369. template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
  370. BOOST_CONTAINER_FORCEINLINE static const key_type &
  371. key_from(const tree_node<T, VoidPointer, tree_type_value, OptimizeSize> &n)
  372. {
  373. return key_of_value()(n.get_data());
  374. }
  375. template <class T>
  376. BOOST_CONTAINER_FORCEINLINE static const T &
  377. key_from(const T &t)
  378. {
  379. return t;
  380. }
  381. BOOST_CONTAINER_FORCEINLINE const key_compare &key_comp() const
  382. { return static_cast<const key_compare &>(*this); }
  383. BOOST_CONTAINER_FORCEINLINE key_compare &key_comp()
  384. { return static_cast<key_compare &>(*this); }
  385. BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
  386. { return this->key_comp()(key1, key2); }
  387. template<class U>
  388. BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const U &nonkey2) const
  389. { return this->key_comp()(key1, this->key_from(nonkey2)); }
  390. template<class U>
  391. BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2) const
  392. { return this->key_comp()(this->key_from(nonkey1), key2); }
  393. template<class U, class V>
  394. BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const V &nonkey2) const
  395. { return this->key_comp()(this->key_from(nonkey1), this->key_from(nonkey2)); }
  396. };
  397. template<class Options>
  398. struct get_tree_opt
  399. {
  400. typedef Options type;
  401. };
  402. template<>
  403. struct get_tree_opt<void>
  404. {
  405. typedef tree_assoc_defaults type;
  406. };
  407. template<class, class KeyOfValue>
  408. struct real_key_of_value
  409. {
  410. typedef KeyOfValue type;
  411. };
  412. template<class T>
  413. struct real_key_of_value<T, void>
  414. {
  415. typedef dtl::identity<T> type;
  416. };
  417. template<class T1, class T2>
  418. struct real_key_of_value<std::pair<T1, T2>, int>
  419. {
  420. typedef dtl::select1st<T1> type;
  421. };
  422. template<class T1, class T2>
  423. struct real_key_of_value<boost::container::pair<T1, T2>, int>
  424. {
  425. typedef dtl::select1st<T1> type;
  426. };
  427. template <class T, class KeyOfValue, class Compare, class Allocator, class Options>
  428. class tree
  429. : public dtl::node_alloc_holder
  430. < typename real_allocator<T, Allocator>::type
  431. , typename dtl::intrusive_tree_type
  432. < typename real_allocator<T, Allocator>::type
  433. , tree_value_compare
  434. <typename allocator_traits<typename real_allocator<T, Allocator>::type>::pointer, Compare, typename real_key_of_value<T, KeyOfValue>::type>
  435. , get_tree_opt<Options>::type::tree_type
  436. , get_tree_opt<Options>::type::optimize_size
  437. >::type
  438. >
  439. {
  440. typedef tree < T, KeyOfValue
  441. , Compare, Allocator, Options> ThisType;
  442. public:
  443. typedef typename real_allocator<T, Allocator>::type allocator_type;
  444. private:
  445. typedef allocator_traits<allocator_type> allocator_traits_t;
  446. typedef typename real_key_of_value<T, KeyOfValue>::type key_of_value_t;
  447. typedef tree_value_compare
  448. < typename allocator_traits_t::pointer
  449. , Compare
  450. , key_of_value_t> ValComp;
  451. typedef typename get_tree_opt<Options>::type options_type;
  452. typedef typename dtl::intrusive_tree_type
  453. < allocator_type, ValComp
  454. , options_type::tree_type
  455. , options_type::optimize_size
  456. >::type Icont;
  457. typedef dtl::node_alloc_holder
  458. <allocator_type, Icont> AllocHolder;
  459. typedef typename AllocHolder::NodePtr NodePtr;
  460. typedef typename AllocHolder::NodeAlloc NodeAlloc;
  461. typedef boost::container::
  462. allocator_traits<NodeAlloc> allocator_traits_type;
  463. typedef typename AllocHolder::ValAlloc ValAlloc;
  464. typedef typename AllocHolder::Node Node;
  465. typedef typename Icont::iterator iiterator;
  466. typedef typename Icont::const_iterator iconst_iterator;
  467. typedef dtl::allocator_destroyer<NodeAlloc> Destroyer;
  468. typedef typename AllocHolder::alloc_version alloc_version;
  469. typedef intrusive_tree_proxy<options_type::tree_type> intrusive_tree_proxy_t;
  470. BOOST_COPYABLE_AND_MOVABLE(tree)
  471. public:
  472. typedef typename key_of_value_t::type key_type;
  473. typedef T value_type;
  474. typedef Compare key_compare;
  475. typedef ValComp value_compare;
  476. typedef typename boost::container::
  477. allocator_traits<allocator_type>::pointer pointer;
  478. typedef typename boost::container::
  479. allocator_traits<allocator_type>::const_pointer const_pointer;
  480. typedef typename boost::container::
  481. allocator_traits<allocator_type>::reference reference;
  482. typedef typename boost::container::
  483. allocator_traits<allocator_type>::const_reference const_reference;
  484. typedef typename boost::container::
  485. allocator_traits<allocator_type>::size_type size_type;
  486. typedef typename boost::container::
  487. allocator_traits<allocator_type>::difference_type difference_type;
  488. typedef dtl::iterator_from_iiterator
  489. <iiterator, false> iterator;
  490. typedef dtl::iterator_from_iiterator
  491. <iiterator, true > const_iterator;
  492. typedef boost::container::reverse_iterator
  493. <iterator> reverse_iterator;
  494. typedef boost::container::reverse_iterator
  495. <const_iterator> const_reverse_iterator;
  496. typedef node_handle
  497. < NodeAlloc, void> node_type;
  498. typedef insert_return_type_base
  499. <iterator, node_type> insert_return_type;
  500. typedef NodeAlloc stored_allocator_type;
  501. private:
  502. typedef key_node_compare<key_compare, key_of_value_t> KeyNodeCompare;
  503. public:
  504. BOOST_CONTAINER_FORCEINLINE tree()
  505. : AllocHolder()
  506. {}
  507. BOOST_CONTAINER_FORCEINLINE explicit tree(const key_compare& comp)
  508. : AllocHolder(ValComp(comp))
  509. {}
  510. BOOST_CONTAINER_FORCEINLINE explicit tree(const key_compare& comp, const allocator_type& a)
  511. : AllocHolder(ValComp(comp), a)
  512. {}
  513. BOOST_CONTAINER_FORCEINLINE explicit tree(const allocator_type& a)
  514. : AllocHolder(a)
  515. {}
  516. template <class InputIterator>
  517. tree(bool unique_insertion, InputIterator first, InputIterator last)
  518. : AllocHolder(value_compare(key_compare()))
  519. {
  520. this->tree_construct(unique_insertion, first, last);
  521. //AllocHolder clears in case of exception
  522. }
  523. template <class InputIterator>
  524. tree(bool unique_insertion, InputIterator first, InputIterator last, const key_compare& comp)
  525. : AllocHolder(value_compare(comp))
  526. {
  527. this->tree_construct(unique_insertion, first, last);
  528. //AllocHolder clears in case of exception
  529. }
  530. template <class InputIterator>
  531. tree(bool unique_insertion, InputIterator first, InputIterator last, const key_compare& comp, const allocator_type& a)
  532. : AllocHolder(value_compare(comp), a)
  533. {
  534. this->tree_construct(unique_insertion, first, last);
  535. //AllocHolder clears in case of exception
  536. }
  537. //construct with ordered range
  538. template <class InputIterator>
  539. tree( ordered_range_t, InputIterator first, InputIterator last)
  540. : AllocHolder(value_compare(key_compare()))
  541. {
  542. this->tree_construct(ordered_range_t(), first, last);
  543. }
  544. template <class InputIterator>
  545. tree( ordered_range_t, InputIterator first, InputIterator last, const key_compare& comp)
  546. : AllocHolder(value_compare(comp))
  547. {
  548. this->tree_construct(ordered_range_t(), first, last);
  549. }
  550. template <class InputIterator>
  551. tree( ordered_range_t, InputIterator first, InputIterator last
  552. , const key_compare& comp, const allocator_type& a)
  553. : AllocHolder(value_compare(comp), a)
  554. {
  555. this->tree_construct(ordered_range_t(), first, last);
  556. }
  557. private:
  558. template <class InputIterator>
  559. void tree_construct(bool unique_insertion, InputIterator first, InputIterator last)
  560. {
  561. //Use cend() as hint to achieve linear time for
  562. //ordered ranges as required by the standard
  563. //for the constructor
  564. if(unique_insertion){
  565. const const_iterator end_it(this->cend());
  566. for ( ; first != last; ++first){
  567. this->insert_unique_hint_convertible(end_it, *first);
  568. }
  569. }
  570. else{
  571. this->tree_construct_non_unique(first, last);
  572. }
  573. }
  574. template <class InputIterator>
  575. void tree_construct_non_unique(InputIterator first, InputIterator last
  576. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  577. , typename dtl::enable_if_or
  578. < void
  579. , dtl::is_same<alloc_version, version_1>
  580. , dtl::is_input_iterator<InputIterator>
  581. >::type * = 0
  582. #endif
  583. )
  584. {
  585. //Use cend() as hint to achieve linear time for
  586. //ordered ranges as required by the standard
  587. //for the constructor
  588. const const_iterator end_it(this->cend());
  589. for ( ; first != last; ++first){
  590. this->insert_equal_hint_convertible(end_it, *first);
  591. }
  592. }
  593. template <class InputIterator>
  594. void tree_construct_non_unique(InputIterator first, InputIterator last
  595. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  596. , typename dtl::disable_if_or
  597. < void
  598. , dtl::is_same<alloc_version, version_1>
  599. , dtl::is_input_iterator<InputIterator>
  600. >::type * = 0
  601. #endif
  602. )
  603. {
  604. //Optimized allocation and construction
  605. this->allocate_many_and_construct
  606. ( first, boost::container::iterator_distance(first, last)
  607. , insert_equal_end_hint_functor<Node, Icont>(this->icont()));
  608. }
  609. template <class InputIterator>
  610. void tree_construct( ordered_range_t, InputIterator first, InputIterator last
  611. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  612. , typename dtl::disable_if_or
  613. < void
  614. , dtl::is_same<alloc_version, version_1>
  615. , dtl::is_input_iterator<InputIterator>
  616. >::type * = 0
  617. #endif
  618. )
  619. {
  620. //Optimized allocation and construction
  621. this->allocate_many_and_construct
  622. ( first, boost::container::iterator_distance(first, last)
  623. , dtl::push_back_functor<Node, Icont>(this->icont()));
  624. //AllocHolder clears in case of exception
  625. }
  626. template <class InputIterator>
  627. void tree_construct( ordered_range_t, InputIterator first, InputIterator last
  628. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  629. , typename dtl::enable_if_or
  630. < void
  631. , dtl::is_same<alloc_version, version_1>
  632. , dtl::is_input_iterator<InputIterator>
  633. >::type * = 0
  634. #endif
  635. )
  636. {
  637. for ( ; first != last; ++first){
  638. this->push_back_impl(*first);
  639. }
  640. }
  641. public:
  642. BOOST_CONTAINER_FORCEINLINE tree(const tree& x)
  643. : AllocHolder(x, x.value_comp())
  644. {
  645. this->icont().clone_from
  646. (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc()));
  647. }
  648. BOOST_CONTAINER_FORCEINLINE tree(BOOST_RV_REF(tree) x)
  649. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<Compare>::value)
  650. : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x), x.value_comp())
  651. {}
  652. BOOST_CONTAINER_FORCEINLINE tree(const tree& x, const allocator_type &a)
  653. : AllocHolder(x.value_comp(), a)
  654. {
  655. this->icont().clone_from
  656. (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc()));
  657. //AllocHolder clears in case of exception
  658. }
  659. tree(BOOST_RV_REF(tree) x, const allocator_type &a)
  660. : AllocHolder(x.value_comp(), a)
  661. {
  662. if(this->node_alloc() == x.node_alloc()){
  663. this->icont().swap(x.icont());
  664. }
  665. else{
  666. this->icont().clone_from
  667. (boost::move(x.icont()), typename AllocHolder::move_cloner(*this), Destroyer(this->node_alloc()));
  668. }
  669. //AllocHolder clears in case of exception
  670. }
  671. BOOST_CONTAINER_FORCEINLINE ~tree()
  672. {} //AllocHolder clears the tree
  673. tree& operator=(BOOST_COPY_ASSIGN_REF(tree) x)
  674. {
  675. if (BOOST_LIKELY(this != &x)) {
  676. NodeAlloc &this_alloc = this->get_stored_allocator();
  677. const NodeAlloc &x_alloc = x.get_stored_allocator();
  678. dtl::bool_<allocator_traits<NodeAlloc>::
  679. propagate_on_container_copy_assignment::value> flag;
  680. if(flag && this_alloc != x_alloc){
  681. this->clear();
  682. }
  683. this->AllocHolder::copy_assign_alloc(x);
  684. //Transfer all the nodes to a temporary tree
  685. //If anything goes wrong, all the nodes will be destroyed
  686. //automatically
  687. Icont other_tree(::boost::move(this->icont()));
  688. //Now recreate the source tree reusing nodes stored by other_tree
  689. this->icont().clone_from
  690. (x.icont()
  691. , RecyclingCloner<AllocHolder, false>(*this, other_tree)
  692. , Destroyer(this->node_alloc()));
  693. //If there are remaining nodes, destroy them
  694. NodePtr p;
  695. while((p = other_tree.unlink_leftmost_without_rebalance())){
  696. AllocHolder::destroy_node(p);
  697. }
  698. }
  699. return *this;
  700. }
  701. tree& operator=(BOOST_RV_REF(tree) x)
  702. BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
  703. allocator_traits_type::is_always_equal::value) &&
  704. boost::container::dtl::is_nothrow_move_assignable<Compare>::value)
  705. {
  706. if (BOOST_LIKELY(this != &x)) {
  707. NodeAlloc &this_alloc = this->node_alloc();
  708. NodeAlloc &x_alloc = x.node_alloc();
  709. const bool propagate_alloc = allocator_traits<NodeAlloc>::
  710. propagate_on_container_move_assignment::value;
  711. const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
  712. //Resources can be transferred if both allocators are
  713. //going to be equal after this function (either propagated or already equal)
  714. if(propagate_alloc || allocators_equal){
  715. //Destroy
  716. this->clear();
  717. //Move allocator if needed
  718. this->AllocHolder::move_assign_alloc(x);
  719. //Obtain resources
  720. this->icont() = boost::move(x.icont());
  721. }
  722. //Else do a one by one move
  723. else{
  724. //Transfer all the nodes to a temporary tree
  725. //If anything goes wrong, all the nodes will be destroyed
  726. //automatically
  727. Icont other_tree(::boost::move(this->icont()));
  728. //Now recreate the source tree reusing nodes stored by other_tree
  729. this->icont().clone_from
  730. (::boost::move(x.icont())
  731. , RecyclingCloner<AllocHolder, true>(*this, other_tree)
  732. , Destroyer(this->node_alloc()));
  733. //If there are remaining nodes, destroy them
  734. NodePtr p;
  735. while((p = other_tree.unlink_leftmost_without_rebalance())){
  736. AllocHolder::destroy_node(p);
  737. }
  738. }
  739. }
  740. return *this;
  741. }
  742. public:
  743. // accessors:
  744. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  745. value_compare value_comp() const
  746. { return this->icont().value_comp().predicate(); }
  747. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  748. key_compare key_comp() const
  749. { return this->icont().value_comp().predicate().key_comp(); }
  750. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  751. allocator_type get_allocator() const
  752. { return allocator_type(this->node_alloc()); }
  753. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  754. const stored_allocator_type &get_stored_allocator() const
  755. { return this->node_alloc(); }
  756. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  757. stored_allocator_type &get_stored_allocator()
  758. { return this->node_alloc(); }
  759. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  760. iterator begin()
  761. { return iterator(this->icont().begin()); }
  762. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  763. const_iterator begin() const
  764. { return this->cbegin(); }
  765. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  766. iterator end()
  767. { return iterator(this->icont().end()); }
  768. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  769. const_iterator end() const
  770. { return this->cend(); }
  771. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  772. reverse_iterator rbegin()
  773. { return reverse_iterator(end()); }
  774. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  775. const_reverse_iterator rbegin() const
  776. { return this->crbegin(); }
  777. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  778. reverse_iterator rend()
  779. { return reverse_iterator(begin()); }
  780. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  781. const_reverse_iterator rend() const
  782. { return this->crend(); }
  783. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
  784. //!
  785. //! <b>Throws</b>: Nothing.
  786. //!
  787. //! <b>Complexity</b>: Constant.
  788. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  789. const_iterator cbegin() const
  790. { return const_iterator(this->non_const_icont().begin()); }
  791. //! <b>Effects</b>: Returns a const_iterator to the end of the container.
  792. //!
  793. //! <b>Throws</b>: Nothing.
  794. //!
  795. //! <b>Complexity</b>: Constant.
  796. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  797. const_iterator cend() const
  798. { return const_iterator(this->non_const_icont().end()); }
  799. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
  800. //! of the reversed container.
  801. //!
  802. //! <b>Throws</b>: Nothing.
  803. //!
  804. //! <b>Complexity</b>: Constant.
  805. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  806. const_reverse_iterator crbegin() const
  807. { return const_reverse_iterator(cend()); }
  808. //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
  809. //! of the reversed container.
  810. //!
  811. //! <b>Throws</b>: Nothing.
  812. //!
  813. //! <b>Complexity</b>: Constant.
  814. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  815. const_reverse_iterator crend() const
  816. { return const_reverse_iterator(cbegin()); }
  817. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  818. bool empty() const
  819. { return !this->size(); }
  820. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  821. size_type size() const
  822. { return this->icont().size(); }
  823. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  824. size_type max_size() const
  825. { return AllocHolder::max_size(); }
  826. BOOST_CONTAINER_FORCEINLINE void swap(ThisType& x)
  827. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  828. && boost::container::dtl::is_nothrow_swappable<Compare>::value )
  829. { AllocHolder::swap(x); }
  830. public:
  831. typedef typename Icont::insert_commit_data insert_commit_data;
  832. // insert/erase
  833. std::pair<iterator,bool> insert_unique_check
  834. (const key_type& key, insert_commit_data &data)
  835. {
  836. std::pair<iiterator, bool> ret =
  837. this->icont().insert_unique_check(key, KeyNodeCompare(key_comp()), data);
  838. return std::pair<iterator, bool>(iterator(ret.first), ret.second);
  839. }
  840. std::pair<iterator,bool> insert_unique_check
  841. (const_iterator hint, const key_type& key, insert_commit_data &data)
  842. {
  843. BOOST_ASSERT((priv_is_linked)(hint));
  844. std::pair<iiterator, bool> ret =
  845. this->icont().insert_unique_check(hint.get(), key, KeyNodeCompare(key_comp()), data);
  846. return std::pair<iterator, bool>(iterator(ret.first), ret.second);
  847. }
  848. template<class MovableConvertible>
  849. iterator insert_unique_commit
  850. (BOOST_FWD_REF(MovableConvertible) v, insert_commit_data &data)
  851. {
  852. NodePtr tmp = AllocHolder::create_node(boost::forward<MovableConvertible>(v));
  853. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  854. iterator ret(this->icont().insert_unique_commit(*tmp, data));
  855. destroy_deallocator.release();
  856. return ret;
  857. }
  858. template<class MovableConvertible>
  859. std::pair<iterator,bool> insert_unique_convertible(BOOST_FWD_REF(MovableConvertible) v)
  860. {
  861. insert_commit_data data;
  862. std::pair<iterator,bool> ret =
  863. this->insert_unique_check(key_of_value_t()(v), data);
  864. if(ret.second){
  865. ret.first = this->insert_unique_commit(boost::forward<MovableConvertible>(v), data);
  866. }
  867. return ret;
  868. }
  869. template<class MovableConvertible>
  870. iterator insert_unique_hint_convertible(const_iterator hint, BOOST_FWD_REF(MovableConvertible) v)
  871. {
  872. BOOST_ASSERT((priv_is_linked)(hint));
  873. insert_commit_data data;
  874. std::pair<iterator,bool> ret =
  875. this->insert_unique_check(hint, key_of_value_t()(v), data);
  876. if(!ret.second)
  877. return ret.first;
  878. return this->insert_unique_commit(boost::forward<MovableConvertible>(v), data);
  879. }
  880. private:
  881. template<class KeyConvertible, class M>
  882. iiterator priv_insert_or_assign_commit
  883. (BOOST_FWD_REF(KeyConvertible) key, BOOST_FWD_REF(M) obj, insert_commit_data &data)
  884. {
  885. NodePtr tmp = AllocHolder::create_node(boost::forward<KeyConvertible>(key), boost::forward<M>(obj));
  886. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  887. iiterator ret(this->icont().insert_unique_commit(*tmp, data));
  888. destroy_deallocator.release();
  889. return ret;
  890. }
  891. bool priv_is_linked(const_iterator const position) const
  892. {
  893. iiterator const cur(position.get());
  894. return cur == this->icont().end() ||
  895. cur == this->icont().root() ||
  896. iiterator(cur).go_parent().go_left() == cur ||
  897. iiterator(cur).go_parent().go_right() == cur;
  898. }
  899. template<class MovableConvertible>
  900. void push_back_impl(BOOST_FWD_REF(MovableConvertible) v)
  901. {
  902. NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
  903. //push_back has no-throw guarantee so avoid any deallocator/destroyer
  904. this->icont().push_back(*tmp);
  905. }
  906. std::pair<iterator, bool> emplace_unique_node(NodePtr p)
  907. {
  908. value_type &v = p->get_data();
  909. insert_commit_data data;
  910. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(p, this->node_alloc());
  911. std::pair<iterator,bool> ret =
  912. this->insert_unique_check(key_of_value_t()(v), data);
  913. if(!ret.second){
  914. return ret;
  915. }
  916. //No throw insertion part, release rollback
  917. destroy_deallocator.release();
  918. return std::pair<iterator,bool>
  919. ( iterator(this->icont().insert_unique_commit(*p, data))
  920. , true );
  921. }
  922. iterator emplace_hint_unique_node(const_iterator hint, NodePtr p)
  923. {
  924. BOOST_ASSERT((priv_is_linked)(hint));
  925. value_type &v = p->get_data();
  926. insert_commit_data data;
  927. std::pair<iterator,bool> ret =
  928. this->insert_unique_check(hint, key_of_value_t()(v), data);
  929. if(!ret.second){
  930. //Destroy unneeded node
  931. Destroyer(this->node_alloc())(p);
  932. return ret.first;
  933. }
  934. return iterator(this->icont().insert_unique_commit(*p, data));
  935. }
  936. public:
  937. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  938. template <class... Args>
  939. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> emplace_unique(BOOST_FWD_REF(Args)... args)
  940. { return this->emplace_unique_node(AllocHolder::create_node(boost::forward<Args>(args)...)); }
  941. template <class... Args>
  942. BOOST_CONTAINER_FORCEINLINE iterator emplace_hint_unique(const_iterator hint, BOOST_FWD_REF(Args)... args)
  943. { return this->emplace_hint_unique_node(hint, AllocHolder::create_node(boost::forward<Args>(args)...)); }
  944. template <class... Args>
  945. iterator emplace_equal(BOOST_FWD_REF(Args)... args)
  946. {
  947. NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
  948. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  949. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
  950. destroy_deallocator.release();
  951. return ret;
  952. }
  953. template <class... Args>
  954. iterator emplace_hint_equal(const_iterator hint, BOOST_FWD_REF(Args)... args)
  955. {
  956. BOOST_ASSERT((priv_is_linked)(hint));
  957. NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
  958. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  959. iterator ret(this->icont().insert_equal(hint.get(), *tmp));
  960. destroy_deallocator.release();
  961. return ret;
  962. }
  963. template <class KeyType, class... Args>
  964. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace
  965. (const_iterator hint, BOOST_FWD_REF(KeyType) key, BOOST_FWD_REF(Args)... args)
  966. {
  967. insert_commit_data data;
  968. const key_type & k = key; //Support emulated rvalue references
  969. std::pair<iiterator, bool> ret =
  970. hint == const_iterator() ? this->icont().insert_unique_check( k, KeyNodeCompare(key_comp()), data)
  971. : this->icont().insert_unique_check(hint.get(), k, KeyNodeCompare(key_comp()), data);
  972. if(ret.second){
  973. ret.first = this->icont().insert_unique_commit
  974. (*AllocHolder::create_node(try_emplace_t(), boost::forward<KeyType>(key), boost::forward<Args>(args)...), data);
  975. }
  976. return std::pair<iterator, bool>(iterator(ret.first), ret.second);
  977. }
  978. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  979. #define BOOST_CONTAINER_TREE_EMPLACE_CODE(N) \
  980. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  981. std::pair<iterator, bool> emplace_unique(BOOST_MOVE_UREF##N)\
  982. { return this->emplace_unique_node(AllocHolder::create_node(BOOST_MOVE_FWD##N)); }\
  983. \
  984. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  985. iterator emplace_hint_unique(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  986. { return this->emplace_hint_unique_node(hint, AllocHolder::create_node(BOOST_MOVE_FWD##N)); }\
  987. \
  988. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  989. iterator emplace_equal(BOOST_MOVE_UREF##N)\
  990. {\
  991. NodePtr tmp(AllocHolder::create_node(BOOST_MOVE_FWD##N));\
  992. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
  993. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));\
  994. destroy_deallocator.release();\
  995. return ret;\
  996. }\
  997. \
  998. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  999. iterator emplace_hint_equal(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1000. {\
  1001. BOOST_ASSERT((priv_is_linked)(hint));\
  1002. NodePtr tmp(AllocHolder::create_node(BOOST_MOVE_FWD##N));\
  1003. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
  1004. iterator ret(this->icont().insert_equal(hint.get(), *tmp));\
  1005. destroy_deallocator.release();\
  1006. return ret;\
  1007. }\
  1008. \
  1009. template <class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N>\
  1010. BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool>\
  1011. try_emplace(const_iterator hint, BOOST_FWD_REF(KeyType) key BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1012. {\
  1013. insert_commit_data data;\
  1014. const key_type & k = key;\
  1015. std::pair<iiterator, bool> ret =\
  1016. hint == const_iterator() ? this->icont().insert_unique_check( k, KeyNodeCompare(key_comp()), data)\
  1017. : this->icont().insert_unique_check(hint.get(), k, KeyNodeCompare(key_comp()), data);\
  1018. if(ret.second){\
  1019. ret.first = this->icont().insert_unique_commit\
  1020. (*AllocHolder::create_node(try_emplace_t(), boost::forward<KeyType>(key) BOOST_MOVE_I##N BOOST_MOVE_FWD##N), data);\
  1021. }\
  1022. return std::pair<iterator, bool>(iterator(ret.first), ret.second);\
  1023. }\
  1024. //
  1025. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_TREE_EMPLACE_CODE)
  1026. #undef BOOST_CONTAINER_TREE_EMPLACE_CODE
  1027. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1028. //BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_unique, value_type, iterator, this->insert_unique_hint_convertible, const_iterator, const_iterator)
  1029. template <class InputIterator>
  1030. void insert_unique_range(InputIterator first, InputIterator last)
  1031. {
  1032. for( ; first != last; ++first)
  1033. this->insert_unique_convertible(*first);
  1034. }
  1035. template<class MovableConvertible>
  1036. iterator insert_equal_convertible(BOOST_FWD_REF(MovableConvertible) v)
  1037. {
  1038. NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
  1039. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  1040. iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
  1041. destroy_deallocator.release();
  1042. return ret;
  1043. }
  1044. template<class MovableConvertible>
  1045. iterator insert_equal_hint_convertible(const_iterator hint, BOOST_FWD_REF(MovableConvertible) v)
  1046. {
  1047. BOOST_ASSERT((priv_is_linked)(hint));
  1048. NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
  1049. scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
  1050. iterator ret(this->icont().insert_equal(hint.get(), *tmp));
  1051. destroy_deallocator.release();
  1052. return ret;
  1053. }
  1054. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG
  1055. (insert_equal, value_type, iterator, this->insert_equal_hint_convertible, const_iterator, const_iterator)
  1056. template <class InputIterator>
  1057. void insert_equal_range(InputIterator first, InputIterator last)
  1058. {
  1059. for( ; first != last; ++first)
  1060. this->insert_equal_convertible(*first);
  1061. }
  1062. template<class KeyType, class M>
  1063. std::pair<iterator, bool> insert_or_assign(const_iterator hint, BOOST_FWD_REF(KeyType) key, BOOST_FWD_REF(M) obj)
  1064. {
  1065. insert_commit_data data;
  1066. const key_type & k = key; //Support emulated rvalue references
  1067. std::pair<iiterator, bool> ret =
  1068. hint == const_iterator() ? this->icont().insert_unique_check(k, KeyNodeCompare(key_comp()), data)
  1069. : this->icont().insert_unique_check(hint.get(), k, KeyNodeCompare(key_comp()), data);
  1070. if(ret.second){
  1071. ret.first = this->priv_insert_or_assign_commit(boost::forward<KeyType>(key), boost::forward<M>(obj), data);
  1072. }
  1073. else{
  1074. ret.first->get_data().second = boost::forward<M>(obj);
  1075. }
  1076. return std::pair<iterator, bool>(iterator(ret.first), ret.second);
  1077. }
  1078. iterator erase(const_iterator position)
  1079. {
  1080. BOOST_ASSERT(position != this->cend() && (priv_is_linked)(position));
  1081. return iterator(this->icont().erase_and_dispose(position.get(), Destroyer(this->node_alloc())));
  1082. }
  1083. BOOST_CONTAINER_FORCEINLINE size_type erase(const key_type& k)
  1084. { return AllocHolder::erase_key(k, KeyNodeCompare(key_comp()), alloc_version()); }
  1085. iterator erase(const_iterator first, const_iterator last)
  1086. {
  1087. BOOST_ASSERT(first == last || (first != this->cend() && (priv_is_linked)(first)));
  1088. BOOST_ASSERT(first == last || (priv_is_linked)(last));
  1089. return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version()));
  1090. }
  1091. node_type extract(const key_type& k)
  1092. {
  1093. iterator const it = this->find(k);
  1094. if(this->end() != it){
  1095. return this->extract(it);
  1096. }
  1097. return node_type();
  1098. }
  1099. node_type extract(const_iterator position)
  1100. {
  1101. BOOST_ASSERT(position != this->cend() && (priv_is_linked)(position));
  1102. iiterator const iit(position.get());
  1103. this->icont().erase(iit);
  1104. return node_type(iit.operator->(), this->node_alloc());
  1105. }
  1106. insert_return_type insert_unique_node(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1107. {
  1108. return this->insert_unique_node(this->end(), boost::move(nh));
  1109. }
  1110. insert_return_type insert_unique_node(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1111. {
  1112. insert_return_type irt; //inserted == false, node.empty()
  1113. if(!nh.empty()){
  1114. insert_commit_data data;
  1115. std::pair<iterator,bool> ret =
  1116. this->insert_unique_check(hint, key_of_value_t()(nh.value()), data);
  1117. if(ret.second){
  1118. irt.inserted = true;
  1119. irt.position = iterator(this->icont().insert_unique_commit(*nh.get(), data));
  1120. nh.release();
  1121. }
  1122. else{
  1123. irt.position = ret.first;
  1124. irt.node = boost::move(nh);
  1125. }
  1126. }
  1127. else{
  1128. irt.position = this->end();
  1129. }
  1130. return BOOST_MOVE_RET(insert_return_type, irt);
  1131. }
  1132. iterator insert_equal_node(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1133. {
  1134. if(nh.empty()){
  1135. return this->end();
  1136. }
  1137. else{
  1138. NodePtr const p(nh.release());
  1139. return iterator(this->icont().insert_equal(*p));
  1140. }
  1141. }
  1142. iterator insert_equal_node(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
  1143. {
  1144. if(nh.empty()){
  1145. return this->end();
  1146. }
  1147. else{
  1148. NodePtr const p(nh.release());
  1149. return iterator(this->icont().insert_equal(hint.get(), *p));
  1150. }
  1151. }
  1152. template<class C2>
  1153. BOOST_CONTAINER_FORCEINLINE void merge_unique(tree<T, KeyOfValue, C2, Allocator, Options>& source)
  1154. { return this->icont().merge_unique(source.icont()); }
  1155. template<class C2>
  1156. BOOST_CONTAINER_FORCEINLINE void merge_equal(tree<T, KeyOfValue, C2, Allocator, Options>& source)
  1157. { return this->icont().merge_equal(source.icont()); }
  1158. BOOST_CONTAINER_FORCEINLINE void clear()
  1159. { AllocHolder::clear(alloc_version()); }
  1160. // search operations. Const and non-const overloads even if no iterator is returned
  1161. // so splay implementations can to their rebalancing when searching in non-const versions
  1162. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1163. iterator find(const key_type& k)
  1164. { return iterator(this->icont().find(k, KeyNodeCompare(key_comp()))); }
  1165. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1166. const_iterator find(const key_type& k) const
  1167. { return const_iterator(this->non_const_icont().find(k, KeyNodeCompare(key_comp()))); }
  1168. template <class K>
  1169. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1170. typename dtl::enable_if_transparent<key_compare, K, iterator>::type
  1171. find(const K& k)
  1172. { return iterator(this->icont().find(k, KeyNodeCompare(key_comp()))); }
  1173. template <class K>
  1174. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1175. typename dtl::enable_if_transparent<key_compare, K, const_iterator>::type
  1176. find(const K& k) const
  1177. { return const_iterator(this->non_const_icont().find(k, KeyNodeCompare(key_comp()))); }
  1178. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1179. size_type count(const key_type& k) const
  1180. { return size_type(this->icont().count(k, KeyNodeCompare(key_comp()))); }
  1181. template <class K>
  1182. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1183. typename dtl::enable_if_transparent<key_compare, K, size_type>::type
  1184. count(const K& k) const
  1185. { return size_type(this->icont().count(k, KeyNodeCompare(key_comp()))); }
  1186. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1187. bool contains(const key_type& x) const
  1188. { return this->find(x) != this->cend(); }
  1189. template<typename K>
  1190. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1191. typename dtl::enable_if_transparent<key_compare, K, bool>::type
  1192. contains(const K& x) const
  1193. { return this->find(x) != this->cend(); }
  1194. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1195. iterator lower_bound(const key_type& k)
  1196. { return iterator(this->icont().lower_bound(k, KeyNodeCompare(key_comp()))); }
  1197. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1198. const_iterator lower_bound(const key_type& k) const
  1199. { return const_iterator(this->non_const_icont().lower_bound(k, KeyNodeCompare(key_comp()))); }
  1200. template <class K>
  1201. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1202. typename dtl::enable_if_transparent<key_compare, K, iterator>::type
  1203. lower_bound(const K& k)
  1204. { return iterator(this->icont().lower_bound(k, KeyNodeCompare(key_comp()))); }
  1205. template <class K>
  1206. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1207. typename dtl::enable_if_transparent<key_compare, K, const_iterator>::type
  1208. lower_bound(const K& k) const
  1209. { return const_iterator(this->non_const_icont().lower_bound(k, KeyNodeCompare(key_comp()))); }
  1210. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1211. iterator upper_bound(const key_type& k)
  1212. { return iterator(this->icont().upper_bound(k, KeyNodeCompare(key_comp()))); }
  1213. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1214. const_iterator upper_bound(const key_type& k) const
  1215. { return const_iterator(this->non_const_icont().upper_bound(k, KeyNodeCompare(key_comp()))); }
  1216. template <class K>
  1217. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1218. typename dtl::enable_if_transparent<key_compare, K, iterator>::type
  1219. upper_bound(const K& k)
  1220. { return iterator(this->icont().upper_bound(k, KeyNodeCompare(key_comp()))); }
  1221. template <class K>
  1222. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1223. typename dtl::enable_if_transparent<key_compare, K, const_iterator>::type
  1224. upper_bound(const K& k) const
  1225. { return const_iterator(this->non_const_icont().upper_bound(k, KeyNodeCompare(key_comp()))); }
  1226. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1227. std::pair<iterator,iterator> equal_range(const key_type& k)
  1228. {
  1229. std::pair<iiterator, iiterator> ret =
  1230. this->icont().equal_range(k, KeyNodeCompare(key_comp()));
  1231. return std::pair<iterator,iterator>(iterator(ret.first), iterator(ret.second));
  1232. }
  1233. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1234. std::pair<const_iterator, const_iterator> equal_range(const key_type& k) const
  1235. {
  1236. std::pair<iiterator, iiterator> ret =
  1237. this->non_const_icont().equal_range(k, KeyNodeCompare(key_comp()));
  1238. return std::pair<const_iterator,const_iterator>
  1239. (const_iterator(ret.first), const_iterator(ret.second));
  1240. }
  1241. template <class K>
  1242. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1243. typename dtl::enable_if_transparent<key_compare, K, std::pair<iterator,iterator> >::type
  1244. equal_range(const K& k)
  1245. {
  1246. std::pair<iiterator, iiterator> ret =
  1247. this->icont().equal_range(k, KeyNodeCompare(key_comp()));
  1248. return std::pair<iterator,iterator>(iterator(ret.first), iterator(ret.second));
  1249. }
  1250. template <class K>
  1251. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1252. typename dtl::enable_if_transparent<key_compare, K, std::pair<const_iterator, const_iterator> >::type
  1253. equal_range(const K& k) const
  1254. {
  1255. std::pair<iiterator, iiterator> ret =
  1256. this->non_const_icont().equal_range(k, KeyNodeCompare(key_comp()));
  1257. return std::pair<const_iterator,const_iterator>
  1258. (const_iterator(ret.first), const_iterator(ret.second));
  1259. }
  1260. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1261. std::pair<iterator,iterator> lower_bound_range(const key_type& k)
  1262. {
  1263. std::pair<iiterator, iiterator> ret =
  1264. this->icont().lower_bound_range(k, KeyNodeCompare(key_comp()));
  1265. return std::pair<iterator,iterator>(iterator(ret.first), iterator(ret.second));
  1266. }
  1267. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1268. std::pair<const_iterator, const_iterator> lower_bound_range(const key_type& k) const
  1269. {
  1270. std::pair<iiterator, iiterator> ret =
  1271. this->non_const_icont().lower_bound_range(k, KeyNodeCompare(key_comp()));
  1272. return std::pair<const_iterator,const_iterator>
  1273. (const_iterator(ret.first), const_iterator(ret.second));
  1274. }
  1275. template <class K>
  1276. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1277. typename dtl::enable_if_transparent<key_compare, K, std::pair<iterator,iterator> >::type
  1278. lower_bound_range(const K& k)
  1279. {
  1280. std::pair<iiterator, iiterator> ret =
  1281. this->icont().lower_bound_range(k, KeyNodeCompare(key_comp()));
  1282. return std::pair<iterator,iterator>(iterator(ret.first), iterator(ret.second));
  1283. }
  1284. template <class K>
  1285. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1286. typename dtl::enable_if_transparent<key_compare, K, std::pair<const_iterator, const_iterator> >::type
  1287. lower_bound_range(const K& k) const
  1288. {
  1289. std::pair<iiterator, iiterator> ret =
  1290. this->non_const_icont().lower_bound_range(k, KeyNodeCompare(key_comp()));
  1291. return std::pair<const_iterator,const_iterator>
  1292. (const_iterator(ret.first), const_iterator(ret.second));
  1293. }
  1294. BOOST_CONTAINER_FORCEINLINE void rebalance()
  1295. { intrusive_tree_proxy_t::rebalance(this->icont()); }
  1296. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1297. friend bool operator==(const tree& x, const tree& y)
  1298. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  1299. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1300. friend bool operator<(const tree& x, const tree& y)
  1301. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  1302. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1303. friend bool operator!=(const tree& x, const tree& y)
  1304. { return !(x == y); }
  1305. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1306. friend bool operator>(const tree& x, const tree& y)
  1307. { return y < x; }
  1308. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1309. friend bool operator<=(const tree& x, const tree& y)
  1310. { return !(y < x); }
  1311. BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
  1312. friend bool operator>=(const tree& x, const tree& y)
  1313. { return !(x < y); }
  1314. BOOST_CONTAINER_FORCEINLINE friend void swap(tree& x, tree& y)
  1315. BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
  1316. && boost::container::dtl::is_nothrow_swappable<Compare>::value )
  1317. { x.swap(y); }
  1318. };
  1319. } //namespace dtl {
  1320. } //namespace container {
  1321. template <class T>
  1322. struct has_trivial_destructor_after_move;
  1323. //!has_trivial_destructor_after_move<> == true_type
  1324. //!specialization for optimizations
  1325. template <class T, class KeyOfValue, class Compare, class Allocator, class Options>
  1326. struct has_trivial_destructor_after_move
  1327. <
  1328. ::boost::container::dtl::tree
  1329. <T, KeyOfValue, Compare, Allocator, Options>
  1330. >
  1331. {
  1332. typedef typename ::boost::container::dtl::tree<T, KeyOfValue, Compare, Allocator, Options>::allocator_type allocator_type;
  1333. typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
  1334. static const bool value = ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
  1335. ::boost::has_trivial_destructor_after_move<pointer>::value &&
  1336. ::boost::has_trivial_destructor_after_move<Compare>::value;
  1337. };
  1338. } //namespace boost {
  1339. #include <boost/container/detail/config_end.hpp>
  1340. #endif //BOOST_CONTAINER_TREE_HPP