////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_TREE_HPP #define BOOST_CONTAINER_TREE_HPP #include "config_begin.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef BOOST_CONTAINER_PERFECT_FORWARDING #include #endif #include //std::pair #include #include namespace boost { namespace container { namespace container_detail { template struct tree_value_compare : public KeyCompare { typedef Value value_type; typedef KeyCompare key_compare; typedef KeyOfValue key_of_value; typedef Key key_type; tree_value_compare(const key_compare &kcomp) : key_compare(kcomp) {} const key_compare &key_comp() const { return static_cast(*this); } key_compare &key_comp() { return static_cast(*this); } template struct is_key { static const bool value = is_same::value; }; template typename enable_if_c::value, const key_type &>::type key_forward(const T &key) const { return key; } template typename enable_if_c::value, const key_type &>::type key_forward(const T &key) const { return KeyOfValue()(key); } template bool operator()(const KeyType &key1, const KeyType2 &key2) const { return key_compare::operator()(this->key_forward(key1), this->key_forward(key2)); } }; template struct rbtree_hook { typedef typename container_detail::bi::make_set_base_hook < container_detail::bi::void_pointer , container_detail::bi::link_mode , container_detail::bi::optimize_size >::type type; }; //This trait is used to type-pun std::pair because in C++03 //compilers std::pair is useless for C++11 features template struct rbtree_internal_data_type { typedef T type; }; template struct rbtree_internal_data_type< std::pair > { typedef pair type; }; //The node to be store in the tree template struct rbtree_node : public rbtree_hook::type { private: //BOOST_COPYABLE_AND_MOVABLE(rbtree_node) rbtree_node(); public: typedef typename rbtree_hook::type hook_type; typedef T value_type; typedef typename rbtree_internal_data_type::type internal_type; typedef rbtree_node node_type; T &get_data() { T* ptr = reinterpret_cast(&this->m_data); return *ptr; } const T &get_data() const { const T* ptr = reinterpret_cast(&this->m_data); return *ptr; } internal_type m_data; template void do_assign(const std::pair &p) { const_cast(m_data.first) = p.first; m_data.second = p.second; } template void do_assign(const pair &p) { const_cast(m_data.first) = p.first; m_data.second = p.second; } template void do_assign(const V &v) { m_data = v; } template void do_move_assign(std::pair &p) { const_cast(m_data.first) = ::boost::move(p.first); m_data.second = ::boost::move(p.second); } template void do_move_assign(pair &p) { const_cast(m_data.first) = ::boost::move(p.first); m_data.second = ::boost::move(p.second); } template void do_move_assign(V &v) { m_data = ::boost::move(v); } }; }//namespace container_detail { namespace container_detail { template struct intrusive_rbtree_type { typedef typename boost::container:: allocator_traits::value_type value_type; typedef typename boost::container:: allocator_traits::void_pointer void_pointer; typedef typename boost::container:: allocator_traits::size_type size_type; typedef typename container_detail::rbtree_node node_type; typedef node_compare node_compare_type; typedef typename container_detail::bi::make_rbtree ,container_detail::bi::base_hook::type> ,container_detail::bi::constant_time_size ,container_detail::bi::size_type >::type container_type; typedef container_type type ; }; } //namespace container_detail { namespace container_detail { template class rbtree : protected container_detail::node_alloc_holder < A , typename container_detail::intrusive_rbtree_type >::type , KeyCompare > { typedef typename container_detail::intrusive_rbtree_type < A, tree_value_compare >::type Icont; typedef container_detail::node_alloc_holder AllocHolder; typedef typename AllocHolder::NodePtr NodePtr; typedef rbtree < Key, Value, KeyOfValue , KeyCompare, A> ThisType; typedef typename AllocHolder::NodeAlloc NodeAlloc; typedef typename AllocHolder::ValAlloc ValAlloc; typedef typename AllocHolder::Node Node; typedef typename Icont::iterator iiterator; typedef typename Icont::const_iterator iconst_iterator; typedef container_detail::allocator_destroyer Destroyer; typedef typename AllocHolder::allocator_v1 allocator_v1; typedef typename AllocHolder::allocator_v2 allocator_v2; typedef typename AllocHolder::alloc_version alloc_version; class RecyclingCloner; friend class RecyclingCloner; class RecyclingCloner { public: RecyclingCloner(AllocHolder &holder, Icont &irbtree) : m_holder(holder), m_icont(irbtree) {} NodePtr operator()(const Node &other) const { if(NodePtr p = m_icont.unlink_leftmost_without_rebalance()){ //First recycle a node (this can't throw) BOOST_TRY{ //This can throw p->do_assign(other.m_data); return p; } BOOST_CATCH(...){ //If there is an exception destroy the whole source m_holder.destroy_node(p); while((p = m_icont.unlink_leftmost_without_rebalance())){ m_holder.destroy_node(p); } BOOST_RETHROW } BOOST_CATCH_END } else{ return m_holder.create_node(other.m_data); } } AllocHolder &m_holder; Icont &m_icont; }; class RecyclingMoveCloner; friend class RecyclingMoveCloner; class RecyclingMoveCloner { public: RecyclingMoveCloner(AllocHolder &holder, Icont &irbtree) : m_holder(holder), m_icont(irbtree) {} NodePtr operator()(const Node &other) const { if(NodePtr p = m_icont.unlink_leftmost_without_rebalance()){ //First recycle a node (this can't throw) BOOST_TRY{ //This can throw p->do_move_assign(const_cast(other).m_data); return p; } BOOST_CATCH(...){ //If there is an exception destroy the whole source m_holder.destroy_node(p); while((p = m_icont.unlink_leftmost_without_rebalance())){ m_holder.destroy_node(p); } BOOST_RETHROW } BOOST_CATCH_END } else{ return m_holder.create_node(other.m_data); } } AllocHolder &m_holder; Icont &m_icont; }; BOOST_COPYABLE_AND_MOVABLE(rbtree) public: typedef Key key_type; typedef Value value_type; typedef A allocator_type; typedef KeyCompare key_compare; typedef tree_value_compare< Key, Value , KeyCompare, KeyOfValue> value_compare; typedef typename boost::container:: allocator_traits::pointer pointer; typedef typename boost::container:: allocator_traits::const_pointer const_pointer; typedef typename boost::container:: allocator_traits::reference reference; typedef typename boost::container:: allocator_traits::const_reference const_reference; typedef typename boost::container:: allocator_traits::size_type size_type; typedef typename boost::container:: allocator_traits::difference_type difference_type; typedef difference_type rbtree_difference_type; typedef pointer rbtree_pointer; typedef const_pointer rbtree_const_pointer; typedef reference rbtree_reference; typedef const_reference rbtree_const_reference; typedef NodeAlloc stored_allocator_type; private: template struct key_node_compare : private KeyValueCompare { key_node_compare(const KeyValueCompare &comp) : KeyValueCompare(comp) {} template struct is_node { static const bool value = is_same::value; }; template typename enable_if_c::value, const value_type &>::type key_forward(const T &node) const { return node.get_data(); } template typename enable_if_c::value, const T &>::type key_forward(const T &key) const { return key; } template bool operator()(const KeyType &key1, const KeyType2 &key2) const { return KeyValueCompare::operator()(this->key_forward(key1), this->key_forward(key2)); } }; typedef key_node_compare KeyNodeCompare; public: //rbtree const_iterator class const_iterator : public std::iterator < std::bidirectional_iterator_tag , value_type , rbtree_difference_type , rbtree_const_pointer , rbtree_const_reference> { protected: typedef typename Icont::iterator iiterator; iiterator m_it; explicit const_iterator(iiterator it) : m_it(it){} void prot_incr() { ++m_it; } void prot_decr() { --m_it; } private: iiterator get() { return this->m_it; } public: friend class rbtree ; typedef rbtree_difference_type difference_type; //Constructors const_iterator() : m_it() {} //Pointer like operators const_reference operator*() const { return m_it->get_data(); } const_pointer operator->() const { return const_pointer(&m_it->get_data()); } //Increment / Decrement const_iterator& operator++() { prot_incr(); return *this; } const_iterator operator++(int) { iiterator tmp = m_it; ++*this; return const_iterator(tmp); } const_iterator& operator--() { prot_decr(); return *this; } const_iterator operator--(int) { iiterator tmp = m_it; --*this; return const_iterator(tmp); } //Comparison operators bool operator== (const const_iterator& r) const { return m_it == r.m_it; } bool operator!= (const const_iterator& r) const { return m_it != r.m_it; } }; //rbtree iterator class iterator : public const_iterator { private: explicit iterator(iiterator it) : const_iterator(it) {} iiterator get() { return this->m_it; } public: friend class rbtree ; typedef rbtree_pointer pointer; typedef rbtree_reference reference; //Constructors iterator(){} //Pointer like operators reference operator*() const { return this->m_it->get_data(); } pointer operator->() const { return boost::intrusive::pointer_traits::pointer_to(this->m_it->get_data()); } //Increment / Decrement iterator& operator++() { this->prot_incr(); return *this; } iterator operator++(int) { iiterator tmp = this->m_it; ++*this; return iterator(tmp); } iterator& operator--() { this->prot_decr(); return *this; } iterator operator--(int) { iterator tmp = *this; --*this; return tmp; } }; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; rbtree() : AllocHolder(key_compare()) {} rbtree(const key_compare& comp, const allocator_type& a = allocator_type()) : AllocHolder(a, comp) {} template rbtree(bool unique_insertion, InputIterator first, InputIterator last, const key_compare& comp, const allocator_type& a #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < container_detail::is_input_iterator::value || container_detail::is_same::value >::type * = 0 #endif ) : AllocHolder(a, comp) { if(unique_insertion){ this->insert_unique(first, last); } else{ this->insert_equal(first, last); } } template rbtree(bool unique_insertion, InputIterator first, InputIterator last, const key_compare& comp, const allocator_type& a #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < !(container_detail::is_input_iterator::value || container_detail::is_same::value) >::type * = 0 #endif ) : AllocHolder(a, comp) { if(unique_insertion){ this->insert_unique(first, last); } else{ //Optimized allocation and construction this->allocate_many_and_construct (first, std::distance(first, last), insert_equal_end_hint_functor(this->icont())); } } template rbtree( ordered_range_t, InputIterator first, InputIterator last , const key_compare& comp = key_compare(), const allocator_type& a = allocator_type() #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < container_detail::is_input_iterator::value || container_detail::is_same::value >::type * = 0 #endif ) : AllocHolder(a, comp) { this->insert_equal(first, last); } template rbtree( ordered_range_t, InputIterator first, InputIterator last , const key_compare& comp = key_compare(), const allocator_type& a = allocator_type() #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < !(container_detail::is_input_iterator::value || container_detail::is_same::value) >::type * = 0 #endif ) : AllocHolder(a, comp) { //Optimized allocation and construction this->allocate_many_and_construct (first, std::distance(first, last), push_back_functor(this->icont())); } rbtree(const rbtree& x) : AllocHolder(x, x.key_comp()) { this->icont().clone_from (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc())); } rbtree(BOOST_RV_REF(rbtree) x) : AllocHolder(::boost::move(static_cast(x)), x.key_comp()) {} rbtree(const rbtree& x, const allocator_type &a) : AllocHolder(a, x.key_comp()) { this->icont().clone_from (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc())); } rbtree(BOOST_RV_REF(rbtree) x, const allocator_type &a) : AllocHolder(a, x.key_comp()) { if(this->node_alloc() == x.node_alloc()){ this->icont().swap(x.icont()); } else{ this->icont().clone_from (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc())); } } ~rbtree() {} //AllocHolder clears the tree rbtree& operator=(BOOST_COPY_ASSIGN_REF(rbtree) x) { if (&x != this){ NodeAlloc &this_alloc = this->get_stored_allocator(); const NodeAlloc &x_alloc = x.get_stored_allocator(); container_detail::bool_:: propagate_on_container_copy_assignment::value> flag; if(flag && this_alloc != x_alloc){ this->clear(); } this->AllocHolder::copy_assign_alloc(x); //Transfer all the nodes to a temporary tree //If anything goes wrong, all the nodes will be destroyed //automatically Icont other_tree(::boost::move(this->icont())); //Now recreate the source tree reusing nodes stored by other_tree this->icont().clone_from (x.icont() , RecyclingCloner(*this, other_tree) , Destroyer(this->node_alloc())); //If there are remaining nodes, destroy them NodePtr p; while((p = other_tree.unlink_leftmost_without_rebalance())){ AllocHolder::destroy_node(p); } } return *this; } rbtree& operator=(BOOST_RV_REF(rbtree) x) { if (&x != this){ NodeAlloc &this_alloc = this->node_alloc(); NodeAlloc &x_alloc = x.node_alloc(); //If allocators are equal we can just swap pointers if(this_alloc == x_alloc){ //Destroy and swap pointers this->clear(); this->icont() = ::boost::move(x.icont()); //Move allocator if needed this->AllocHolder::move_assign_alloc(x); } //If unequal allocators, then do a one by one move else{ //Transfer all the nodes to a temporary tree //If anything goes wrong, all the nodes will be destroyed //automatically Icont other_tree(::boost::move(this->icont())); //Now recreate the source tree reusing nodes stored by other_tree this->icont().clone_from (x.icont() , RecyclingMoveCloner(*this, other_tree) , Destroyer(this->node_alloc())); //If there are remaining nodes, destroy them NodePtr p; while((p = other_tree.unlink_leftmost_without_rebalance())){ AllocHolder::destroy_node(p); } } } return *this; } public: // accessors: value_compare value_comp() const { return this->icont().value_comp().value_comp(); } key_compare key_comp() const { return this->icont().value_comp().value_comp().key_comp(); } allocator_type get_allocator() const { return allocator_type(this->node_alloc()); } const stored_allocator_type &get_stored_allocator() const { return this->node_alloc(); } stored_allocator_type &get_stored_allocator() { return this->node_alloc(); } iterator begin() { return iterator(this->icont().begin()); } const_iterator begin() const { return this->cbegin(); } iterator end() { return iterator(this->icont().end()); } const_iterator end() const { return this->cend(); } reverse_iterator rbegin() { return reverse_iterator(end()); } const_reverse_iterator rbegin() const { return this->crbegin(); } reverse_iterator rend() { return reverse_iterator(begin()); } const_reverse_iterator rend() const { return this->crend(); } //! Effects: Returns a const_iterator to the first element contained in the container. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator cbegin() const { return const_iterator(this->non_const_icont().begin()); } //! Effects: Returns a const_iterator to the end of the container. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator cend() const { return const_iterator(this->non_const_icont().end()); } //! Effects: Returns a const_reverse_iterator pointing to the beginning //! of the reversed container. //! //! Throws: Nothing. //! //! Complexity: Constant. const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } //! Effects: Returns a const_reverse_iterator pointing to the end //! of the reversed container. //! //! Throws: Nothing. //! //! Complexity: Constant. const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } bool empty() const { return !this->size(); } size_type size() const { return this->icont().size(); } size_type max_size() const { return AllocHolder::max_size(); } void swap(ThisType& x) { AllocHolder::swap(x); } public: typedef typename Icont::insert_commit_data insert_commit_data; // insert/erase std::pair insert_unique_check (const key_type& key, insert_commit_data &data) { std::pair ret = this->icont().insert_unique_check(key, KeyNodeCompare(value_comp()), data); return std::pair(iterator(ret.first), ret.second); } std::pair insert_unique_check (const_iterator hint, const key_type& key, insert_commit_data &data) { std::pair ret = this->icont().insert_unique_check(hint.get(), key, KeyNodeCompare(value_comp()), data); return std::pair(iterator(ret.first), ret.second); } iterator insert_unique_commit(const value_type& v, insert_commit_data &data) { NodePtr tmp = AllocHolder::create_node(v); iiterator it(this->icont().insert_unique_commit(*tmp, data)); return iterator(it); } template iterator insert_unique_commit (BOOST_FWD_REF(MovableConvertible) mv, insert_commit_data &data) { NodePtr tmp = AllocHolder::create_node(boost::forward(mv)); iiterator it(this->icont().insert_unique_commit(*tmp, data)); return iterator(it); } std::pair insert_unique(const value_type& v) { insert_commit_data data; std::pair ret = this->insert_unique_check(KeyOfValue()(v), data); if(!ret.second) return ret; return std::pair (this->insert_unique_commit(v, data), true); } template std::pair insert_unique(BOOST_FWD_REF(MovableConvertible) mv) { insert_commit_data data; std::pair ret = this->insert_unique_check(KeyOfValue()(mv), data); if(!ret.second) return ret; return std::pair (this->insert_unique_commit(boost::forward(mv), data), true); } private: std::pair emplace_unique_impl(NodePtr p) { value_type &v = p->get_data(); insert_commit_data data; scoped_destroy_deallocator destroy_deallocator(p, this->node_alloc()); std::pair ret = this->insert_unique_check(KeyOfValue()(v), data); if(!ret.second){ return ret; } //No throw insertion part, release rollback destroy_deallocator.release(); return std::pair ( iterator(iiterator(this->icont().insert_unique_commit(*p, data))) , true ); } iterator emplace_unique_hint_impl(const_iterator hint, NodePtr p) { value_type &v = p->get_data(); insert_commit_data data; std::pair ret = this->insert_unique_check(hint, KeyOfValue()(v), data); if(!ret.second){ Destroyer(this->node_alloc())(p); return ret.first; } return iterator(iiterator(this->icont().insert_unique_commit(*p, data))); } public: #ifdef BOOST_CONTAINER_PERFECT_FORWARDING template std::pair emplace_unique(Args&&... args) { return this->emplace_unique_impl(AllocHolder::create_node(boost::forward(args)...)); } template iterator emplace_hint_unique(const_iterator hint, Args&&... args) { return this->emplace_unique_hint_impl(hint, AllocHolder::create_node(boost::forward(args)...)); } template iterator emplace_equal(Args&&... args) { NodePtr p(AllocHolder::create_node(boost::forward(args)...)); return iterator(this->icont().insert_equal(this->icont().end(), *p)); } template iterator emplace_hint_equal(const_iterator hint, Args&&... args) { NodePtr p(AllocHolder::create_node(boost::forward(args)...)); return iterator(this->icont().insert_equal(hint.get(), *p)); } #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING #define BOOST_PP_LOCAL_MACRO(n) \ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ std::pair emplace_unique(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ { \ return this->emplace_unique_impl \ (AllocHolder::create_node(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \ } \ \ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ iterator emplace_hint_unique(const_iterator hint \ BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ { \ return this->emplace_unique_hint_impl \ (hint, AllocHolder::create_node(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \ } \ \ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ iterator emplace_equal(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ { \ NodePtr p(AllocHolder::create_node(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \ return iterator(this->icont().insert_equal(this->icont().end(), *p)); \ } \ \ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \ iterator emplace_hint_equal(const_iterator hint \ BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \ { \ NodePtr p(AllocHolder::create_node(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \ return iterator(this->icont().insert_equal(hint.get(), *p)); \ } \ //! #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS) #include BOOST_PP_LOCAL_ITERATE() #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING iterator insert_unique(const_iterator hint, const value_type& v) { insert_commit_data data; std::pair ret = this->insert_unique_check(hint, KeyOfValue()(v), data); if(!ret.second) return ret.first; return this->insert_unique_commit(v, data); } template iterator insert_unique(const_iterator hint, BOOST_FWD_REF(MovableConvertible) mv) { insert_commit_data data; std::pair ret = this->insert_unique_check(hint, KeyOfValue()(mv), data); if(!ret.second) return ret.first; return this->insert_unique_commit(boost::forward(mv), data); } template void insert_unique(InputIterator first, InputIterator last) { if(this->empty()){ //Insert with end hint, to achieve linear //complexity if [first, last) is ordered const_iterator hint(this->cend()); for( ; first != last; ++first) hint = this->insert_unique(hint, *first); } else{ for( ; first != last; ++first) this->insert_unique(*first); } } iterator insert_equal(const value_type& v) { NodePtr p(AllocHolder::create_node(v)); return iterator(this->icont().insert_equal(this->icont().end(), *p)); } template iterator insert_equal(BOOST_FWD_REF(MovableConvertible) mv) { NodePtr p(AllocHolder::create_node(boost::forward(mv))); return iterator(this->icont().insert_equal(this->icont().end(), *p)); } iterator insert_equal(const_iterator hint, const value_type& v) { NodePtr p(AllocHolder::create_node(v)); return iterator(this->icont().insert_equal(hint.get(), *p)); } template iterator insert_equal(const_iterator hint, BOOST_FWD_REF(MovableConvertible) mv) { NodePtr p(AllocHolder::create_node(boost::forward(mv))); return iterator(this->icont().insert_equal(hint.get(), *p)); } template void insert_equal(InputIterator first, InputIterator last) { //Insert with end hint, to achieve linear //complexity if [first, last) is ordered const_iterator hint(this->cend()); for( ; first != last; ++first) hint = this->insert_equal(hint, *first); } iterator erase(const_iterator position) { return iterator(this->icont().erase_and_dispose(position.get(), Destroyer(this->node_alloc()))); } size_type erase(const key_type& k) { return AllocHolder::erase_key(k, KeyNodeCompare(value_comp()), alloc_version()); } iterator erase(const_iterator first, const_iterator last) { return iterator(AllocHolder::erase_range(first.get(), last.get(), alloc_version())); } void clear() { AllocHolder::clear(alloc_version()); } // set operations: iterator find(const key_type& k) { return iterator(this->icont().find(k, KeyNodeCompare(value_comp()))); } const_iterator find(const key_type& k) const { return const_iterator(this->non_const_icont().find(k, KeyNodeCompare(value_comp()))); } size_type count(const key_type& k) const { return size_type(this->icont().count(k, KeyNodeCompare(value_comp()))); } iterator lower_bound(const key_type& k) { return iterator(this->icont().lower_bound(k, KeyNodeCompare(value_comp()))); } const_iterator lower_bound(const key_type& k) const { return const_iterator(this->non_const_icont().lower_bound(k, KeyNodeCompare(value_comp()))); } iterator upper_bound(const key_type& k) { return iterator(this->icont().upper_bound(k, KeyNodeCompare(value_comp()))); } const_iterator upper_bound(const key_type& k) const { return const_iterator(this->non_const_icont().upper_bound(k, KeyNodeCompare(value_comp()))); } std::pair equal_range(const key_type& k) { std::pair ret = this->icont().equal_range(k, KeyNodeCompare(value_comp())); return std::pair(iterator(ret.first), iterator(ret.second)); } std::pair equal_range(const key_type& k) const { std::pair ret = this->non_const_icont().equal_range(k, KeyNodeCompare(value_comp())); return std::pair (const_iterator(ret.first), const_iterator(ret.second)); } private: class insert_equal_end_hint_functor; friend class insert_equal_end_hint_functor; class insert_equal_end_hint_functor { Icont &icont_; const iconst_iterator cend_; public: insert_equal_end_hint_functor(Icont &icont) : icont_(icont), cend_(this->icont_.cend()) {} void operator()(Node &n) { this->icont_.insert_equal(cend_, n); } }; class push_back_functor; friend class push_back_functor; class push_back_functor { Icont &icont_; public: push_back_functor(Icont &icont) : icont_(icont) {} void operator()(Node &n) { this->icont_.push_back(n); } }; }; template inline bool operator==(const rbtree& x, const rbtree& y) { return x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin()); } template inline bool operator<(const rbtree& x, const rbtree& y) { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } template inline bool operator!=(const rbtree& x, const rbtree& y) { return !(x == y); } template inline bool operator>(const rbtree& x, const rbtree& y) { return y < x; } template inline bool operator<=(const rbtree& x, const rbtree& y) { return !(y < x); } template inline bool operator>=(const rbtree& x, const rbtree& y) { return !(x < y); } template inline void swap(rbtree& x, rbtree& y) { x.swap(y); } } //namespace container_detail { } //namespace container { /* //!has_trivial_destructor_after_move<> == true_type //!specialization for optimizations template struct has_trivial_destructor_after_move > { static const bool value = has_trivial_destructor_after_move::value && has_trivial_destructor_after_move::value; }; */ } //namespace boost { #include #endif //BOOST_CONTAINER_TREE_HPP