summaryrefslogtreecommitdiff
path: root/boost/intrusive/detail
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-10-30 19:57:26 (GMT)
committerAnas Nashif <anas.nashif@intel.com>2012-10-30 19:57:26 (GMT)
commit1a78a62555be32868418fe52f8e330c9d0f95d5a (patch)
treed3765a80e7d3b9640ec2e930743630cd6b9fce2b /boost/intrusive/detail
downloadboost-1a78a62555be32868418fe52f8e330c9d0f95d5a.zip
boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.tar.gz
boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.tar.bz2
Imported Upstream version 1.49.0upstream/1.49.0
Diffstat (limited to 'boost/intrusive/detail')
-rw-r--r--boost/intrusive/detail/any_node_and_algorithms.hpp297
-rw-r--r--boost/intrusive/detail/assert.hpp41
-rw-r--r--boost/intrusive/detail/avltree_node.hpp185
-rw-r--r--boost/intrusive/detail/clear_on_destructor_base.hpp36
-rw-r--r--boost/intrusive/detail/common_slist_algorithms.hpp103
-rw-r--r--boost/intrusive/detail/config_begin.hpp52
-rw-r--r--boost/intrusive/detail/config_end.hpp15
-rw-r--r--boost/intrusive/detail/ebo_functor_holder.hpp95
-rw-r--r--boost/intrusive/detail/function_detector.hpp88
-rw-r--r--boost/intrusive/detail/generic_hook.hpp209
-rw-r--r--boost/intrusive/detail/has_member_function_callable_with.hpp356
-rw-r--r--boost/intrusive/detail/hashtable_node.hpp249
-rw-r--r--boost/intrusive/detail/is_stateful_value_traits.hpp77
-rw-r--r--boost/intrusive/detail/list_node.hpp190
-rw-r--r--boost/intrusive/detail/memory_util.hpp279
-rw-r--r--boost/intrusive/detail/mpl.hpp355
-rw-r--r--boost/intrusive/detail/parent_from_member.hpp69
-rw-r--r--boost/intrusive/detail/preprocessor.hpp52
-rw-r--r--boost/intrusive/detail/rbtree_node.hpp177
-rw-r--r--boost/intrusive/detail/slist_node.hpp163
-rw-r--r--boost/intrusive/detail/transform_iterator.hpp173
-rw-r--r--boost/intrusive/detail/tree_algorithms.hpp1697
-rw-r--r--boost/intrusive/detail/tree_node.hpp190
-rw-r--r--boost/intrusive/detail/utilities.hpp879
-rw-r--r--boost/intrusive/detail/workaround.hpp22
25 files changed, 6049 insertions, 0 deletions
diff --git a/boost/intrusive/detail/any_node_and_algorithms.hpp b/boost/intrusive/detail/any_node_and_algorithms.hpp
new file mode 100644
index 0000000..bda9ad3
--- /dev/null
+++ b/boost/intrusive/detail/any_node_and_algorithms.hpp
@@ -0,0 +1,297 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_ANY_NODE_HPP
+#define BOOST_INTRUSIVE_ANY_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <cstddef>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/pointer_cast.hpp>
+
+namespace boost {
+namespace intrusive {
+
+template<class VoidPointer>
+struct any_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<any_node>::type node_ptr;
+ node_ptr node_ptr_1;
+ node_ptr node_ptr_2;
+ node_ptr node_ptr_3;
+ std::size_t size_t_1;
+};
+
+template<class VoidPointer>
+struct any_list_node_traits
+{
+ typedef any_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ static const node_ptr &get_next(const const_node_ptr & n)
+ { return n->node_ptr_1; }
+
+ static void set_next(const node_ptr & n, const node_ptr & next)
+ { n->node_ptr_1 = next; }
+
+ static const node_ptr &get_previous(const const_node_ptr & n)
+ { return n->node_ptr_2; }
+
+ static void set_previous(const node_ptr & n, const node_ptr & prev)
+ { n->node_ptr_2 = prev; }
+};
+
+
+template<class VoidPointer>
+struct any_slist_node_traits
+{
+ typedef any_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ static const node_ptr &get_next(const const_node_ptr & n)
+ { return n->node_ptr_1; }
+
+ static void set_next(const node_ptr & n, const node_ptr & next)
+ { n->node_ptr_1 = next; }
+};
+
+
+template<class VoidPointer>
+struct any_unordered_node_traits
+ : public any_slist_node_traits<VoidPointer>
+{
+ typedef any_slist_node_traits<VoidPointer> reduced_slist_node_traits;
+ typedef typename reduced_slist_node_traits::node node;
+ typedef typename reduced_slist_node_traits::node_ptr node_ptr;
+ typedef typename reduced_slist_node_traits::const_node_ptr const_node_ptr;
+
+ static const bool store_hash = true;
+ static const bool optimize_multikey = true;
+
+ static const node_ptr &get_next(const const_node_ptr & n)
+ { return n->node_ptr_1; }
+
+ static void set_next(const node_ptr & n, const node_ptr & next)
+ { n->node_ptr_1 = next; }
+
+ static node_ptr get_prev_in_group(const const_node_ptr & n)
+ { return n->node_ptr_2; }
+
+ static void set_prev_in_group(const node_ptr & n, const node_ptr & prev)
+ { n->node_ptr_2 = prev; }
+
+ static std::size_t get_hash(const const_node_ptr & n)
+ { return n->size_t_1; }
+
+ static void set_hash(const node_ptr & n, std::size_t h)
+ { n->size_t_1 = h; }
+};
+
+
+template<class VoidPointer>
+struct any_rbtree_node_traits
+{
+ typedef any_node<VoidPointer> node;
+
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ typedef std::size_t color;
+
+ static const node_ptr &get_parent(const const_node_ptr & n)
+ { return n->node_ptr_1; }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { n->node_ptr_1 = p; }
+
+ static const node_ptr &get_left(const const_node_ptr & n)
+ { return n->node_ptr_2; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->node_ptr_2 = l; }
+
+ static const node_ptr &get_right(const const_node_ptr & n)
+ { return n->node_ptr_3; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->node_ptr_3 = r; }
+
+ static color get_color(const const_node_ptr & n)
+ { return n->size_t_1; }
+
+ static void set_color(const node_ptr & n, color c)
+ { n->size_t_1 = c; }
+
+ static color black()
+ { return 0u; }
+
+ static color red()
+ { return 1u; }
+};
+
+
+template<class VoidPointer>
+struct any_avltree_node_traits
+{
+ typedef any_node<VoidPointer> node;
+
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+ typedef std::size_t balance;
+
+ static const node_ptr &get_parent(const const_node_ptr & n)
+ { return n->node_ptr_1; }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { n->node_ptr_1 = p; }
+
+ static const node_ptr &get_left(const const_node_ptr & n)
+ { return n->node_ptr_2; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->node_ptr_2 = l; }
+
+ static const node_ptr &get_right(const const_node_ptr & n)
+ { return n->node_ptr_3; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->node_ptr_3 = r; }
+
+ static balance get_balance(const const_node_ptr & n)
+ { return n->size_t_1; }
+
+ static void set_balance(const node_ptr & n, balance b)
+ { n->size_t_1 = b; }
+
+ static balance negative()
+ { return 0u; }
+
+ static balance zero()
+ { return 1u; }
+
+ static balance positive()
+ { return 2u; }
+};
+
+
+template<class VoidPointer>
+struct any_tree_node_traits
+{
+ typedef any_node<VoidPointer> node;
+
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ static const node_ptr &get_parent(const const_node_ptr & n)
+ { return n->node_ptr_1; }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { n->node_ptr_1 = p; }
+
+ static const node_ptr &get_left(const const_node_ptr & n)
+ { return n->node_ptr_2; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->node_ptr_2 = l; }
+
+ static const node_ptr &get_right(const const_node_ptr & n)
+ { return n->node_ptr_3; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->node_ptr_3 = r; }
+};
+
+template<class VoidPointer>
+class any_node_traits
+{
+ public:
+ typedef any_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+};
+
+template<class VoidPointer>
+class any_algorithms
+{
+ template <class T>
+ static void function_not_available_for_any_hooks(typename detail::enable_if<detail::is_same<T, bool> >::type)
+ {}
+
+ public:
+ typedef any_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+ typedef any_node_traits<VoidPointer> node_traits;
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(const node_ptr & node)
+ { node->node_ptr_1 = 0; };
+
+ //! <b>Effects</b>: Returns true if node is in the same state as if called init(node)
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool inited(const const_node_ptr & node)
+ { return !node->node_ptr_1; };
+
+ static bool unique(const const_node_ptr & node)
+ { return 0 == node->node_ptr_1; }
+
+ static void unlink(const node_ptr &)
+ {
+ //Auto-unlink hooks and unlink() are not available for any hooks
+ any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
+ }
+
+ static void swap_nodes(const node_ptr & l, const node_ptr & r)
+ {
+ //Any nodes have no swap_nodes capability because they don't know
+ //what algorithm they must use to unlink the node from the container
+ any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
+ }
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_ANY_NODE_HPP
diff --git a/boost/intrusive/detail/assert.hpp b/boost/intrusive/detail/assert.hpp
new file mode 100644
index 0000000..cfe392b
--- /dev/null
+++ b/boost/intrusive/detail/assert.hpp
@@ -0,0 +1,41 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_ASSERT_HPP
+#define BOOST_INTRUSIVE_DETAIL_ASSERT_HPP
+
+#if defined(_MSC_VER)&&(_MSC_VER>=1200)
+#pragma once
+#endif
+
+#if !defined(BOOST_INTRUSIVE_INVARIANT_ASSERT)
+ #include <boost/assert.hpp>
+ #define BOOST_INTRUSIVE_INVARIANT_ASSERT BOOST_ASSERT
+#elif defined(BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE)
+ #include BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE
+#endif
+
+#if !defined(BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT)
+ #include <boost/assert.hpp>
+ #define BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT BOOST_ASSERT
+#elif defined(BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE)
+ #include BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE
+#endif
+
+#if !defined(BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT)
+ #include <boost/assert.hpp>
+ #define BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT BOOST_ASSERT
+#elif defined(BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE)
+ #include BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE
+#endif
+
+#endif //BOOST_INTRUSIVE_DETAIL_ASSERT_HPP
diff --git a/boost/intrusive/detail/avltree_node.hpp b/boost/intrusive/detail/avltree_node.hpp
new file mode 100644
index 0000000..dc600e6
--- /dev/null
+++ b/boost/intrusive/detail/avltree_node.hpp
@@ -0,0 +1,185 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_AVLTREE_NODE_HPP
+#define BOOST_INTRUSIVE_AVLTREE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/intrusive/avltree_algorithms.hpp>
+#include <boost/intrusive/pointer_plus_bits.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/////////////////////////////////////////////////////////////////////////////
+// //
+// Generic node_traits for any pointer type //
+// //
+/////////////////////////////////////////////////////////////////////////////
+
+//This is the compact representation: 3 pointers
+template<class VoidPointer>
+struct compact_avltree_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <compact_avltree_node<VoidPointer> >::type node_ptr;
+ enum balance { negative_t, zero_t, positive_t };
+ node_ptr parent_, left_, right_;
+};
+
+//This is the normal representation: 3 pointers + enum
+template<class VoidPointer>
+struct avltree_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <avltree_node<VoidPointer> >::type node_ptr;
+ enum balance { negative_t, zero_t, positive_t };
+ node_ptr parent_, left_, right_;
+ balance balance_;
+};
+
+//This is the default node traits implementation
+//using a node with 3 generic pointers plus an enum
+template<class VoidPointer>
+struct default_avltree_node_traits_impl
+{
+ typedef avltree_node<VoidPointer> node;
+
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <const node>::type const_node_ptr;
+
+ typedef typename node::balance balance;
+
+ static const node_ptr & get_parent(const const_node_ptr & n)
+ { return n->parent_; }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { n->parent_ = p; }
+
+ static const node_ptr & get_left(const const_node_ptr & n)
+ { return n->left_; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->left_ = l; }
+
+ static const node_ptr & get_right(const const_node_ptr & n)
+ { return n->right_; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->right_ = r; }
+
+ static balance get_balance(const const_node_ptr & n)
+ { return n->balance_; }
+
+ static void set_balance(const node_ptr & n, balance b)
+ { n->balance_ = b; }
+
+ static balance negative()
+ { return node::negative_t; }
+
+ static balance zero()
+ { return node::zero_t; }
+
+ static balance positive()
+ { return node::positive_t; }
+};
+
+//This is the compact node traits implementation
+//using a node with 3 generic pointers
+template<class VoidPointer>
+struct compact_avltree_node_traits_impl
+{
+ typedef compact_avltree_node<VoidPointer> node;
+
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <const node>::type const_node_ptr;
+ typedef typename node::balance balance;
+
+ typedef pointer_plus_bits<node_ptr, 2> ptr_bit;
+
+ static node_ptr get_parent(const const_node_ptr & n)
+ { return ptr_bit::get_pointer(n->parent_); }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { ptr_bit::set_pointer(n->parent_, p); }
+
+ static const node_ptr & get_left(const const_node_ptr & n)
+ { return n->left_; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->left_ = l; }
+
+ static const node_ptr & get_right(const const_node_ptr & n)
+ { return n->right_; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->right_ = r; }
+
+ static balance get_balance(const const_node_ptr & n)
+ { return (balance)ptr_bit::get_bits(n->parent_); }
+
+ static void set_balance(const node_ptr & n, balance b)
+ { ptr_bit::set_bits(n->parent_, (std::size_t)b); }
+
+ static balance negative()
+ { return node::negative_t; }
+
+ static balance zero()
+ { return node::zero_t; }
+
+ static balance positive()
+ { return node::positive_t; }
+};
+
+//Dispatches the implementation based on the boolean
+template<class VoidPointer, bool Compact>
+struct avltree_node_traits_dispatch
+ : public default_avltree_node_traits_impl<VoidPointer>
+{};
+
+template<class VoidPointer>
+struct avltree_node_traits_dispatch<VoidPointer, true>
+ : public compact_avltree_node_traits_impl<VoidPointer>
+{};
+
+//Inherit from the detail::link_dispatch depending on the embedding capabilities
+template<class VoidPointer, bool OptimizeSize = false>
+struct avltree_node_traits
+ : public avltree_node_traits_dispatch
+ < VoidPointer
+ , OptimizeSize &&
+ max_pointer_plus_bits
+ < VoidPointer
+ , detail::alignment_of<compact_avltree_node<VoidPointer> >::value
+ >::value >= 2u
+ >
+{};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_AVLTREE_NODE_HPP
diff --git a/boost/intrusive/detail/clear_on_destructor_base.hpp b/boost/intrusive/detail/clear_on_destructor_base.hpp
new file mode 100644
index 0000000..6765dfa
--- /dev/null
+++ b/boost/intrusive/detail/clear_on_destructor_base.hpp
@@ -0,0 +1,36 @@
+//////} // ///////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2008-2009. 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP
+#define BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<class Derived>
+class clear_on_destructor_base
+{
+ protected:
+ ~clear_on_destructor_base()
+ {
+ static_cast<Derived*>(this)->clear();
+ }
+};
+
+} // namespace detail {
+} // namespace intrusive {
+} // namespace boost {
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP
diff --git a/boost/intrusive/detail/common_slist_algorithms.hpp b/boost/intrusive/detail/common_slist_algorithms.hpp
new file mode 100644
index 0000000..15d6b3f
--- /dev/null
+++ b/boost/intrusive/detail/common_slist_algorithms.hpp
@@ -0,0 +1,103 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <cstddef>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<class NodeTraits>
+class common_slist_algorithms
+{
+ public:
+ typedef typename NodeTraits::node node;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+ typedef NodeTraits node_traits;
+
+ static node_ptr get_previous_node(const node_ptr & prev_init_node, const node_ptr & this_node)
+ {
+ node_ptr p = prev_init_node;
+ for( node_ptr p_next
+ ; this_node != (p_next = NodeTraits::get_next(p))
+ ; p = p_next){
+ //Logic error: possible use of linear lists with
+ //operations only permitted with lists
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(p);
+ }
+ return p;
+ }
+
+ static void init_header(const node_ptr & this_node)
+ { NodeTraits::set_next(this_node, this_node); }
+
+ static void init(const node_ptr & this_node)
+ { NodeTraits::set_next(this_node, node_ptr()); }
+
+ static bool unique(const const_node_ptr & this_node)
+ {
+ node_ptr next = NodeTraits::get_next(this_node);
+ return !next || next == this_node;
+ }
+
+ static bool inited(const const_node_ptr & this_node)
+ { return !NodeTraits::get_next(this_node); }
+
+ static void unlink_after(const node_ptr & prev_node)
+ {
+ const_node_ptr this_node(NodeTraits::get_next(prev_node));
+ NodeTraits::set_next(prev_node, NodeTraits::get_next(this_node));
+ }
+
+ static void unlink_after(const node_ptr & prev_node, const node_ptr & last_node)
+ { NodeTraits::set_next(prev_node, last_node); }
+
+ static void link_after(const node_ptr & prev_node, const node_ptr & this_node)
+ {
+ NodeTraits::set_next(this_node, NodeTraits::get_next(prev_node));
+ NodeTraits::set_next(prev_node, this_node);
+ }
+
+ static void incorporate_after(const node_ptr & bp, const node_ptr & b, const node_ptr & be)
+ {
+ node_ptr p(NodeTraits::get_next(bp));
+ NodeTraits::set_next(bp, b);
+ NodeTraits::set_next(be, p);
+ }
+
+ static void transfer_after(const node_ptr & bp, const node_ptr & bb, const node_ptr & be)
+ {
+ if (bp != bb && bp != be && bb != be) {
+ node_ptr next_b = NodeTraits::get_next(bb);
+ node_ptr next_e = NodeTraits::get_next(be);
+ node_ptr next_p = NodeTraits::get_next(bp);
+ NodeTraits::set_next(bb, next_e);
+ NodeTraits::set_next(be, next_p);
+ NodeTraits::set_next(bp, next_b);
+ }
+ }
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP
diff --git a/boost/intrusive/detail/config_begin.hpp b/boost/intrusive/detail/config_begin.hpp
new file mode 100644
index 0000000..bb126fc
--- /dev/null
+++ b/boost/intrusive/detail/config_begin.hpp
@@ -0,0 +1,52 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_CONFIG_INCLUDED
+#define BOOST_INTRUSIVE_CONFIG_INCLUDED
+#include <boost/config.hpp>
+#endif
+
+#ifdef BOOST_MSVC
+
+ #pragma warning (push)
+ //
+ //'function' : resolved overload was found by argument-dependent lookup
+ //A function found by argument-dependent lookup (Koenig lookup) was eventually
+ //chosen by overload resolution.
+ //
+ //In Visual C++ .NET and earlier compilers, a different function would have
+ //been called. To pick the original function, use an explicitly qualified name.
+ //
+
+ //warning C4275: non dll-interface class 'x' used as base for
+ //dll-interface class 'Y'
+ #pragma warning (disable : 4275)
+ //warning C4251: 'x' : class 'y' needs to have dll-interface to
+ //be used by clients of class 'z'
+ #pragma warning (disable : 4251)
+ #pragma warning (disable : 4675)
+ #pragma warning (disable : 4996)
+ #pragma warning (disable : 4503)
+ #pragma warning (disable : 4284) // odd return type for operator->
+ #pragma warning (disable : 4244) // possible loss of data
+ #pragma warning (disable : 4521) ////Disable "multiple copy constructors specified"
+ #pragma warning (disable : 4522)
+ #pragma warning (disable : 4146)
+ #pragma warning (disable : 4267) //conversion from 'X' to 'Y', possible loss of data
+ #pragma warning (disable : 4127) //conditional expression is constant
+ #pragma warning (disable : 4706) //assignment within conditional expression
+ #pragma warning (disable : 4541) //'typeid' used on polymorphic type 'boost::exception' with /GR-
+ #pragma warning (disable : 4512) //'typeid' used on polymorphic type 'boost::exception' with /GR-
+#endif
+
+//#define BOOST_INTRUSIVE_USE_ITERATOR_FACADE
+//#define BOOST_INTRUSIVE_USE_ITERATOR_ENABLE_IF_CONVERTIBLE
diff --git a/boost/intrusive/detail/config_end.hpp b/boost/intrusive/detail/config_end.hpp
new file mode 100644
index 0000000..4277cb5
--- /dev/null
+++ b/boost/intrusive/detail/config_end.hpp
@@ -0,0 +1,15 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#if defined BOOST_MSVC
+ #pragma warning (pop)
+#endif
diff --git a/boost/intrusive/detail/ebo_functor_holder.hpp b/boost/intrusive/detail/ebo_functor_holder.hpp
new file mode 100644
index 0000000..d4c2d15
--- /dev/null
+++ b/boost/intrusive/detail/ebo_functor_holder.hpp
@@ -0,0 +1,95 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Joaquin M Lopez Munoz 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
+#define BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<typename T, bool IsEmpty = true>
+class ebo_functor_holder_impl
+{
+ public:
+ ebo_functor_holder_impl()
+ {}
+ ebo_functor_holder_impl(const T& t)
+ : t_(t)
+ {}
+ template<class Arg1, class Arg2>
+ ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2)
+ : t_(arg1, arg2)
+ {}
+
+ T& get(){return t_;}
+ const T& get()const{return t_;}
+
+ private:
+ T t_;
+};
+
+template<typename T>
+class ebo_functor_holder_impl<T, false>
+ : public T
+{
+ public:
+ ebo_functor_holder_impl()
+ {}
+ ebo_functor_holder_impl(const T& t)
+ : T(t)
+ {}
+ template<class Arg1, class Arg2>
+ ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2)
+ : T(arg1, arg2)
+ {}
+
+ T& get(){return *this;}
+ const T& get()const{return *this;}
+};
+
+template<typename T>
+class ebo_functor_holder
+ : public ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value>
+{
+ private:
+ typedef ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value> super;
+
+ public:
+ ebo_functor_holder(){}
+ ebo_functor_holder(const T& t)
+ : super(t)
+ {}
+
+ template<class Arg1, class Arg2>
+ ebo_functor_holder(const Arg1& arg1, const Arg2& arg2)
+ : super(arg1, arg2)
+ {}
+
+ ebo_functor_holder& operator=(const ebo_functor_holder& x)
+ {
+ this->get()=x.get();
+ return *this;
+ }
+};
+
+
+} //namespace detail {
+} //namespace intrusive {
+} //namespace boost {
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
diff --git a/boost/intrusive/detail/function_detector.hpp b/boost/intrusive/detail/function_detector.hpp
new file mode 100644
index 0000000..e00a7ef
--- /dev/null
+++ b/boost/intrusive/detail/function_detector.hpp
@@ -0,0 +1,88 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2009-2009.
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+// This code was modified from the code posted by Alexandre Courpron in his
+// article "Interface Detection" in The Code Project:
+// http://www.codeproject.com/KB/architecture/Detector.aspx
+///////////////////////////////////////////////////////////////////////////////
+// Copyright 2007 Alexandre Courpron
+//
+// Permission to use, copy, modify, redistribute and sell this software,
+// provided that this copyright notice appears on all copies of the software.
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
+#define BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace function_detector {
+
+ typedef char NotFoundType;
+ struct StaticFunctionType { NotFoundType x [2]; };
+ struct NonStaticFunctionType { NotFoundType x [3]; };
+
+ enum
+ { NotFound = 0,
+ StaticFunction = sizeof( StaticFunctionType ) - sizeof( NotFoundType ),
+ NonStaticFunction = sizeof( NonStaticFunctionType ) - sizeof( NotFoundType )
+ };
+
+} //namespace boost {
+} //namespace intrusive {
+} //namespace function_detector {
+
+#define BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(Identifier, InstantiationKey) \
+ namespace boost { \
+ namespace intrusive { \
+ namespace function_detector { \
+ template < class T, \
+ class NonStaticType, \
+ class NonStaticConstType, \
+ class StaticType > \
+ class DetectMember_##InstantiationKey_##Identifier { \
+ template < NonStaticType > \
+ struct TestNonStaticNonConst ; \
+ \
+ template < NonStaticConstType > \
+ struct TestNonStaticConst ; \
+ \
+ template < StaticType > \
+ struct TestStatic ; \
+ \
+ template <class U > \
+ static NonStaticFunctionType Test( TestNonStaticNonConst<&U::Identifier>*, int ); \
+ \
+ template <class U > \
+ static NonStaticFunctionType Test( TestNonStaticConst<&U::Identifier>*, int ); \
+ \
+ template <class U> \
+ static StaticFunctionType Test( TestStatic<&U::Identifier>*, int ); \
+ \
+ template <class U> \
+ static NotFoundType Test( ... ); \
+ public : \
+ static const int check = NotFound + (sizeof(Test<T>(0, 0)) - sizeof(NotFoundType));\
+ };\
+}}} //namespace boost::intrusive::function_detector {
+
+#define BOOST_INTRUSIVE_DETECT_FUNCTION(Class, InstantiationKey, ReturnType, Identifier, Params) \
+ ::boost::intrusive::function_detector::DetectMember_##InstantiationKey_##Identifier< Class,\
+ ReturnType (Class::*)Params,\
+ ReturnType (Class::*)Params const,\
+ ReturnType (*)Params \
+ >::check
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //@ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
diff --git a/boost/intrusive/detail/generic_hook.hpp b/boost/intrusive/detail/generic_hook.hpp
new file mode 100644
index 0000000..fc35610
--- /dev/null
+++ b/boost/intrusive/detail/generic_hook.hpp
@@ -0,0 +1,209 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_GENERIC_HOOK_HPP
+#define BOOST_INTRUSIVE_GENERIC_HOOK_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/static_assert.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+/// @cond
+
+enum
+{ NoBaseHook
+, ListBaseHook
+, SlistBaseHook
+, SetBaseHook
+, UsetBaseHook
+, SplaySetBaseHook
+, AvlSetBaseHook
+, BsSetBaseHook
+, AnyBaseHook
+};
+
+struct no_default_definer{};
+
+template <class Hook, unsigned int>
+struct default_definer;
+
+template <class Hook>
+struct default_definer<Hook, ListBaseHook>
+{ typedef Hook default_list_hook; };
+
+template <class Hook>
+struct default_definer<Hook, SlistBaseHook>
+{ typedef Hook default_slist_hook; };
+
+template <class Hook>
+struct default_definer<Hook, SetBaseHook>
+{ typedef Hook default_set_hook; };
+
+template <class Hook>
+struct default_definer<Hook, UsetBaseHook>
+{ typedef Hook default_uset_hook; };
+
+template <class Hook>
+struct default_definer<Hook, SplaySetBaseHook>
+{ typedef Hook default_splay_set_hook; };
+
+template <class Hook>
+struct default_definer<Hook, AvlSetBaseHook>
+{ typedef Hook default_avl_set_hook; };
+
+template <class Hook>
+struct default_definer<Hook, BsSetBaseHook>
+{ typedef Hook default_bs_set_hook; };
+
+template <class Hook>
+struct default_definer<Hook, AnyBaseHook>
+{ typedef Hook default_any_hook; };
+
+template <class Hook, unsigned int BaseHookType>
+struct make_default_definer
+{
+ typedef typename detail::if_c
+ < BaseHookType != 0
+ , default_definer<Hook, BaseHookType>
+ , no_default_definer>::type type;
+};
+
+template
+ < class GetNodeAlgorithms
+ , class Tag
+ , link_mode_type LinkMode
+ , int HookType
+ >
+struct make_node_holder
+{
+ typedef typename detail::if_c
+ <!detail::is_same<Tag, member_tag>::value
+ , detail::node_holder
+ < typename GetNodeAlgorithms::type::node
+ , Tag
+ , LinkMode
+ , HookType>
+ , typename GetNodeAlgorithms::type::node
+ >::type type;
+};
+
+/// @endcond
+
+template
+ < class GetNodeAlgorithms
+ , class Tag
+ , link_mode_type LinkMode
+ , int HookType
+ >
+class generic_hook
+ /// @cond
+
+ //If the hook is a base hook, derive generic hook from detail::node_holder
+ //so that a unique base class is created to convert from the node
+ //to the type. This mechanism will be used by base_hook_traits.
+ //
+ //If the hook is a member hook, generic hook will directly derive
+ //from the hook.
+ : public make_default_definer
+ < generic_hook<GetNodeAlgorithms, Tag, LinkMode, HookType>
+ , detail::is_same<Tag, default_tag>::value*HookType
+ >::type
+ , public make_node_holder<GetNodeAlgorithms, Tag, LinkMode, HookType>::type
+ /// @endcond
+{
+ /// @cond
+ typedef typename GetNodeAlgorithms::type node_algorithms;
+ typedef typename node_algorithms::node node;
+ typedef typename node_algorithms::node_ptr node_ptr;
+ typedef typename node_algorithms::const_node_ptr const_node_ptr;
+
+ public:
+ struct boost_intrusive_tags
+ {
+ static const int hook_type = HookType;
+ static const link_mode_type link_mode = LinkMode;
+ typedef Tag tag;
+ typedef typename GetNodeAlgorithms::type::node_traits node_traits;
+ static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value;
+ static const bool safemode_or_autounlink =
+ (int)link_mode == (int)auto_unlink || (int)link_mode == (int)safe_link;
+ };
+
+ node_ptr this_ptr()
+ { return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*this)); }
+
+ const_node_ptr this_ptr() const
+ { return pointer_traits<const_node_ptr>::pointer_to(static_cast<const node&>(*this)); }
+
+ public:
+ /// @endcond
+
+ generic_hook()
+ {
+ if(boost_intrusive_tags::safemode_or_autounlink){
+ node_algorithms::init(this->this_ptr());
+ }
+ }
+
+ generic_hook(const generic_hook& )
+ {
+ if(boost_intrusive_tags::safemode_or_autounlink){
+ node_algorithms::init(this->this_ptr());
+ }
+ }
+
+ generic_hook& operator=(const generic_hook& )
+ { return *this; }
+
+ ~generic_hook()
+ {
+ destructor_impl
+ (*this, detail::link_dispatch<boost_intrusive_tags::link_mode>());
+ }
+
+ void swap_nodes(generic_hook &other)
+ {
+ node_algorithms::swap_nodes
+ (this->this_ptr(), other.this_ptr());
+ }
+
+ bool is_linked() const
+ {
+ //is_linked() can be only used in safe-mode or auto-unlink
+ BOOST_STATIC_ASSERT(( boost_intrusive_tags::safemode_or_autounlink ));
+ return !node_algorithms::unique(this->this_ptr());
+ }
+
+ void unlink()
+ {
+ BOOST_STATIC_ASSERT(( (int)boost_intrusive_tags::link_mode == (int)auto_unlink ));
+ node_algorithms::unlink(this->this_ptr());
+ node_algorithms::init(this->this_ptr());
+ }
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP
diff --git a/boost/intrusive/detail/has_member_function_callable_with.hpp b/boost/intrusive/detail/has_member_function_callable_with.hpp
new file mode 100644
index 0000000..33811e3
--- /dev/null
+++ b/boost/intrusive/detail/has_member_function_callable_with.hpp
@@ -0,0 +1,356 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2011-2011. 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/intrusive for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+// sample.h
+
+#if !BOOST_PP_IS_ITERATING
+
+ #ifndef BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED
+ #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED
+
+ #include <boost/intrusive/detail/config_begin.hpp>
+ #include <boost/intrusive/detail/workaround.hpp>
+ #include <boost/intrusive/detail/preprocessor.hpp>
+ #include <boost/static_assert.hpp>
+ #include <boost/move/move.hpp>
+
+ //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and
+ //wrong SFINAE for GCC 4.2/4.3
+ #if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__*100 + __GNUC_MINOR__*10) >= 340) && ((__GNUC__*100 + __GNUC_MINOR__*10) <= 430)
+ #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED
+ #elif defined(BOOST_INTEL) && (BOOST_INTEL < 1200 )
+ #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED
+ #endif
+
+ namespace boost_intrusive_has_member_function_callable_with {
+
+ struct dont_care
+ {
+ dont_care(...);
+ };
+
+ struct private_type
+ {
+ static private_type p;
+ private_type const &operator,(int) const;
+ };
+
+ typedef char yes_type; // sizeof(yes_type) == 1
+ struct no_type{ char dummy[2]; }; // sizeof(no_type) == 2
+
+ template<typename T>
+ no_type is_private_type(T const &);
+ yes_type is_private_type(private_type const &);
+
+ } //boost_intrusive_has_member_function_callable_with
+
+ #include <boost/intrusive/detail/config_end.hpp>
+
+ #endif //BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED
+
+#else //!BOOST_PP_IS_ITERATING
+
+ #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
+ #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME not defined!"
+ #endif
+
+ #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN
+ #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN not defined!"
+ #endif
+
+ #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
+ #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END not defined!"
+ #endif
+
+ #if BOOST_PP_ITERATION_START() != 0
+ #error "BOOST_PP_ITERATION_START() must be zero (0)"
+ #endif
+
+ #if BOOST_PP_ITERATION() == 0
+
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN
+
+ template <typename Type>
+ class BOOST_PP_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
+ {
+ struct BaseMixin
+ {
+ void BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME();
+ };
+
+ struct Base : public Type, public BaseMixin { Base(); };
+ template <typename T, T t> class Helper{};
+
+ template <typename U>
+ static boost_intrusive_has_member_function_callable_with::no_type deduce
+ (U*, Helper<void (BaseMixin::*)(), &U::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME>* = 0);
+ static boost_intrusive_has_member_function_callable_with::yes_type deduce(...);
+
+ public:
+ static const bool value =
+ sizeof(boost_intrusive_has_member_function_callable_with::yes_type) == sizeof(deduce((Base*)(0)));
+ };
+
+ #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ template<typename Fun, bool HasFunc
+ BOOST_PP_ENUM_TRAILING(BOOST_PP_ITERATION_FINISH(), BOOST_INTRUSIVE_PP_TEMPLATE_PARAM_VOID_DEFAULT, _)>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl);
+ //!
+
+ template<typename Fun BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION_FINISH(), class P)>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl)
+ <Fun, false BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION_FINISH(), P)>
+ {
+ static const bool value = false;
+ };
+ //!
+
+ #if !defined(_MSC_VER) || (_MSC_VER != 1600)
+
+ #if defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED)
+
+ template<typename Fun>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)>
+ {
+ //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and
+ //wrong SFINAE for GCC 4.2/4.3
+ static const bool value = true;
+ };
+
+ #else
+
+ //Special case for 0 args
+ template< class F
+ , std::size_t N =
+ sizeof((boost::move_detail::declval<F>().
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))>
+ struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
+ {
+ boost_intrusive_has_member_function_callable_with::yes_type dummy;
+ BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int);
+ };
+
+ //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not
+ //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0.
+ template<class F>
+ struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<F, 0>
+ {
+ boost_intrusive_has_member_function_callable_with::no_type dummy;
+ BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int);
+ };
+
+ template<typename Fun>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)>
+ {
+ template<class U>
+ static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>
+ Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*);
+
+ template <class U>
+ static boost_intrusive_has_member_function_callable_with::no_type Test(...);
+
+ static const bool value = sizeof(Test< Fun >(0))
+ == sizeof(boost_intrusive_has_member_function_callable_with::yes_type);
+ };
+ #endif
+
+ #else //#if !defined(_MSC_VER) || (_MSC_VER != 1600)
+ template<typename Fun>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)>
+ {
+ template<class U>
+ static decltype( boost::move_detail::declval<Fun>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME()
+ , boost_intrusive_has_member_function_callable_with::yes_type())
+ Test(Fun*);
+
+ template<class U>
+ static boost_intrusive_has_member_function_callable_with::no_type Test(...);
+
+ static const bool value = sizeof(Test<Fun>(0))
+ == sizeof(boost_intrusive_has_member_function_callable_with::yes_type);
+ };
+ #endif //#if !defined(_MSC_VER) || (_MSC_VER != 1600)
+
+ #else //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ template<typename Fun, bool HasFunc, class ...Args>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl);
+
+ template<typename Fun, class ...Args>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ <Fun, false, Args...>
+ {
+ static const bool value = false;
+ };
+
+ //Special case for 0 args
+ template< class F
+ , std::size_t N =
+ sizeof((boost::move_detail::declval<F>().
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))>
+ struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
+ {
+ boost_intrusive_has_member_function_callable_with::yes_type dummy;
+ BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int);
+ };
+
+ //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not
+ //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0.
+ template<class F>
+ struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<F, 0>
+ {
+ boost_intrusive_has_member_function_callable_with::no_type dummy;
+ BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int);
+ };
+
+ template<typename Fun>
+ struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ <Fun, true>
+ {
+ template<class U>
+ static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
+ <U> Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*);
+
+ template <class U>
+ static boost_intrusive_has_member_function_callable_with::no_type Test(...);
+
+ static const bool value = sizeof(Test< Fun >(0))
+ == sizeof(boost_intrusive_has_member_function_callable_with::yes_type);
+ };
+
+ template<typename Fun, class ...DontCares>
+ struct BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )
+ : Fun
+ {
+ BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )();
+ using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME;
+
+ boost_intrusive_has_member_function_callable_with::private_type
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
+ ( DontCares...) const;
+ };
+
+ template<typename Fun, class ...Args>
+ struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl)
+ <Fun, true , Args...>
+ {
+ template<class T>
+ struct make_dontcare
+ {
+ typedef boost_intrusive_has_member_function_callable_with::dont_care type;
+ };
+
+ typedef BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )
+ <Fun, typename make_dontcare<Args>::type...> FunWrap;
+
+ static bool const value = (sizeof(boost_intrusive_has_member_function_callable_with::no_type) ==
+ sizeof(boost_intrusive_has_member_function_callable_with::is_private_type
+ ( (::boost::move_detail::declval< FunWrap >().
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
+ ( ::boost::move_detail::declval<Args>()... ), 0) )
+ )
+ );
+ };
+
+ template<typename Fun, class ...Args>
+ struct BOOST_PP_CAT( has_member_function_callable_with_
+ , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
+ : public BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_
+ , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ < Fun
+ , BOOST_PP_CAT( has_member_function_named_
+ , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )<Fun>::value
+ , Args... >
+ {};
+
+ #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
+
+ #else //BOOST_PP_ITERATION() == 0
+
+ #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN
+
+ template<typename Fun>
+ struct BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION())
+ , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))
+ : Fun
+ {
+ BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION())
+ , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))();
+
+ using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME;
+ boost_intrusive_has_member_function_callable_with::private_type
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
+ ( BOOST_PP_ENUM(BOOST_PP_ITERATION()
+ , BOOST_INTRUSIVE_PP_IDENTITY
+ , boost_intrusive_has_member_function_callable_with::dont_care)) const;
+ };
+
+ template<typename Fun BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), class P)>
+ struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_
+ , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl)
+ <Fun, true
+ BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), P)
+ BOOST_PP_ENUM_TRAILING( BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION())
+ , BOOST_INTRUSIVE_PP_IDENTITY
+ , void)>
+ {
+ typedef BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION())
+ , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))<Fun>
+ FunWrap;
+ static bool const value =
+ (sizeof(boost_intrusive_has_member_function_callable_with::no_type) ==
+ sizeof(boost_intrusive_has_member_function_callable_with::is_private_type
+ ( (boost::move_detail::declval<FunWrap>().
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
+ ( BOOST_PP_ENUM( BOOST_PP_ITERATION(), BOOST_INTRUSIVE_PP_DECLVAL, _) ), 0
+ )
+ )
+ )
+ );
+ };
+
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
+ #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ #endif //BOOST_PP_ITERATION() == 0
+
+ #if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH()
+
+ #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN
+
+ template<typename Fun
+ BOOST_PP_ENUM_TRAILING(BOOST_PP_ITERATION_FINISH(), BOOST_INTRUSIVE_PP_TEMPLATE_PARAM_VOID_DEFAULT, _)>
+ struct BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)
+ : public BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl)
+ <Fun, BOOST_PP_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<Fun>::value
+ BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION_FINISH(), P) >
+ {};
+
+ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
+
+ #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING)
+
+ #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME
+ #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN
+ #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END
+
+ #endif //#if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH()
+
+#endif //!BOOST_PP_IS_ITERATING
diff --git a/boost/intrusive/detail/hashtable_node.hpp b/boost/intrusive/detail/hashtable_node.hpp
new file mode 100644
index 0000000..ac6ab81
--- /dev/null
+++ b/boost/intrusive/detail/hashtable_node.hpp
@@ -0,0 +1,249 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_HASHTABLE_NODE_HPP
+#define BOOST_INTRUSIVE_HASHTABLE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/intrusive/circular_list_algorithms.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+//#include <boost/intrusive/detail/slist_node.hpp> //remove-me
+#include <boost/intrusive/pointer_traits.hpp>
+#include <cstddef>
+#include <boost/pointer_cast.hpp>
+#include <boost/move/move.hpp>
+
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<int Dummy = 0>
+struct prime_list_holder
+{
+ static const std::size_t prime_list[];
+ static const std::size_t prime_list_size;
+};
+
+template<int Dummy>
+const std::size_t prime_list_holder<Dummy>::prime_list[] = {
+ 3ul, 7ul, 11ul, 17ul, 29ul,
+ 53ul, 97ul, 193ul, 389ul, 769ul,
+ 1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
+ 49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
+ 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
+ 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
+ 1610612741ul, 3221225473ul, 4294967291ul };
+
+template<int Dummy>
+const std::size_t prime_list_holder<Dummy>::prime_list_size
+ = sizeof(prime_list)/sizeof(std::size_t);
+
+template <class Slist>
+struct bucket_impl : public Slist
+{
+ typedef Slist slist_type;
+ bucket_impl()
+ {}
+
+ bucket_impl(const bucket_impl &)
+ {}
+
+ ~bucket_impl()
+ {
+ //This bucket is still being used!
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(Slist::empty());
+ }
+
+ bucket_impl &operator=(const bucket_impl&)
+ {
+ //This bucket is still in use!
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(Slist::empty());
+ //Slist::clear();
+ return *this;
+ }
+};
+
+template<class Slist>
+struct bucket_traits_impl
+{
+ private:
+ BOOST_COPYABLE_AND_MOVABLE(bucket_traits_impl)
+
+ public:
+ /// @cond
+
+ typedef typename pointer_traits
+ <typename Slist::pointer>::template rebind_pointer
+ < bucket_impl<Slist> >::type bucket_ptr;
+ typedef typename Slist::size_type size_type;
+ /// @endcond
+
+ bucket_traits_impl(bucket_ptr buckets, size_type len)
+ : buckets_(buckets), buckets_len_(len)
+ {}
+
+ bucket_traits_impl(const bucket_traits_impl &x)
+ : buckets_(x.buckets_), buckets_len_(x.buckets_len_)
+ {}
+
+
+ bucket_traits_impl(BOOST_RV_REF(bucket_traits_impl) x)
+ : buckets_(x.buckets_), buckets_len_(x.buckets_len_)
+ { x.buckets_ = bucket_ptr(); x.buckets_len_ = 0; }
+
+ bucket_traits_impl& operator=(BOOST_RV_REF(bucket_traits_impl) x)
+ {
+ buckets_ = x.buckets_; buckets_len_ = x.buckets_len_;
+ x.buckets_ = bucket_ptr(); x.buckets_len_ = 0; return *this;
+ }
+
+ bucket_traits_impl& operator=(BOOST_COPY_ASSIGN_REF(bucket_traits_impl) x)
+ {
+ buckets_ = x.buckets_; buckets_len_ = x.buckets_len_; return *this;
+ }
+
+ const bucket_ptr &bucket_begin() const
+ { return buckets_; }
+
+ size_type bucket_count() const
+ { return buckets_len_; }
+
+ private:
+ bucket_ptr buckets_;
+ size_type buckets_len_;
+};
+
+template<class Container, bool IsConst>
+class hashtable_iterator
+ : public std::iterator
+ < std::forward_iterator_tag
+ , typename Container::value_type
+ , typename pointer_traits<typename Container::value_type*>::difference_type
+ , typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type *
+ , typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type &
+ >
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::siterator siterator;
+ typedef typename Container::const_siterator const_siterator;
+ typedef typename Container::bucket_type bucket_type;
+
+ typedef typename pointer_traits
+ <typename Container::pointer>::template rebind_pointer
+ < const Container >::type const_cont_ptr;
+ typedef typename Container::size_type size_type;
+
+ static typename Container::node_ptr downcast_bucket(typename bucket_type::node_ptr p)
+ {
+ return pointer_traits<typename Container::node_ptr>::
+ pointer_to(static_cast<typename Container::node&>(*p));
+ }
+
+ public:
+ typedef typename Container::value_type value_type;
+ typedef typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type *pointer;
+ typedef typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type &reference;
+
+ hashtable_iterator ()
+ {}
+
+ explicit hashtable_iterator(siterator ptr, const Container *cont)
+ : slist_it_ (ptr), cont_ (cont ? pointer_traits<const_cont_ptr>::pointer_to(*cont) : const_cont_ptr() )
+ {}
+
+ hashtable_iterator(const hashtable_iterator<Container, false> &other)
+ : slist_it_(other.slist_it()), cont_(other.get_container())
+ {}
+
+ const siterator &slist_it() const
+ { return slist_it_; }
+
+ hashtable_iterator<Container, false> unconst() const
+ { return hashtable_iterator<Container, false>(this->slist_it(), this->get_container()); }
+
+ public:
+ hashtable_iterator& operator++()
+ { this->increment(); return *this; }
+
+ hashtable_iterator operator++(int)
+ {
+ hashtable_iterator result (*this);
+ this->increment();
+ return result;
+ }
+
+ friend bool operator== (const hashtable_iterator& i, const hashtable_iterator& i2)
+ { return i.slist_it_ == i2.slist_it_; }
+
+ friend bool operator!= (const hashtable_iterator& i, const hashtable_iterator& i2)
+ { return !(i == i2); }
+
+ reference operator*() const
+ { return *this->operator ->(); }
+
+ pointer operator->() const
+ {
+ return boost::intrusive::detail::to_raw_pointer(this->get_real_value_traits()->to_value_ptr
+ (downcast_bucket(slist_it_.pointed_node())));
+ }
+
+ const const_cont_ptr &get_container() const
+ { return cont_; }
+
+ const real_value_traits *get_real_value_traits() const
+ { return &this->get_container()->get_real_value_traits(); }
+
+ private:
+ void increment()
+ {
+ const Container *cont = boost::intrusive::detail::to_raw_pointer(cont_);
+ bucket_type* buckets = boost::intrusive::detail::to_raw_pointer(cont->bucket_pointer());
+ size_type buckets_len = cont->bucket_count();
+
+ ++slist_it_;
+ if(buckets[0].cend().pointed_node() <= slist_it_.pointed_node() &&
+ slist_it_.pointed_node()<= buckets[buckets_len].cend().pointed_node() ){
+ //Now get the bucket_impl from the iterator
+ const bucket_type &b = static_cast<const bucket_type&>
+ (bucket_type::slist_type::container_from_end_iterator(slist_it_));
+
+ //Now just calculate the index b has in the bucket array
+ size_type n_bucket = static_cast<size_type>(&b - &buckets[0]);
+ do{
+ if (++n_bucket == buckets_len){
+ slist_it_ = (&buckets[0] + buckets_len)->end();
+ break;
+ }
+ slist_it_ = buckets[n_bucket].begin();
+ }
+ while (slist_it_ == buckets[n_bucket].end());
+ }
+ }
+
+ siterator slist_it_;
+ const_cont_ptr cont_;
+};
+
+} //namespace detail {
+} //namespace intrusive {
+} //namespace boost {
+
+#endif
diff --git a/boost/intrusive/detail/is_stateful_value_traits.hpp b/boost/intrusive/detail/is_stateful_value_traits.hpp
new file mode 100644
index 0000000..e38f4de
--- /dev/null
+++ b/boost/intrusive/detail/is_stateful_value_traits.hpp
@@ -0,0 +1,77 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2009-2009.
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP
+#define BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+
+#if defined(_MSC_VER) && (_MSC_VER <= 1310)
+
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<class ValueTraits>
+struct is_stateful_value_traits
+{
+ static const bool value = !detail::is_empty_class<ValueTraits>::value;
+};
+
+}}}
+
+#else
+
+#include <boost/intrusive/detail/function_detector.hpp>
+
+BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(to_node_ptr, boost_intrusive)
+BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(to_value_ptr, boost_intrusive)
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<class ValueTraits>
+struct is_stateful_value_traits
+{
+ typedef typename ValueTraits::node_ptr node_ptr;
+ typedef typename ValueTraits::pointer pointer;
+ typedef typename ValueTraits::value_type value_type;
+ typedef typename ValueTraits::const_node_ptr const_node_ptr;
+ typedef typename ValueTraits::const_pointer const_pointer;
+
+ typedef ValueTraits value_traits;
+
+ static const bool value =
+ (boost::intrusive::function_detector::NonStaticFunction ==
+ (BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, node_ptr, to_node_ptr, (value_type&) )))
+ ||
+ (boost::intrusive::function_detector::NonStaticFunction ==
+ (BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, pointer, to_value_ptr, (node_ptr) )))
+ ||
+ (boost::intrusive::function_detector::NonStaticFunction ==
+ (BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, const_node_ptr, to_node_ptr, (const value_type&) )))
+ ||
+ (boost::intrusive::function_detector::NonStaticFunction ==
+ (BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, const_pointer, to_value_ptr, (const_node_ptr) )))
+ ;
+};
+
+}}}
+
+#endif
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //@ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP
diff --git a/boost/intrusive/detail/list_node.hpp b/boost/intrusive/detail/list_node.hpp
new file mode 100644
index 0000000..df99912
--- /dev/null
+++ b/boost/intrusive/detail/list_node.hpp
@@ -0,0 +1,190 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_LIST_NODE_HPP
+#define BOOST_INTRUSIVE_LIST_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+
+namespace boost {
+namespace intrusive {
+
+// list_node_traits can be used with circular_list_algorithms and supplies
+// a list_node holding the pointers needed for a double-linked list
+// it is used by list_derived_node and list_member_node
+
+template<class VoidPointer>
+struct list_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>:: template rebind_pointer<list_node>::type node_ptr;
+ node_ptr next_;
+ node_ptr prev_;
+};
+
+template<class VoidPointer>
+struct list_node_traits
+{
+ typedef list_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>:: template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>:: template rebind_pointer<const node>::type const_node_ptr;
+
+ static const node_ptr &get_previous(const const_node_ptr & n)
+ { return n->prev_; }
+
+ static void set_previous(const node_ptr & n, const node_ptr & prev)
+ { n->prev_ = prev; }
+
+ static const node_ptr &get_next(const const_node_ptr & n)
+ { return n->next_; }
+
+ static void set_next(const node_ptr & n, const node_ptr & next)
+ { n->next_ = next; }
+};
+
+// list_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class list_iterator
+ : public std::iterator
+ < std::bidirectional_iterator_tag
+ , typename Container::value_type
+ , typename Container::difference_type
+ , typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type
+ , typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ typedef typename Container::value_type value_type;
+ typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer;
+ typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference;
+
+ list_iterator()
+ : members_ (node_ptr(), 0)
+ {}
+
+ explicit list_iterator(const node_ptr & node, const Container *cont_ptr)
+ : members_ (node, cont_ptr)
+ {}
+
+ list_iterator(list_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ list_iterator &operator=(const node_ptr &node)
+ { members_.nodeptr_ = node; return static_cast<list_iterator&>(*this); }
+
+ public:
+ list_iterator& operator++()
+ {
+ node_ptr p = node_traits::get_next(members_.nodeptr_);
+ members_.nodeptr_ = p;
+ //members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return static_cast<list_iterator&> (*this);
+ }
+
+ list_iterator operator++(int)
+ {
+ list_iterator result (*this);
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return result;
+ }
+
+ list_iterator& operator--()
+ {
+ members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
+ return static_cast<list_iterator&> (*this);
+ }
+
+ list_iterator operator--(int)
+ {
+ list_iterator result (*this);
+ members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
+ return result;
+ }
+
+ friend bool operator== (const list_iterator& l, const list_iterator& r)
+ { return l.pointed_node() == r.pointed_node(); }
+
+ friend bool operator!= (const list_iterator& l, const list_iterator& r)
+ { return !(l == r); }
+
+ reference operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return this->get_real_value_traits()->to_value_ptr(members_.nodeptr_); }
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr){
+ const Container* c = static_cast<const Container*>(members_.get_ptr());
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(c != 0);
+ return c;
+ }
+ else{
+ return 0;
+ }
+ }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ list_iterator<Container, false> unconst() const
+ { return list_iterator<Container, false>(this->pointed_node(), this->get_container()); }
+
+ private:
+ struct members
+ : public detail::select_constptr
+ <void_pointer, store_container_ptr>::type
+ {
+ typedef typename detail::select_constptr
+ <void_pointer, store_container_ptr>::type Base;
+
+ members(const node_ptr &n_ptr, const void *cont)
+ : Base(cont), nodeptr_(n_ptr)
+ {}
+
+ node_ptr nodeptr_;
+ } members_;
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_LIST_NODE_HPP
diff --git a/boost/intrusive/detail/memory_util.hpp b/boost/intrusive/detail/memory_util.hpp
new file mode 100644
index 0000000..ad026c6
--- /dev/null
+++ b/boost/intrusive/detail/memory_util.hpp
@@ -0,0 +1,279 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Pablo Halpern 2009. 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)
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2011-2011. 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/intrusive for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP
+#define BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP
+
+#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/workaround.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/detail/preprocessor.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template <typename T>
+inline T* addressof(T& obj)
+{
+ return static_cast<T*>
+ (static_cast<void*>
+ (const_cast<char*>
+ (&reinterpret_cast<const char&>(obj))
+ )
+ );
+}
+
+template <typename T> struct unvoid { typedef T type; };
+template <> struct unvoid<void> { struct type { }; };
+template <> struct unvoid<const void> { struct type { }; };
+
+template <typename T>
+struct LowPriorityConversion
+{
+ // Convertible from T with user-defined-conversion rank.
+ LowPriorityConversion(const T&) { }
+};
+
+// Infrastructure for providing a default type for T::TNAME if absent.
+#define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \
+ template <typename T, typename DefaultType> \
+ struct boost_intrusive_default_type_ ## TNAME \
+ { \
+ template <typename X> \
+ static char test(int, typename X::TNAME*); \
+ \
+ template <typename X> \
+ static int test(boost::intrusive::detail:: \
+ LowPriorityConversion<int>, void*); \
+ \
+ struct DefaultWrap { typedef DefaultType TNAME; }; \
+ \
+ static const bool value = (1 == sizeof(test<T>(0, 0))); \
+ \
+ typedef typename \
+ ::boost::intrusive::detail::if_c \
+ <value, T, DefaultWrap>::type::TNAME type; \
+ }; \
+ \
+ template <typename T, typename DefaultType> \
+ struct boost_intrusive_eval_default_type_ ## TNAME \
+ { \
+ template <typename X> \
+ static char test(int, typename X::TNAME*); \
+ \
+ template <typename X> \
+ static int test(boost::intrusive::detail:: \
+ LowPriorityConversion<int>, void*); \
+ \
+ struct DefaultWrap \
+ { typedef typename DefaultType::type TNAME; }; \
+ \
+ static const bool value = (1 == sizeof(test<T>(0, 0))); \
+ \
+ typedef typename \
+ ::boost::intrusive::detail::eval_if_c \
+ < value \
+ , ::boost::intrusive::detail::identity<T> \
+ , ::boost::intrusive::detail::identity<DefaultWrap> \
+ >::type::TNAME type; \
+ }; \
+//
+
+#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
+ typename INSTANTIATION_NS_PREFIX \
+ boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \
+//
+
+#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
+ typename INSTANTIATION_NS_PREFIX \
+ boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \
+//
+
+}}} //namespace boost::intrusive::detail
+
+#include <boost/intrusive/detail/has_member_function_callable_with.hpp>
+
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME pointer_to
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail {
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
+#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>))
+#include BOOST_PP_ITERATE()
+
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME static_cast_from
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail {
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
+#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>))
+#include BOOST_PP_ITERATE()
+
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME const_cast_from
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail {
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
+#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>))
+#include BOOST_PP_ITERATE()
+
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME dynamic_cast_from
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail {
+#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
+#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>))
+#include BOOST_PP_ITERATE()
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(element_type)
+BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type)
+
+//////////////////////
+//struct first_param
+//////////////////////
+
+template <typename T> struct first_param
+{ typedef void type; };
+
+#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
+
+ template <template <typename, typename...> class TemplateClass, typename T, typename... Args>
+ struct first_param< TemplateClass<T, Args...> >
+ {
+ typedef T type;
+ };
+
+#else //C++03 compilers
+
+ #define BOOST_PP_LOCAL_MACRO(n) \
+ template < template <typename \
+ BOOST_PP_ENUM_TRAILING(n, BOOST_INTRUSIVE_PP_IDENTITY, typename) > \
+ class TemplateClass \
+ , typename T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)> \
+ struct first_param \
+ < TemplateClass<T BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> > \
+ { \
+ typedef T type; \
+ }; \
+ //
+ #define BOOST_PP_LOCAL_LIMITS (0, BOOST_INTRUSIVE_MAX_CONSTRUCTOR_PARAMETERS)
+ #include BOOST_PP_LOCAL_ITERATE()
+
+#endif //!defined(BOOST_NO_VARIADIC_TEMPLATES)
+
+///////////////////////////
+//struct type_rebind_mode
+///////////////////////////
+template <typename Ptr, typename T>
+struct type_has_rebind
+{
+ template <typename X>
+ static char test(int, typename X::template rebind<T>*);
+
+ template <typename X>
+ static int test(boost::intrusive::detail::LowPriorityConversion<int>, void*);
+
+ static const bool value = (1 == sizeof(test<Ptr>(0, 0)));
+};
+
+template <typename Ptr, typename T>
+struct type_has_rebind_other
+{
+ template <typename X>
+ static char test(int, typename X::template rebind<T>::other*);
+
+ template <typename X>
+ static int test(boost::intrusive::detail::LowPriorityConversion<int>, void*);
+
+ static const bool value = (1 == sizeof(test<Ptr>(0, 0)));
+};
+
+template <typename Ptr, typename T>
+struct type_rebind_mode
+{
+ template <typename X>
+ static char test(int, typename X::template rebind<T>::other*);
+
+ template <typename X>
+ static int test(boost::intrusive::detail::LowPriorityConversion<int>, void*);
+
+ static const unsigned int rebind = (unsigned int)type_has_rebind<Ptr, T>::value;
+ static const unsigned int rebind_other = (unsigned int)type_has_rebind_other<Ptr, T>::value;
+ static const unsigned int mode = rebind + rebind*rebind_other;
+};
+
+////////////////////////
+//struct type_rebinder
+////////////////////////
+template <typename Ptr, typename U, unsigned int RebindMode = type_rebind_mode<Ptr, U>::mode>
+struct type_rebinder;
+
+// Implementation of pointer_traits<Ptr>::rebind if Ptr has
+// its own rebind::other type (C++03)
+template <typename Ptr, typename U>
+struct type_rebinder< Ptr, U, 2u >
+{
+ typedef typename Ptr::template rebind<U>::other type;
+};
+
+// Implementation of pointer_traits<Ptr>::rebind if Ptr has
+// its own rebind template.
+template <typename Ptr, typename U>
+struct type_rebinder< Ptr, U, 1u >
+{
+ typedef typename Ptr::template rebind<U> type;
+};
+
+// Specialization of pointer_traits<Ptr>::rebind if Ptr does not
+// have its own rebind template but has a the form Ptr<class T,
+// OtherArgs>, where OtherArgs comprises zero or more type parameters.
+// Many pointers fit this form, hence many pointers will get a
+// reasonable default for rebind.
+#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
+
+template <template <class, class...> class Ptr, typename T, class... Tn, class U>
+struct type_rebinder<Ptr<T, Tn...>, U, 0u >
+{
+ typedef Ptr<U, Tn...> type;
+};
+
+#else //C++03 compilers
+
+#define BOOST_PP_LOCAL_MACRO(n) \
+template < template <typename \
+ BOOST_PP_ENUM_TRAILING(n, BOOST_INTRUSIVE_PP_IDENTITY, typename) > \
+ class Ptr \
+ , typename T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) \
+ , class U> \
+struct type_rebinder \
+ < Ptr<T BOOST_PP_ENUM_TRAILING_PARAMS(n, P)>, U, 0u > \
+{ \
+ typedef Ptr<U BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> type; \
+}; \
+//
+#define BOOST_PP_LOCAL_LIMITS (0, BOOST_INTRUSIVE_MAX_CONSTRUCTOR_PARAMETERS)
+#include BOOST_PP_LOCAL_ITERATE()
+
+#endif //!defined(BOOST_NO_VARIADIC_TEMPLATES)
+
+} //namespace detail {
+} //namespace intrusive {
+} //namespace boost {
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif // ! defined(BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP)
diff --git a/boost/intrusive/detail/mpl.hpp b/boost/intrusive/detail/mpl.hpp
new file mode 100644
index 0000000..075381c
--- /dev/null
+++ b/boost/intrusive/detail/mpl.hpp
@@ -0,0 +1,355 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP
+#define BOOST_INTRUSIVE_DETAIL_MPL_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <cstddef>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+typedef char one;
+struct two {one _[2];};
+
+template< bool C_ >
+struct bool_
+{
+ static const bool value = C_;
+};
+
+typedef bool_<true> true_;
+typedef bool_<false> false_;
+
+typedef true_ true_type;
+typedef false_ false_type;
+
+typedef char yes_type;
+struct no_type
+{
+ char padding[8];
+};
+
+template <bool B, class T = void>
+struct enable_if_c {
+ typedef T type;
+};
+
+template <class T>
+struct enable_if_c<false, T> {};
+
+template <class Cond, class T = void>
+struct enable_if : public enable_if_c<Cond::value, T>{};
+
+template<class F, class Param>
+struct apply
+{
+ typedef typename F::template apply<Param>::type type;
+};
+
+template <class T, class U>
+class is_convertible
+{
+ typedef char true_t;
+ class false_t { char dummy[2]; };
+ static true_t dispatch(U);
+ static false_t dispatch(...);
+ static const T &trigger();
+ public:
+ static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t);
+};
+
+template<
+ bool C
+ , typename T1
+ , typename T2
+ >
+struct if_c
+{
+ typedef T1 type;
+};
+
+template<
+ typename T1
+ , typename T2
+ >
+struct if_c<false,T1,T2>
+{
+ typedef T2 type;
+};
+
+template<
+ typename C
+ , typename T1
+ , typename T2
+ >
+struct if_
+{
+ typedef typename if_c<0 != C::value, T1, T2>::type type;
+};
+
+template<
+ bool C
+ , typename F1
+ , typename F2
+ >
+struct eval_if_c
+ : if_c<C,F1,F2>::type
+{};
+
+template<
+ typename C
+ , typename T1
+ , typename T2
+ >
+struct eval_if
+ : if_<C,T1,T2>::type
+{};
+
+// identity is an extension: it is not part of the standard.
+template <class T>
+struct identity
+{
+ typedef T type;
+};
+
+#if defined(BOOST_MSVC) || defined(__BORLANDC_)
+#define BOOST_INTRUSIVE_TT_DECL __cdecl
+#else
+#define BOOST_INTRUSIVE_TT_DECL
+#endif
+
+#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64)
+#define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+#endif
+
+template <typename T>
+struct is_unary_or_binary_function_impl
+{ static const bool value = false; };
+
+// see boost ticket #4094
+// avoid duplicate definitions of is_unary_or_binary_function_impl
+#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (*)()>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (*)(...)>
+{ static const bool value = true; };
+
+#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__stdcall*)()>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__fastcall*)()>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__cdecl*)()>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__cdecl*)(...)>
+{ static const bool value = true; };
+
+#endif
+
+// see boost ticket #4094
+// avoid duplicate definitions of is_unary_or_binary_function_impl
+#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (*)(T0)>
+{ static const bool value = true; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (*)(T0...)>
+{ static const bool value = true; };
+
+#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)>
+{ static const bool value = true; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)>
+{ static const bool value = true; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__cdecl*)(T0)>
+{ static const bool value = true; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)>
+{ static const bool value = true; };
+
+#endif
+
+// see boost ticket #4094
+// avoid duplicate definitions of is_unary_or_binary_function_impl
+#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (*)(T0, T1)>
+{ static const bool value = true; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (*)(T0, T1...)>
+{ static const bool value = true; };
+
+#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)>
+{ static const bool value = true; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)>
+{ static const bool value = true; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1)>
+{ static const bool value = true; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1...)>
+{ static const bool value = true; };
+#endif
+
+template <typename T>
+struct is_unary_or_binary_function_impl<T&>
+{ static const bool value = false; };
+
+template<typename T>
+struct is_unary_or_binary_function
+{ static const bool value = is_unary_or_binary_function_impl<T>::value; };
+
+//boost::alignment_of yields to 10K lines of preprocessed code, so we
+//need an alternative
+template <typename T> struct alignment_of;
+
+template <typename T>
+struct alignment_of_hack
+{
+ char c;
+ T t;
+ alignment_of_hack();
+};
+
+template <unsigned A, unsigned S>
+struct alignment_logic
+{
+ static const std::size_t value = A < S ? A : S;
+};
+
+template< typename T >
+struct alignment_of
+{
+ static const std::size_t value = alignment_logic
+ < sizeof(alignment_of_hack<T>) - sizeof(T)
+ , sizeof(T)
+ >::value;
+};
+
+template <typename T, typename U>
+struct is_same
+{
+ typedef char yes_type;
+ struct no_type
+ {
+ char padding[8];
+ };
+
+ template <typename V>
+ static yes_type is_same_tester(V*, V*);
+ static no_type is_same_tester(...);
+
+ static T *t;
+ static U *u;
+
+ static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u));
+};
+
+template<typename T>
+struct add_const
+{ typedef const T type; };
+
+template<typename T>
+struct remove_const
+{ typedef T type; };
+
+template<typename T>
+struct remove_const<const T>
+{ typedef T type; };
+
+template<class T>
+struct remove_reference
+{
+ typedef T type;
+};
+
+template<class T>
+struct remove_reference<T&>
+{
+ typedef T type;
+};
+
+template<class Class>
+class is_empty_class
+{
+ template <typename T>
+ struct empty_helper_t1 : public T
+ {
+ empty_helper_t1();
+ int i[256];
+ };
+
+ struct empty_helper_t2
+ { int i[256]; };
+
+ public:
+ static const bool value = sizeof(empty_helper_t1<Class>) == sizeof(empty_helper_t2);
+};
+
+template<std::size_t S>
+struct ls_zeros
+{
+ static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value);
+};
+
+template<>
+struct ls_zeros<0>
+{
+ static const std::size_t value = 0;
+};
+
+template<>
+struct ls_zeros<1>
+{
+ static const std::size_t value = 0;
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP
diff --git a/boost/intrusive/detail/parent_from_member.hpp b/boost/intrusive/detail/parent_from_member.hpp
new file mode 100644
index 0000000..c06d932
--- /dev/null
+++ b/boost/intrusive/detail/parent_from_member.hpp
@@ -0,0 +1,69 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
+#define BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <cstddef>
+
+#if defined(BOOST_MSVC) || ((defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && defined(BOOST_INTEL))
+
+#define BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER
+#include <boost/cstdint.hpp>
+#endif
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<class Parent, class Member>
+inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member)
+{
+ //The implementation of a pointer to member is compiler dependent.
+ #if defined(BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER)
+ //msvc compliant compilers use their the first 32 bits as offset (even in 64 bit mode)
+ return *(const boost::int32_t*)(void*)&ptr_to_member;
+ //This works with gcc, msvc, ac++, ibmcpp
+ #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \
+ defined(__IBMCPP__) || defined(__DECCXX)
+ const Parent * const parent = 0;
+ const char *const member = reinterpret_cast<const char*>(&(parent->*ptr_to_member));
+ return std::ptrdiff_t(member - reinterpret_cast<const char*>(parent));
+ #else
+ //This is the traditional C-front approach: __MWERKS__, __DMC__, __SUNPRO_CC
+ return (*(const std::ptrdiff_t*)(void*)&ptr_to_member) - 1;
+ #endif
+}
+
+template<class Parent, class Member>
+inline Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
+{
+ return (Parent*)((char*)member - offset_from_pointer_to_member(ptr_to_member));
+}
+
+template<class Parent, class Member>
+inline const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
+{
+ return (const Parent*)((const char*)member - offset_from_pointer_to_member(ptr_to_member));
+}
+
+} //namespace detail {
+} //namespace intrusive {
+} //namespace boost {
+
+#ifdef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER
+#undef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER
+#endif
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
diff --git a/boost/intrusive/detail/preprocessor.hpp b/boost/intrusive/detail/preprocessor.hpp
new file mode 100644
index 0000000..de66280
--- /dev/null
+++ b/boost/intrusive/detail/preprocessor.hpp
@@ -0,0 +1,52 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2008-2011. 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/intrusive for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_PREPROCESSOR_HPP
+#define BOOST_INTRUSIVE_DETAIL_PREPROCESSOR_HPP
+
+#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/workaround.hpp>
+
+#include <boost/preprocessor/iteration/local.hpp>
+#include <boost/preprocessor/punctuation/paren_if.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/control/expr_if.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
+#include <boost/preprocessor/repetition/enum_trailing.hpp>
+#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
+#include <boost/preprocessor/repetition/enum_shifted.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/logical/not.hpp>
+#include <boost/preprocessor/arithmetic/sub.hpp>
+#include <boost/preprocessor/arithmetic/add.hpp>
+#include <boost/preprocessor/iteration/iterate.hpp>
+
+#define BOOST_INTRUSIVE_MAX_CONSTRUCTOR_PARAMETERS 10
+
+#define BOOST_INTRUSIVE_PP_IDENTITY(z, n, data) data
+
+#define BOOST_INTRUSIVE_PP_DECLVAL(z, n, data) \
+boost::move_detail::declval< BOOST_PP_CAT(P, n) >() \
+//!
+
+#define BOOST_INTRUSIVE_PP_TEMPLATE_PARAM_VOID_DEFAULT(z, n, data) \
+ BOOST_PP_CAT(class P, n) = void \
+//!
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_DETAIL_PREPROCESSOR_HPP
diff --git a/boost/intrusive/detail/rbtree_node.hpp b/boost/intrusive/detail/rbtree_node.hpp
new file mode 100644
index 0000000..dbe0130
--- /dev/null
+++ b/boost/intrusive/detail/rbtree_node.hpp
@@ -0,0 +1,177 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2009.
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_RBTREE_NODE_HPP
+#define BOOST_INTRUSIVE_RBTREE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/intrusive/rbtree_algorithms.hpp>
+#include <boost/intrusive/pointer_plus_bits.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/////////////////////////////////////////////////////////////////////////////
+// //
+// Generic node_traits for any pointer type //
+// //
+/////////////////////////////////////////////////////////////////////////////
+
+//This is the compact representation: 3 pointers
+template<class VoidPointer>
+struct compact_rbtree_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <compact_rbtree_node<VoidPointer> >::type node_ptr;
+ enum color { red_t, black_t };
+ node_ptr parent_, left_, right_;
+};
+
+//This is the normal representation: 3 pointers + enum
+template<class VoidPointer>
+struct rbtree_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <rbtree_node<VoidPointer> >::type node_ptr;
+
+ enum color { red_t, black_t };
+ node_ptr parent_, left_, right_;
+ color color_;
+};
+
+//This is the default node traits implementation
+//using a node with 3 generic pointers plus an enum
+template<class VoidPointer>
+struct default_rbtree_node_traits_impl
+{
+ typedef rbtree_node<VoidPointer> node;
+
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ typedef typename node::color color;
+
+ static const node_ptr & get_parent(const const_node_ptr & n)
+ { return n->parent_; }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { n->parent_ = p; }
+
+ static const node_ptr & get_left(const const_node_ptr & n)
+ { return n->left_; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->left_ = l; }
+
+ static const node_ptr & get_right(const const_node_ptr & n)
+ { return n->right_; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->right_ = r; }
+
+ static color get_color(const const_node_ptr & n)
+ { return n->color_; }
+
+ static void set_color(const node_ptr & n, color c)
+ { n->color_ = c; }
+
+ static color black()
+ { return node::black_t; }
+
+ static color red()
+ { return node::red_t; }
+};
+
+//This is the compact node traits implementation
+//using a node with 3 generic pointers
+template<class VoidPointer>
+struct compact_rbtree_node_traits_impl
+{
+ typedef compact_rbtree_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ typedef pointer_plus_bits<node_ptr, 1> ptr_bit;
+
+ typedef typename node::color color;
+
+ static node_ptr get_parent(const const_node_ptr & n)
+ { return ptr_bit::get_pointer(n->parent_); }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { ptr_bit::set_pointer(n->parent_, p); }
+
+ static const node_ptr & get_left(const const_node_ptr & n)
+ { return n->left_; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->left_ = l; }
+
+ static const node_ptr & get_right(const const_node_ptr & n)
+ { return n->right_; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->right_ = r; }
+
+ static color get_color(const const_node_ptr & n)
+ { return (color)ptr_bit::get_bits(n->parent_); }
+
+ static void set_color(const node_ptr & n, color c)
+ { ptr_bit::set_bits(n->parent_, c != 0); }
+
+ static color black()
+ { return node::black_t; }
+
+ static color red()
+ { return node::red_t; }
+};
+
+//Dispatches the implementation based on the boolean
+template<class VoidPointer, bool Compact>
+struct rbtree_node_traits_dispatch
+ : public default_rbtree_node_traits_impl<VoidPointer>
+{};
+
+template<class VoidPointer>
+struct rbtree_node_traits_dispatch<VoidPointer, true>
+ : public compact_rbtree_node_traits_impl<VoidPointer>
+{};
+
+//Inherit from the detail::link_dispatch depending on the embedding capabilities
+template<class VoidPointer, bool OptimizeSize = false>
+struct rbtree_node_traits
+ : public rbtree_node_traits_dispatch
+ < VoidPointer
+ , OptimizeSize &&
+ (max_pointer_plus_bits
+ < VoidPointer
+ , detail::alignment_of<compact_rbtree_node<VoidPointer> >::value
+ >::value >= 1)
+ >
+{};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_RBTREE_NODE_HPP
diff --git a/boost/intrusive/detail/slist_node.hpp b/boost/intrusive/detail/slist_node.hpp
new file mode 100644
index 0000000..5b96c09
--- /dev/null
+++ b/boost/intrusive/detail/slist_node.hpp
@@ -0,0 +1,163 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_SLIST_NODE_HPP
+#define BOOST_INTRUSIVE_SLIST_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+
+namespace boost {
+namespace intrusive {
+
+template<class VoidPointer>
+struct slist_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<slist_node>::type node_ptr;
+ node_ptr next_;
+};
+
+// slist_node_traits can be used with circular_slist_algorithms and supplies
+// a slist_node holding the pointers needed for a singly-linked list
+// it is used by slist_base_hook and slist_member_hook
+template<class VoidPointer>
+struct slist_node_traits
+{
+ typedef slist_node<VoidPointer> node;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
+
+ static const node_ptr &get_next(const const_node_ptr & n)
+ { return n->next_; }
+
+ static void set_next(const node_ptr & n, const node_ptr & next)
+ { n->next_ = next; }
+};
+
+// slist_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class slist_iterator
+ : public std::iterator
+ < std::forward_iterator_tag
+ , typename Container::value_type
+ , typename Container::difference_type
+ , typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type
+ , typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename pointer_traits
+ <node_ptr>::template rebind_pointer <void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ typedef typename Container::value_type value_type;
+ typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer;
+ typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference;
+
+ slist_iterator()
+ : members_ (node_ptr(), 0)
+ {}
+
+ explicit slist_iterator(const node_ptr & node, const Container *cont_ptr)
+ : members_ (node, cont_ptr)
+ {}
+
+ slist_iterator(slist_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ slist_iterator &operator=(const node_ptr &node)
+ { members_.nodeptr_ = node; return static_cast<slist_iterator&>(*this); }
+
+ public:
+ slist_iterator& operator++()
+ {
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return static_cast<slist_iterator&> (*this);
+ }
+
+ slist_iterator operator++(int)
+ {
+ slist_iterator result (*this);
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return result;
+ }
+
+ friend bool operator== (const slist_iterator& l, const slist_iterator& r)
+ { return l.pointed_node() == r.pointed_node(); }
+
+ friend bool operator!= (const slist_iterator& l, const slist_iterator& r)
+ { return !(l == r); }
+
+ reference operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return this->get_real_value_traits()->to_value_ptr(members_.nodeptr_); }
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr)
+ return static_cast<const Container*>(members_.get_ptr());
+ else
+ return 0;
+ }
+
+ slist_iterator<Container, false> unconst() const
+ { return slist_iterator<Container, false>(this->pointed_node(), this->get_container()); }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ private:
+ struct members
+ : public detail::select_constptr
+ <void_pointer, store_container_ptr>::type
+ {
+ typedef typename detail::select_constptr
+ <void_pointer, store_container_ptr>::type Base;
+
+ members(const node_ptr &n_ptr, const void *cont)
+ : Base(cont), nodeptr_(n_ptr)
+ {}
+
+ node_ptr nodeptr_;
+ } members_;
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SLIST_NODE_HPP
diff --git a/boost/intrusive/detail/transform_iterator.hpp b/boost/intrusive/detail/transform_iterator.hpp
new file mode 100644
index 0000000..15ef3ab
--- /dev/null
+++ b/boost/intrusive/detail/transform_iterator.hpp
@@ -0,0 +1,173 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP
+#define BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template <class PseudoReference>
+struct operator_arrow_proxy
+{
+ operator_arrow_proxy(const PseudoReference &px)
+ : m_value(px)
+ {}
+
+ PseudoReference* operator->() const { return &m_value; }
+ // This function is needed for MWCW and BCC, which won't call operator->
+ // again automatically per 13.3.1.2 para 8
+// operator T*() const { return &m_value; }
+ mutable PseudoReference m_value;
+};
+
+template <class T>
+struct operator_arrow_proxy<T&>
+{
+ operator_arrow_proxy(T &px)
+ : m_value(px)
+ {}
+
+ T* operator->() const { return &m_value; }
+ // This function is needed for MWCW and BCC, which won't call operator->
+ // again automatically per 13.3.1.2 para 8
+// operator T*() const { return &m_value; }
+ T &m_value;
+};
+
+template <class Iterator, class UnaryFunction>
+class transform_iterator
+ : public std::iterator
+ < typename Iterator::iterator_category
+ , typename detail::remove_reference<typename UnaryFunction::result_type>::type
+ , typename Iterator::difference_type
+ , operator_arrow_proxy<typename UnaryFunction::result_type>
+ , typename UnaryFunction::result_type>
+{
+ public:
+ explicit transform_iterator(const Iterator &it, const UnaryFunction &f = UnaryFunction())
+ : members_(it, f)
+ {}
+
+ explicit transform_iterator()
+ : members_()
+ {}
+
+ Iterator get_it() const
+ { return members_.m_it; }
+
+ //Constructors
+ transform_iterator& operator++()
+ { increment(); return *this; }
+
+ transform_iterator operator++(int)
+ {
+ transform_iterator result (*this);
+ increment();
+ return result;
+ }
+
+ friend bool operator== (const transform_iterator& i, const transform_iterator& i2)
+ { return i.equal(i2); }
+
+ friend bool operator!= (const transform_iterator& i, const transform_iterator& i2)
+ { return !(i == i2); }
+
+/*
+ friend bool operator> (const transform_iterator& i, const transform_iterator& i2)
+ { return i2 < i; }
+
+ friend bool operator<= (const transform_iterator& i, const transform_iterator& i2)
+ { return !(i > i2); }
+
+ friend bool operator>= (const transform_iterator& i, const transform_iterator& i2)
+ { return !(i < i2); }
+*/
+ friend typename Iterator::difference_type operator- (const transform_iterator& i, const transform_iterator& i2)
+ { return i2.distance_to(i); }
+
+ //Arithmetic
+ transform_iterator& operator+=(typename Iterator::difference_type off)
+ { this->advance(off); return *this; }
+
+ transform_iterator operator+(typename Iterator::difference_type off) const
+ {
+ transform_iterator other(*this);
+ other.advance(off);
+ return other;
+ }
+
+ friend transform_iterator operator+(typename Iterator::difference_type off, const transform_iterator& right)
+ { return right + off; }
+
+ transform_iterator& operator-=(typename Iterator::difference_type off)
+ { this->advance(-off); return *this; }
+
+ transform_iterator operator-(typename Iterator::difference_type off) const
+ { return *this + (-off); }
+
+ typename UnaryFunction::result_type operator*() const
+ { return dereference(); }
+
+ operator_arrow_proxy<typename UnaryFunction::result_type>
+ operator->() const
+ { return operator_arrow_proxy<typename UnaryFunction::result_type>(dereference()); }
+
+ private:
+ struct members
+ : UnaryFunction
+ {
+ members(const Iterator &it, const UnaryFunction &f)
+ : UnaryFunction(f), m_it(it)
+ {}
+
+ members()
+ {}
+
+ Iterator m_it;
+ } members_;
+
+
+ void increment()
+ { ++members_.m_it; }
+
+ void decrement()
+ { --members_.m_it; }
+
+ bool equal(const transform_iterator &other) const
+ { return members_.m_it == other.members_.m_it; }
+
+ bool less(const transform_iterator &other) const
+ { return other.members_.m_it < members_.m_it; }
+
+ typename UnaryFunction::result_type dereference() const
+ { return members_(*members_.m_it); }
+
+ void advance(typename Iterator::difference_type n)
+ { std::advance(members_.m_it, n); }
+
+ typename Iterator::difference_type distance_to(const transform_iterator &other)const
+ { return std::distance(other.members_.m_it, members_.m_it); }
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP
diff --git a/boost/intrusive/detail/tree_algorithms.hpp b/boost/intrusive/detail/tree_algorithms.hpp
new file mode 100644
index 0000000..8d31d9d
--- /dev/null
+++ b/boost/intrusive/detail/tree_algorithms.hpp
@@ -0,0 +1,1697 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <cstddef>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+//! This is an implementation of a binary search tree.
+//! A node in the search tree has references to its children and its parent. This
+//! is to allow traversal of the whole tree from a given node making the
+//! implementation of iterator a pointer to a node.
+//! At the top of the tree a node is used specially. This node's parent pointer
+//! is pointing to the root of the tree. Its left pointer points to the
+//! leftmost node in the tree and the right pointer to the rightmost one.
+//! This node is used to represent the end-iterator.
+//!
+//! +---------+
+//! header------------------------------>| |
+//! | |
+//! +----------(left)--------| |--------(right)---------+
+//! | +---------+ |
+//! | | |
+//! | | (parent) |
+//! | | |
+//! | | |
+//! | +---------+ |
+//! root of tree ..|......................> | | |
+//! | | D | |
+//! | | | |
+//! | +-------+---------+-------+ |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | +---------+ +---------+ |
+//! | | | | | |
+//! | | B | | F | |
+//! | | | | | |
+//! | +--+---------+--+ +--+---------+--+ |
+//! | | | | | |
+//! | | | | | |
+//! | | | | | |
+//! | +---+-----+ +-----+---+ +---+-----+ +-----+---+ |
+//! +-->| | | | | | | |<--+
+//! | A | | C | | E | | G |
+//! | | | | | | | |
+//! +---------+ +---------+ +---------+ +---------+
+//!
+
+//! tree_algorithms is configured with a NodeTraits class, which encapsulates the
+//! information about the node to be manipulated. NodeTraits must support the
+//! following interface:
+//!
+//! <b>Typedefs</b>:
+//!
+//! <tt>node</tt>: The type of the node that forms the circular list
+//!
+//! <tt>node_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+template<class NodeTraits>
+class tree_algorithms
+{
+ public:
+ typedef typename NodeTraits::node node;
+ typedef NodeTraits node_traits;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+
+ //! This type is the information that will be filled by insert_unique_check
+ struct insert_commit_data
+ {
+ insert_commit_data()
+ : link_left(false)
+ , node()
+ {}
+ bool link_left;
+ node_ptr node;
+ };
+
+ struct nop_erase_fixup
+ {
+ void operator()(const node_ptr&, const node_ptr&){}
+ };
+
+ /// @cond
+ private:
+ template<class Disposer>
+ struct dispose_subtree_disposer
+ {
+ dispose_subtree_disposer(Disposer &disp, const node_ptr & subtree)
+ : disposer_(&disp), subtree_(subtree)
+ {}
+
+ void release()
+ { disposer_ = 0; }
+
+ ~dispose_subtree_disposer()
+ {
+ if(disposer_){
+ dispose_subtree(subtree_, *disposer_);
+ }
+ }
+ Disposer *disposer_;
+ node_ptr subtree_;
+ };
+
+ static node_ptr uncast(const const_node_ptr & ptr)
+ { return pointer_traits<node_ptr>::const_cast_from(ptr); }
+
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const const_node_ptr & header)
+ { return node_traits::get_left(header); }
+
+ static node_ptr end_node(const const_node_ptr & header)
+ { return uncast(header); }
+
+ //! <b>Requires</b>: 'node' is a node of the tree or an node initialized
+ //! by init(...) or init_node.
+ //!
+ //! <b>Effects</b>: Returns true if the node is initialized by init() or init_node().
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool unique(const const_node_ptr & node)
+ { return !NodeTraits::get_parent(node); }
+
+ static node_ptr get_header(const const_node_ptr & node)
+ {
+ node_ptr h = uncast(node);
+ if(NodeTraits::get_parent(node)){
+ h = NodeTraits::get_parent(node);
+ while(!is_header(h))
+ h = NodeTraits::get_parent(h);
+ }
+ return h;
+ }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(const node_ptr & node1, const node_ptr & node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(get_header(node1)), header2(get_header(node2));
+ swap_nodes(node1, header1, node2, header2);
+ }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees with header header1 and header2.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2)
+ {
+ if(node1 == node2)
+ return;
+
+ //node1 and node2 must not be header nodes
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT((header1 != node1 && header2 != node2));
+ if(header1 != header2){
+ //Update header1 if necessary
+ if(node1 == NodeTraits::get_left(header1)){
+ NodeTraits::set_left(header1, node2);
+ }
+
+ if(node1 == NodeTraits::get_right(header1)){
+ NodeTraits::set_right(header1, node2);
+ }
+
+ if(node1 == NodeTraits::get_parent(header1)){
+ NodeTraits::set_parent(header1, node2);
+ }
+
+ //Update header2 if necessary
+ if(node2 == NodeTraits::get_left(header2)){
+ NodeTraits::set_left(header2, node1);
+ }
+
+ if(node2 == NodeTraits::get_right(header2)){
+ NodeTraits::set_right(header2, node1);
+ }
+
+ if(node2 == NodeTraits::get_parent(header2)){
+ NodeTraits::set_parent(header2, node1);
+ }
+ }
+ else{
+ //If both nodes are from the same tree
+ //Update header if necessary
+ if(node1 == NodeTraits::get_left(header1)){
+ NodeTraits::set_left(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_left(header2)){
+ NodeTraits::set_left(header2, node1);
+ }
+
+ if(node1 == NodeTraits::get_right(header1)){
+ NodeTraits::set_right(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_right(header2)){
+ NodeTraits::set_right(header2, node1);
+ }
+
+ if(node1 == NodeTraits::get_parent(header1)){
+ NodeTraits::set_parent(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_parent(header2)){
+ NodeTraits::set_parent(header2, node1);
+ }
+
+ //Adjust data in nodes to be swapped
+ //so that final link swap works as expected
+ if(node1 == NodeTraits::get_parent(node2)){
+ NodeTraits::set_parent(node2, node2);
+
+ if(node2 == NodeTraits::get_right(node1)){
+ NodeTraits::set_right(node1, node1);
+ }
+ else{
+ NodeTraits::set_left(node1, node1);
+ }
+ }
+ else if(node2 == NodeTraits::get_parent(node1)){
+ NodeTraits::set_parent(node1, node1);
+
+ if(node1 == NodeTraits::get_right(node2)){
+ NodeTraits::set_right(node2, node2);
+ }
+ else{
+ NodeTraits::set_left(node2, node2);
+ }
+ }
+ }
+
+ //Now swap all the links
+ node_ptr temp;
+ //swap left link
+ temp = NodeTraits::get_left(node1);
+ NodeTraits::set_left(node1, NodeTraits::get_left(node2));
+ NodeTraits::set_left(node2, temp);
+ //swap right link
+ temp = NodeTraits::get_right(node1);
+ NodeTraits::set_right(node1, NodeTraits::get_right(node2));
+ NodeTraits::set_right(node2, temp);
+ //swap parent link
+ temp = NodeTraits::get_parent(node1);
+ NodeTraits::set_parent(node1, NodeTraits::get_parent(node2));
+ NodeTraits::set_parent(node2, temp);
+
+ //Now adjust adjacent nodes for newly inserted node 1
+ if((temp = NodeTraits::get_left(node1))){
+ NodeTraits::set_parent(temp, node1);
+ }
+ if((temp = NodeTraits::get_right(node1))){
+ NodeTraits::set_parent(temp, node1);
+ }
+ if((temp = NodeTraits::get_parent(node1)) &&
+ //The header has been already updated so avoid it
+ temp != header2){
+ if(NodeTraits::get_left(temp) == node2){
+ NodeTraits::set_left(temp, node1);
+ }
+ if(NodeTraits::get_right(temp) == node2){
+ NodeTraits::set_right(temp, node1);
+ }
+ }
+ //Now adjust adjacent nodes for newly inserted node 2
+ if((temp = NodeTraits::get_left(node2))){
+ NodeTraits::set_parent(temp, node2);
+ }
+ if((temp = NodeTraits::get_right(node2))){
+ NodeTraits::set_parent(temp, node2);
+ }
+ if((temp = NodeTraits::get_parent(node2)) &&
+ //The header has been already updated so avoid it
+ temp != header1){
+ if(NodeTraits::get_left(temp) == node1){
+ NodeTraits::set_left(temp, node2);
+ }
+ if(NodeTraits::get_right(temp) == node1){
+ NodeTraits::set_right(temp, node2);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+ replace_node(node_to_be_replaced, get_header(node_to_be_replaced), new_node);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+
+ //Update header if necessary
+ if(node_to_be_replaced == NodeTraits::get_left(header)){
+ NodeTraits::set_left(header, new_node);
+ }
+
+ if(node_to_be_replaced == NodeTraits::get_right(header)){
+ NodeTraits::set_right(header, new_node);
+ }
+
+ if(node_to_be_replaced == NodeTraits::get_parent(header)){
+ NodeTraits::set_parent(header, new_node);
+ }
+
+ //Now set data from the original node
+ node_ptr temp;
+ NodeTraits::set_left(new_node, NodeTraits::get_left(node_to_be_replaced));
+ NodeTraits::set_right(new_node, NodeTraits::get_right(node_to_be_replaced));
+ NodeTraits::set_parent(new_node, NodeTraits::get_parent(node_to_be_replaced));
+
+ //Now adjust adjacent nodes for newly inserted node
+ if((temp = NodeTraits::get_left(new_node))){
+ NodeTraits::set_parent(temp, new_node);
+ }
+ if((temp = NodeTraits::get_right(new_node))){
+ NodeTraits::set_parent(temp, new_node);
+ }
+ if((temp = NodeTraits::get_parent(new_node)) &&
+ //The header has been already updated so avoid it
+ temp != header){
+ if(NodeTraits::get_left(temp) == node_to_be_replaced){
+ NodeTraits::set_left(temp, new_node);
+ }
+ if(NodeTraits::get_right(temp) == node_to_be_replaced){
+ NodeTraits::set_right(temp, new_node);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: 'node' is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(const node_ptr & node)
+ {
+ node_ptr p_right(NodeTraits::get_right(node));
+ if(p_right){
+ return minimum(p_right);
+ }
+ else {
+ node_ptr p(node);
+ node_ptr x = NodeTraits::get_parent(p);
+ while(p == NodeTraits::get_right(x)){
+ p = x;
+ x = NodeTraits::get_parent(x);
+ }
+ return NodeTraits::get_right(p) != x ? x : uncast(p);
+ }
+ }
+
+ //! <b>Requires</b>: 'node' is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(const node_ptr & node)
+ {
+ if(is_header(node)){
+ return NodeTraits::get_right(node);
+ //return maximum(NodeTraits::get_parent(node));
+ }
+ else if(NodeTraits::get_left(node)){
+ return maximum(NodeTraits::get_left(node));
+ }
+ else {
+ node_ptr p(node);
+ node_ptr x = NodeTraits::get_parent(p);
+ while(p == NodeTraits::get_left(x)){
+ p = x;
+ x = NodeTraits::get_parent(x);
+ }
+ return x;
+ }
+ }
+
+ //! <b>Requires</b>: 'node' is a node of a tree but not the header.
+ //!
+ //! <b>Effects</b>: Returns the minimum node of the subtree starting at p.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the size of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr minimum (const node_ptr & node)
+ {
+ node_ptr p(node);
+ for(node_ptr p_left = NodeTraits::get_left(p)
+ ;p_left
+ ;p_left = NodeTraits::get_left(p)){
+ p = p_left;
+ }
+ return p;
+ }
+
+ //! <b>Requires</b>: 'node' is a node of a tree but not the header.
+ //!
+ //! <b>Effects</b>: Returns the maximum node of the subtree starting at p.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the size of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr maximum(const node_ptr & node)
+ {
+ node_ptr p(node);
+ for(node_ptr p_right = NodeTraits::get_right(p)
+ ;p_right
+ ;p_right = NodeTraits::get_right(p)){
+ p = p_right;
+ }
+ return p;
+ }
+
+ //! <b>Requires</b>: 'node' must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(const node_ptr & node)
+ {
+ NodeTraits::set_parent(node, node_ptr());
+ NodeTraits::set_left(node, node_ptr());
+ NodeTraits::set_right(node, node_ptr());
+ };
+
+ //! <b>Effects</b>: Returns true if node is in the same state as if called init(node)
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool inited(const const_node_ptr & node)
+ {
+ return !NodeTraits::get_parent(node) &&
+ !NodeTraits::get_left(node) &&
+ !NodeTraits::get_right(node) ;
+ };
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(const node_ptr & header)
+ {
+ NodeTraits::set_parent(header, node_ptr());
+ NodeTraits::set_left(header, header);
+ NodeTraits::set_right(header, header);
+ }
+
+ //! <b>Requires</b>: "disposer" must be an object function
+ //! taking a node_ptr parameter and shouldn't throw.
+ //!
+ //! <b>Effects</b>: Empties the target tree calling
+ //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree
+ //! except the header.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template<class Disposer>
+ static void clear_and_dispose(const node_ptr & header, Disposer disposer)
+ {
+ node_ptr source_root = NodeTraits::get_parent(header);
+ if(!source_root)
+ return;
+ dispose_subtree(source_root, disposer);
+ init_header(header);
+ }
+
+ //! <b>Requires</b>: header is the header of a tree.
+ //!
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree, and
+ //! updates the header link to the new leftmost node.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header)
+ {
+ node_ptr leftmost = NodeTraits::get_left(header);
+ if (leftmost == header)
+ return node_ptr();
+ node_ptr leftmost_parent(NodeTraits::get_parent(leftmost));
+ node_ptr leftmost_right (NodeTraits::get_right(leftmost));
+ bool is_root = leftmost_parent == header;
+
+ if (leftmost_right){
+ NodeTraits::set_parent(leftmost_right, leftmost_parent);
+ NodeTraits::set_left(header, tree_algorithms::minimum(leftmost_right));
+
+ if (is_root)
+ NodeTraits::set_parent(header, leftmost_right);
+ else
+ NodeTraits::set_left(NodeTraits::get_parent(header), leftmost_right);
+ }
+ else if (is_root){
+ NodeTraits::set_parent(header, node_ptr());
+ NodeTraits::set_left(header, header);
+ NodeTraits::set_right(header, header);
+ }
+ else{
+ NodeTraits::set_left(leftmost_parent, node_ptr());
+ NodeTraits::set_left(header, leftmost_parent);
+ }
+ return leftmost;
+ }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const const_node_ptr & subtree)
+ {
+ if(!subtree) return 0;
+ std::size_t count = 0;
+ node_ptr p = minimum(uncast(subtree));
+ bool continue_looping = true;
+ while(continue_looping){
+ ++count;
+ node_ptr p_right(NodeTraits::get_right(p));
+ if(p_right){
+ p = minimum(p_right);
+ }
+ else {
+ for(;;){
+ node_ptr q;
+ if (p == subtree){
+ continue_looping = false;
+ break;
+ }
+ q = p;
+ p = NodeTraits::get_parent(p);
+ if (NodeTraits::get_left(p) == q)
+ break;
+ }
+ }
+ }
+ return count;
+ }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t size(const const_node_ptr & header)
+ {
+ node_ptr beg(begin_node(header));
+ node_ptr end(end_node(header));
+ std::size_t i = 0;
+ for(;beg != end; beg = next_node(beg)) ++i;
+ return i;
+ }
+
+ //! <b>Requires</b>: header1 and header2 must be the header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two trees. After the function header1 will contain
+ //! links to the second tree and header2 will have links to the first tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void swap_tree(const node_ptr & header1, const node_ptr & header2)
+ {
+ if(header1 == header2)
+ return;
+
+ node_ptr tmp;
+
+ //Parent swap
+ tmp = NodeTraits::get_parent(header1);
+ NodeTraits::set_parent(header1, NodeTraits::get_parent(header2));
+ NodeTraits::set_parent(header2, tmp);
+ //Left swap
+ tmp = NodeTraits::get_left(header1);
+ NodeTraits::set_left(header1, NodeTraits::get_left(header2));
+ NodeTraits::set_left(header2, tmp);
+ //Right swap
+ tmp = NodeTraits::get_right(header1);
+ NodeTraits::set_right(header1, NodeTraits::get_right(header2));
+ NodeTraits::set_right(header2, tmp);
+
+ //Now test parent
+ node_ptr h1_parent(NodeTraits::get_parent(header1));
+ if(h1_parent){
+ NodeTraits::set_parent(h1_parent, header1);
+ }
+ else{
+ NodeTraits::set_left(header1, header1);
+ NodeTraits::set_right(header1, header1);
+ }
+
+ node_ptr h2_parent(NodeTraits::get_parent(header2));
+ if(h2_parent){
+ NodeTraits::set_parent(h2_parent, header2);
+ }
+ else{
+ NodeTraits::set_left(header2, header2);
+ NodeTraits::set_right(header2, header2);
+ }
+ }
+
+ static bool is_header(const const_node_ptr & p)
+ {
+ node_ptr p_left (NodeTraits::get_left(p));
+ node_ptr p_right(NodeTraits::get_right(p));
+ if(!NodeTraits::get_parent(p) || //Header condition when empty tree
+ (p_left && p_right && //Header always has leftmost and rightmost
+ (p_left == p_right || //Header condition when only node
+ (NodeTraits::get_parent(p_left) != p ||
+ NodeTraits::get_parent(p_right) != p ))
+ //When tree size > 1 headers can't be leftmost's
+ //and rightmost's parent
+ )){
+ return true;
+ }
+ return false;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to
+ //! "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr end = uncast(header);
+ node_ptr y = lower_bound(header, key, comp);
+ return (y == end || comp(key, y)) ? end : y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing
+ //! all elements that are equivalent to "key" according to "comp" or an
+ //! empty range that indicates the position where those elements would be
+ //! if they there are no equivalent elements.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, node_ptr> equal_range
+ (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else if(comp(key, x)){
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ else{
+ node_ptr xu(x), yu(y);
+ y = x, x = NodeTraits::get_left(x);
+ xu = NodeTraits::get_right(xu);
+
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else {
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ }
+
+ while(xu){
+ if(comp(key, xu)){
+ yu = xu;
+ xu = NodeTraits::get_left(xu);
+ }
+ else {
+ xu = NodeTraits::get_right(xu);
+ }
+ }
+ return std::pair<node_ptr,node_ptr> (y, yu);
+ }
+ }
+ return std::pair<node_ptr,node_ptr> (y, y);
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is
+ //! not less than "key" according to "comp" or "header" if that element does
+ //! not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else {
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ }
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+ while(x){
+ if(comp(key, x)){
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ else {
+ x = NodeTraits::get_right(x);
+ }
+ }
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! "commit_data" must have been obtained from a previous call to
+ //! "insert_unique_check". No objects should have been inserted or erased
+ //! from the set between the "insert_unique_check" that filled "commit_data"
+ //! and the call to "insert_commit".
+ //!
+ //!
+ //! <b>Effects</b>: Inserts new_node in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ static void insert_unique_commit
+ (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data)
+ { return insert_commit(header, new_value, commit_data); }
+
+ static void insert_commit
+ (const node_ptr & header, const node_ptr & new_node, const insert_commit_data &commit_data)
+ {
+ //Check if commit_data has not been initialized by a insert_unique_check call.
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(commit_data.node != node_ptr());
+ node_ptr parent_node(commit_data.node);
+ if(parent_node == header){
+ NodeTraits::set_parent(header, new_node);
+ NodeTraits::set_right(header, new_node);
+ NodeTraits::set_left(header, new_node);
+ }
+ else if(commit_data.link_left){
+ NodeTraits::set_left(parent_node, new_node);
+ if(parent_node == NodeTraits::get_left(header))
+ NodeTraits::set_left(header, new_node);
+ }
+ else{
+ NodeTraits::set_right(parent_node, new_node);
+ if(parent_node == NodeTraits::get_right(header))
+ NodeTraits::set_right(header, new_node);
+ }
+ NodeTraits::set_parent(new_node, parent_node);
+ NodeTraits::set_right(new_node, node_ptr());
+ NodeTraits::set_left(new_node, node_ptr());
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const const_node_ptr & header, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ std::size_t depth = 0;
+ node_ptr h(uncast(header));
+ node_ptr y(h);
+ node_ptr x(NodeTraits::get_parent(y));
+ node_ptr prev = node_ptr();
+
+ //Find the upper bound, cache the previous value and if we should
+ //store it in the left or right node
+ bool left_child = true;
+ while(x){
+ ++depth;
+ y = x;
+ x = (left_child = comp(key, x)) ?
+ NodeTraits::get_left(x) : (prev = y, NodeTraits::get_right(x));
+ }
+
+ if(pdepth) *pdepth = depth;
+
+ //Since we've found the upper bound there is no other value with the same key if:
+ // - There is no previous node
+ // - The previous node is less than the key
+ if(!prev || comp(prev, key)){
+ commit_data.link_left = left_child;
+ commit_data.node = y;
+ return std::pair<node_ptr, bool>(node_ptr(), true);
+ }
+ //If the previous value was not less than key, it means that it's equal
+ //(because we've checked the upper bound)
+ else{
+ return std::pair<node_ptr, bool>(prev, false);
+ }
+ }
+
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const const_node_ptr & header, const node_ptr &hint, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ //hint must be bigger than the key
+ if(hint == header || comp(key, hint)){
+ node_ptr prev(hint);
+ //Previous value should be less than the key
+ if(hint == begin_node(header)|| comp((prev = prev_node(hint)), key)){
+ commit_data.link_left = unique(header) || !NodeTraits::get_left(hint);
+ commit_data.node = commit_data.link_left ? hint : prev;
+ if(pdepth){
+ *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1;
+ }
+ return std::pair<node_ptr, bool>(node_ptr(), true);
+ }
+ }
+ //Hint was wrong, use hintless insertion
+ return insert_unique_check(header, key, comp, commit_data, pdepth);
+ }
+
+ template<class NodePtrCompare>
+ static void insert_equal_check
+ (const node_ptr &header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp
+ , insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ if(hint == header || !comp(hint, new_node)){
+ node_ptr prev(hint);
+ if(hint == NodeTraits::get_left(header) ||
+ !comp(new_node, (prev = prev_node(hint)))){
+ bool link_left = unique(header) || !NodeTraits::get_left(hint);
+ commit_data.link_left = link_left;
+ commit_data.node = link_left ? hint : prev;
+ if(pdepth){
+ *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1;
+ }
+ }
+ else{
+ insert_equal_upper_bound_check(header, new_node, comp, commit_data, pdepth);
+ }
+ }
+ else{
+ insert_equal_lower_bound_check(header, new_node, comp, commit_data, pdepth);
+ }
+ }
+
+ template<class NodePtrCompare>
+ static void insert_equal_upper_bound_check
+ (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0)
+ { insert_equal_check_impl(true, h, new_node, comp, commit_data, pdepth); }
+
+ template<class NodePtrCompare>
+ static void insert_equal_lower_bound_check
+ (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0)
+ { insert_equal_check_impl(false, h, new_node, comp, commit_data, pdepth); }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal
+ (const node_ptr & h, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_equal_check(h, hint, new_node, comp, commit_data, pdepth);
+ insert_commit(h, new_node, commit_data);
+ return new_node;
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_upper_bound
+ (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_equal_upper_bound_check(h, new_node, comp, commit_data, pdepth);
+ insert_commit(h, new_node, commit_data);
+ return new_node;
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_lower_bound
+ (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_equal_lower_bound_check(h, new_node, comp, commit_data, pdepth);
+ insert_commit(h, new_node, commit_data);
+ return new_node;
+ }
+
+ static node_ptr insert_before
+ (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_before_check(header, pos, commit_data, pdepth);
+ insert_commit(header, new_node, commit_data);
+ return new_node;
+ }
+
+ static void insert_before_check
+ (const node_ptr &header, const node_ptr & pos
+ , insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ node_ptr prev(pos);
+ if(pos != NodeTraits::get_left(header))
+ prev = prev_node(pos);
+ bool link_left = unique(header) || !NodeTraits::get_left(pos);
+ commit_data.link_left = link_left;
+ commit_data.node = link_left ? pos : prev;
+ if(pdepth){
+ *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1;
+ }
+ }
+
+ static void push_back
+ (const node_ptr & header, const node_ptr & new_node, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ push_back_check(header, commit_data, pdepth);
+ insert_commit(header, new_node, commit_data);
+ }
+
+ static void push_back_check
+ (const node_ptr & header, insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ node_ptr prev(NodeTraits::get_right(header));
+ if(pdepth){
+ *pdepth = prev == header ? 0 : depth(prev) + 1;
+ }
+ commit_data.link_left = false;
+ commit_data.node = prev;
+ }
+
+ static void push_front
+ (const node_ptr & header, const node_ptr & new_node, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ push_front_check(header, commit_data, pdepth);
+ insert_commit(header, new_node, commit_data);
+ }
+
+ static void push_front_check
+ (const node_ptr & header, insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ node_ptr pos(NodeTraits::get_left(header));
+ if(pdepth){
+ *pdepth = pos == header ? 0 : depth(pos) + 1;
+ }
+ commit_data.link_left = true;
+ commit_data.node = pos;
+ }
+
+ //! <b>Requires</b>: 'node' can't be a header node.
+ //!
+ //! <b>Effects</b>: Calculates the depth of a node: the depth of a
+ //! node is the length (number of edges) of the path from the root
+ //! to that node. (The root node is at depth 0.)
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of nodes in the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t depth(const const_node_ptr & node)
+ {
+ const_node_ptr p(node);
+ std::size_t depth = 0;
+ node_ptr p_parent;
+ while(p != NodeTraits::get_parent(p_parent = NodeTraits::get_parent(p))){
+ ++depth;
+ p = p_parent;
+ }
+ return depth;
+ }
+
+ //! <b>Requires</b>: "cloner" must be a function
+ //! object taking a node_ptr and returning a new cloned node of it. "disposer" must
+ //! take a node_ptr and shouldn't throw.
+ //!
+ //! <b>Effects</b>: First empties target tree calling
+ //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree
+ //! except the header.
+ //!
+ //! Then, duplicates the entire tree pointed by "source_header" cloning each
+ //! source node with <tt>node_ptr Cloner::operator()(const node_ptr &)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(const node_ptr &)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer)
+ {
+ if(!unique(target_header)){
+ clear_and_dispose(target_header, disposer);
+ }
+
+ node_ptr leftmost, rightmost;
+ node_ptr new_root = clone_subtree
+ (source_header, target_header, cloner, disposer, leftmost, rightmost);
+
+ //Now update header node
+ NodeTraits::set_parent(target_header, new_root);
+ NodeTraits::set_left (target_header, leftmost);
+ NodeTraits::set_right (target_header, rightmost);
+ }
+
+ template <class Cloner, class Disposer>
+ static node_ptr clone_subtree
+ (const const_node_ptr &source_parent, const node_ptr &target_parent
+ , Cloner cloner, Disposer disposer
+ , node_ptr &leftmost_out, node_ptr &rightmost_out
+ )
+ {
+ node_ptr target_sub_root = target_parent;
+ node_ptr source_root = NodeTraits::get_parent(source_parent);
+ if(!source_root){
+ leftmost_out = rightmost_out = source_root;
+ }
+ else{
+ //We'll calculate leftmost and rightmost nodes while iterating
+ node_ptr current = source_root;
+ node_ptr insertion_point = target_sub_root = cloner(current);
+
+ //We'll calculate leftmost and rightmost nodes while iterating
+ node_ptr leftmost = target_sub_root;
+ node_ptr rightmost = target_sub_root;
+
+ //First set the subroot
+ NodeTraits::set_left(target_sub_root, node_ptr());
+ NodeTraits::set_right(target_sub_root, node_ptr());
+ NodeTraits::set_parent(target_sub_root, target_parent);
+
+ dispose_subtree_disposer<Disposer> rollback(disposer, target_sub_root);
+ while(true) {
+ //First clone left nodes
+ if( NodeTraits::get_left(current) &&
+ !NodeTraits::get_left(insertion_point)) {
+ current = NodeTraits::get_left(current);
+ node_ptr temp = insertion_point;
+ //Clone and mark as leaf
+ insertion_point = cloner(current);
+ NodeTraits::set_left (insertion_point, node_ptr());
+ NodeTraits::set_right (insertion_point, node_ptr());
+ //Insert left
+ NodeTraits::set_parent(insertion_point, temp);
+ NodeTraits::set_left (temp, insertion_point);
+ //Update leftmost
+ if(rightmost == target_sub_root)
+ leftmost = insertion_point;
+ }
+ //Then clone right nodes
+ else if( NodeTraits::get_right(current) &&
+ !NodeTraits::get_right(insertion_point)){
+ current = NodeTraits::get_right(current);
+ node_ptr temp = insertion_point;
+ //Clone and mark as leaf
+ insertion_point = cloner(current);
+ NodeTraits::set_left (insertion_point, node_ptr());
+ NodeTraits::set_right (insertion_point, node_ptr());
+ //Insert right
+ NodeTraits::set_parent(insertion_point, temp);
+ NodeTraits::set_right (temp, insertion_point);
+ //Update rightmost
+ rightmost = insertion_point;
+ }
+ //If not, go up
+ else if(current == source_root){
+ break;
+ }
+ else{
+ //Branch completed, go up searching more nodes to clone
+ current = NodeTraits::get_parent(current);
+ insertion_point = NodeTraits::get_parent(insertion_point);
+ }
+ }
+ rollback.release();
+ leftmost_out = leftmost;
+ rightmost_out = rightmost;
+ }
+ return target_sub_root;
+ }
+
+ template<class Disposer>
+ static void dispose_subtree(const node_ptr & node, Disposer disposer)
+ {
+ node_ptr save;
+ node_ptr x(node);
+ while (x){
+ save = NodeTraits::get_left(x);
+ if (save) {
+ // Right rotation
+ NodeTraits::set_left(x, NodeTraits::get_right(save));
+ NodeTraits::set_right(save, x);
+ }
+ else {
+ save = NodeTraits::get_right(x);
+ init(x);
+ disposer(x);
+ }
+ x = save;
+ }
+ }
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is a left child.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_left_child(const node_ptr & p)
+ { return NodeTraits::get_left(NodeTraits::get_parent(p)) == p; }
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is a right child.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_right_child(const node_ptr & p)
+ { return NodeTraits::get_right(NodeTraits::get_parent(p)) == p; }
+
+ //Fix header and own's parent data when replacing x with own, providing own's old data with parent
+ static void replace_own_impl(const node_ptr & own, const node_ptr & x, const node_ptr & header, const node_ptr & own_parent, bool own_was_left)
+ {
+ if(NodeTraits::get_parent(header) == own)
+ NodeTraits::set_parent(header, x);
+ else if(own_was_left)
+ NodeTraits::set_left(own_parent, x);
+ else
+ NodeTraits::set_right(own_parent, x);
+ }
+
+ //Fix header and own's parent data when replacing x with own, supposing own
+ //links with its parent are still ok
+ static void replace_own(const node_ptr & own, const node_ptr & x, const node_ptr & header)
+ {
+ node_ptr own_parent(NodeTraits::get_parent(own));
+ bool own_is_left(NodeTraits::get_left(own_parent) == own);
+ replace_own_impl(own, x, header, own_parent, own_is_left);
+ }
+
+ // rotate parent p to left (no header and p's parent fixup)
+ static node_ptr rotate_left(const node_ptr & p)
+ {
+ node_ptr x(NodeTraits::get_right(p));
+ node_ptr x_left(NodeTraits::get_left(x));
+ NodeTraits::set_right(p, x_left);
+ if(x_left){
+ NodeTraits::set_parent(x_left, p);
+ }
+ NodeTraits::set_left(x, p);
+ NodeTraits::set_parent(p, x);
+ return x;
+ }
+
+ // rotate parent p to left (with header and p's parent fixup)
+ static void rotate_left(const node_ptr & p, const node_ptr & header)
+ {
+ bool p_was_left(is_left_child(p));
+ node_ptr p_old_parent(NodeTraits::get_parent(p));
+ node_ptr x(rotate_left(p));
+ NodeTraits::set_parent(x, p_old_parent);
+ replace_own_impl(p, x, header, p_old_parent, p_was_left);
+ }
+
+ // rotate parent p to right (no header and p's parent fixup)
+ static node_ptr rotate_right(const node_ptr & p)
+ {
+ node_ptr x(NodeTraits::get_left(p));
+ node_ptr x_right(NodeTraits::get_right(x));
+ NodeTraits::set_left(p, x_right);
+ if(x_right){
+ NodeTraits::set_parent(x_right, p);
+ }
+ NodeTraits::set_right(x, p);
+ NodeTraits::set_parent(p, x);
+ return x;
+ }
+
+ // rotate parent p to right (with header and p's parent fixup)
+ static void rotate_right(const node_ptr & p, const node_ptr & header)
+ {
+ bool p_was_left(is_left_child(p));
+ node_ptr p_old_parent(NodeTraits::get_parent(p));
+ node_ptr x(rotate_right(p));
+ NodeTraits::set_parent(x, p_old_parent);
+ replace_own_impl(p, x, header, p_old_parent, p_was_left);
+ }
+
+ static void erase(const node_ptr & header, const node_ptr & z)
+ {
+ data_for_rebalance ignored;
+ erase_impl(header, z, ignored);
+ }
+
+ struct data_for_rebalance
+ {
+ node_ptr x;
+ node_ptr x_parent;
+ node_ptr y;
+ };
+
+ template<class F>
+ static void erase(const node_ptr & header, const node_ptr & z, F z_and_successor_fixup, data_for_rebalance &info)
+ {
+ erase_impl(header, z, info);
+ if(info.y != z){
+ z_and_successor_fixup(z, info.y);
+ }
+ }
+
+ static void unlink(const node_ptr & node)
+ {
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
+ while(!is_header(x))
+ x = NodeTraits::get_parent(x);
+ erase(x, node);
+ }
+ }
+
+ static void tree_to_vine(const node_ptr & header)
+ { subtree_to_vine(NodeTraits::get_parent(header)); }
+
+ static void vine_to_tree(const node_ptr & header, std::size_t count)
+ { vine_to_subtree(NodeTraits::get_parent(header), count); }
+
+ static void rebalance(const node_ptr & header)
+ {
+ //Taken from:
+ //"Tree rebalancing in optimal time and space"
+ //Quentin F. Stout and Bette L. Warren
+ std::size_t len = 0;
+ subtree_to_vine(NodeTraits::get_parent(header), &len);
+ vine_to_subtree(NodeTraits::get_parent(header), len);
+ }
+
+ static node_ptr rebalance_subtree(const node_ptr & old_root)
+ {
+ std::size_t len = 0;
+ node_ptr new_root = subtree_to_vine(old_root, &len);
+ return vine_to_subtree(new_root, len);
+ }
+
+ static node_ptr subtree_to_vine(const node_ptr & old_root, std::size_t *plen = 0)
+ {
+ std::size_t len;
+ len = 0;
+ if(!old_root) return node_ptr();
+
+ //To avoid irregularities in the algorithm (old_root can be a
+ //left or right child or even the root of the tree) just put the
+ //root as the right child of its parent. Before doing this backup
+ //information to restore the original relationship after
+ //the algorithm is applied.
+ node_ptr super_root = NodeTraits::get_parent(old_root);
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root);
+
+ //Get info
+ node_ptr super_root_right_backup = NodeTraits::get_right(super_root);
+ bool super_root_is_header = is_header(super_root);
+ bool old_root_is_right = is_right_child(old_root);
+
+ node_ptr x(old_root);
+ node_ptr new_root(x);
+ node_ptr save;
+ bool moved_to_right = false;
+ for( ; x; x = save){
+ save = NodeTraits::get_left(x);
+ if(save){
+ // Right rotation
+ node_ptr save_right = NodeTraits::get_right(save);
+ node_ptr x_parent = NodeTraits::get_parent(x);
+ NodeTraits::set_parent(save, x_parent);
+ NodeTraits::set_right (x_parent, save);
+ NodeTraits::set_parent(x, save);
+ NodeTraits::set_right (save, x);
+ NodeTraits::set_left(x, save_right);
+ if(save_right)
+ NodeTraits::set_parent(save_right, x);
+ if(!moved_to_right)
+ new_root = save;
+ }
+ else{
+ moved_to_right = true;
+ save = NodeTraits::get_right(x);
+ ++len;
+ }
+ }
+
+ if(super_root_is_header){
+ NodeTraits::set_right(super_root, super_root_right_backup);
+ NodeTraits::set_parent(super_root, new_root);
+ }
+ else if(old_root_is_right){
+ NodeTraits::set_right(super_root, new_root);
+ }
+ else{
+ NodeTraits::set_right(super_root, super_root_right_backup);
+ NodeTraits::set_left(super_root, new_root);
+ }
+ if(plen) *plen = len;
+ return new_root;
+ }
+
+ static node_ptr vine_to_subtree(const node_ptr & old_root, std::size_t count)
+ {
+ std::size_t leaf_nodes = count + 1 - ((std::size_t) 1 << floor_log2 (count + 1));
+ std::size_t vine_nodes = count - leaf_nodes;
+
+ node_ptr new_root = compress_subtree(old_root, leaf_nodes);
+ while(vine_nodes > 1){
+ vine_nodes /= 2;
+ new_root = compress_subtree(new_root, vine_nodes);
+ }
+ return new_root;
+ }
+
+ static node_ptr compress_subtree(const node_ptr & old_root, std::size_t count)
+ {
+ if(!old_root) return old_root;
+
+ //To avoid irregularities in the algorithm (old_root can be
+ //left or right child or even the root of the tree) just put the
+ //root as the right child of its parent. First obtain
+ //information to restore the original relationship after
+ //the algorithm is applied.
+ node_ptr super_root = NodeTraits::get_parent(old_root);
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root);
+
+ //Get info
+ node_ptr super_root_right_backup = NodeTraits::get_right(super_root);
+ bool super_root_is_header = is_header(super_root);
+ bool old_root_is_right = is_right_child(old_root);
+
+ //Put old_root as right child
+ NodeTraits::set_right(super_root, old_root);
+
+ //Start the compression algorithm
+ node_ptr even_parent = super_root;
+ node_ptr new_root = old_root;
+
+ while(count--){
+ node_ptr even = NodeTraits::get_right(even_parent);
+ node_ptr odd = NodeTraits::get_right(even);
+
+ if(new_root == old_root)
+ new_root = odd;
+
+ node_ptr even_right = NodeTraits::get_left(odd);
+ NodeTraits::set_right(even, even_right);
+ if (even_right)
+ NodeTraits::set_parent(even_right, even);
+
+ NodeTraits::set_right(even_parent, odd);
+ NodeTraits::set_parent(odd, even_parent);
+ NodeTraits::set_left(odd, even);
+ NodeTraits::set_parent(even, odd);
+ even_parent = odd;
+ }
+
+ if(super_root_is_header){
+ NodeTraits::set_parent(super_root, new_root);
+ NodeTraits::set_right(super_root, super_root_right_backup);
+ }
+ else if(old_root_is_right){
+ NodeTraits::set_right(super_root, new_root);
+ }
+ else{
+ NodeTraits::set_left(super_root, new_root);
+ NodeTraits::set_right(super_root, super_root_right_backup);
+ }
+ return new_root;
+ }
+
+ //! <b>Requires</b>: "n" must be a node inserted in a tree.
+ //!
+ //! <b>Effects</b>: Returns a pointer to the header node of the tree.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr get_root(const node_ptr & node)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT((!inited(node)));
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
+ while(!is_header(x)){
+ x = NodeTraits::get_parent(x);
+ }
+ return x;
+ }
+ else{
+ return node;
+ }
+ }
+
+ private:
+ template<class NodePtrCompare>
+ static void insert_equal_check_impl
+ (bool upper, const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0)
+ {
+ std::size_t depth = 0;
+ node_ptr y(h);
+ node_ptr x(NodeTraits::get_parent(y));
+ bool link_left;
+
+ if(upper){
+ while(x){
+ ++depth;
+ y = x;
+ x = comp(new_node, x) ?
+ NodeTraits::get_left(x) : NodeTraits::get_right(x);
+ }
+ link_left = (y == h) || comp(new_node, y);
+ }
+ else{
+ while(x){
+ ++depth;
+ y = x;
+ x = !comp(x, new_node) ?
+ NodeTraits::get_left(x) : NodeTraits::get_right(x);
+ }
+ link_left = (y == h) || !comp(y, new_node);
+ }
+
+ commit_data.link_left = link_left;
+ commit_data.node = y;
+ if(pdepth) *pdepth = depth;
+ }
+
+ static void erase_impl(const node_ptr & header, const node_ptr & z, data_for_rebalance &info)
+ {
+ node_ptr y(z);
+ node_ptr x;
+ node_ptr x_parent = node_ptr();
+ node_ptr z_left(NodeTraits::get_left(z));
+ node_ptr z_right(NodeTraits::get_right(z));
+ if(!z_left){
+ x = z_right; // x might be null.
+ }
+ else if(!z_right){ // z has exactly one non-null child. y == z.
+ x = z_left; // x is not null.
+ }
+ else{
+ // find z's successor
+ y = tree_algorithms::minimum (z_right);
+ x = NodeTraits::get_right(y); // x might be null.
+ }
+
+ if(y != z){
+ // relink y in place of z. y is z's successor
+ NodeTraits::set_parent(NodeTraits::get_left(z), y);
+ NodeTraits::set_left(y, NodeTraits::get_left(z));
+ if(y != NodeTraits::get_right(z)){
+ x_parent = NodeTraits::get_parent(y);
+ if(x)
+ NodeTraits::set_parent(x, x_parent);
+ NodeTraits::set_left(x_parent, x); // y must be a child of left_
+ NodeTraits::set_right(y, NodeTraits::get_right(z));
+ NodeTraits::set_parent(NodeTraits::get_right(z), y);
+ }
+ else
+ x_parent = y;
+ tree_algorithms::replace_own (z, y, header);
+ NodeTraits::set_parent(y, NodeTraits::get_parent(z));
+ }
+ else { // y == z --> z has only one child, or none
+ x_parent = NodeTraits::get_parent(z);
+ if(x)
+ NodeTraits::set_parent(x, x_parent);
+ tree_algorithms::replace_own (z, x, header);
+ if(NodeTraits::get_left(header) == z){
+ NodeTraits::set_left(header, !NodeTraits::get_right(z) ? // z->get_left() must be null also
+ NodeTraits::get_parent(z) : // makes leftmost == header if z == root
+ tree_algorithms::minimum (x));
+ }
+ if(NodeTraits::get_right(header) == z){
+ NodeTraits::set_right(header, !NodeTraits::get_left(z) ? // z->get_right() must be null also
+ NodeTraits::get_parent(z) : // makes rightmost == header if z == root
+ tree_algorithms::maximum(x));
+ }
+ }
+
+ info.x = x;
+ info.x_parent = x_parent;
+ info.y = y;
+ }
+};
+
+} //namespace detail {
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
diff --git a/boost/intrusive/detail/tree_node.hpp b/boost/intrusive/detail/tree_node.hpp
new file mode 100644
index 0000000..ccbe70c
--- /dev/null
+++ b/boost/intrusive/detail/tree_node.hpp
@@ -0,0 +1,190 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_TREE_NODE_HPP
+#define BOOST_INTRUSIVE_TREE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+template<class VoidPointer>
+struct tree_node
+{
+ typedef typename pointer_traits
+ <VoidPointer>::template rebind_pointer
+ <tree_node<VoidPointer> >::type node_ptr;
+
+ node_ptr parent_, left_, right_;
+};
+
+template<class VoidPointer>
+struct tree_node_traits
+{
+ typedef tree_node<VoidPointer> node;
+
+ typedef typename pointer_traits<VoidPointer>::template
+ rebind_pointer<node>::type node_ptr;
+ typedef typename pointer_traits<VoidPointer>::template
+ rebind_pointer<const node>::type const_node_ptr;
+
+ static const node_ptr & get_parent(const const_node_ptr & n)
+ { return n->parent_; }
+
+ static void set_parent(const node_ptr & n, const node_ptr & p)
+ { n->parent_ = p; }
+
+ static const node_ptr & get_left(const const_node_ptr & n)
+ { return n->left_; }
+
+ static void set_left(const node_ptr & n, const node_ptr & l)
+ { n->left_ = l; }
+
+ static const node_ptr & get_right(const const_node_ptr & n)
+ { return n->right_; }
+
+ static void set_right(const node_ptr & n, const node_ptr & r)
+ { n->right_ = r; }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// //
+// Implementation of the tree iterator //
+// //
+/////////////////////////////////////////////////////////////////////////////
+
+// tree_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class tree_iterator
+ : public std::iterator
+ < std::bidirectional_iterator_tag
+ , typename Container::value_type
+ , typename Container::difference_type
+ , typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type
+ , typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::node_algorithms node_algorithms;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename pointer_traits<node_ptr>::template
+ rebind_pointer<void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ typedef typename Container::value_type value_type;
+ typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer;
+ typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference;
+
+
+ tree_iterator()
+ : members_ (node_ptr(), (const void *)0)
+ {}
+
+ explicit tree_iterator(const node_ptr & nodeptr, const Container *cont_ptr)
+ : members_ (nodeptr, cont_ptr)
+ {}
+
+ tree_iterator(tree_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ tree_iterator &operator=(const node_ptr &nodeptr)
+ { members_.nodeptr_ = nodeptr; return static_cast<tree_iterator&>(*this); }
+
+ public:
+ tree_iterator& operator++()
+ {
+ members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
+ return static_cast<tree_iterator&> (*this);
+ }
+
+ tree_iterator operator++(int)
+ {
+ tree_iterator result (*this);
+ members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
+ return result;
+ }
+
+ tree_iterator& operator--()
+ {
+ members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
+ return static_cast<tree_iterator&> (*this);
+ }
+
+ tree_iterator operator--(int)
+ {
+ tree_iterator result (*this);
+ members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
+ return result;
+ }
+
+ friend bool operator== (const tree_iterator& l, const tree_iterator& r)
+ { return l.pointed_node() == r.pointed_node(); }
+
+ friend bool operator!= (const tree_iterator& l, const tree_iterator& r)
+ { return !(l == r); }
+
+ reference operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return this->get_real_value_traits()->to_value_ptr(members_.nodeptr_); }
+
+ const Container *get_container() const
+ { return static_cast<const Container*>(members_.get_ptr()); }
+
+ const real_value_traits *get_real_value_traits() const
+ { return &this->get_container()->get_real_value_traits(); }
+
+ tree_iterator end_iterator_from_it() const
+ {
+ return tree_iterator(node_algorithms::get_header(this->pointed_node()), this->get_container());
+ }
+
+ tree_iterator<Container, false> unconst() const
+ { return tree_iterator<Container, false>(this->pointed_node(), this->get_container()); }
+
+ private:
+ struct members
+ : public detail::select_constptr
+ <void_pointer, store_container_ptr>::type
+ {
+ typedef typename detail::select_constptr
+ <void_pointer, store_container_ptr>::type Base;
+
+ members(const node_ptr &n_ptr, const void *cont)
+ : Base(cont), nodeptr_(n_ptr)
+ {}
+
+ node_ptr nodeptr_;
+ } members_;
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TREE_NODE_HPP
diff --git a/boost/intrusive/detail/utilities.hpp b/boost/intrusive/detail/utilities.hpp
new file mode 100644
index 0000000..c041620
--- /dev/null
+++ b/boost/intrusive/detail/utilities.hpp
@@ -0,0 +1,879 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2009
+//
+// 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/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP
+#define BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/intrusive/detail/parent_from_member.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/detail/is_stateful_value_traits.hpp>
+#include <boost/intrusive/pointer_traits.hpp>
+#include <boost/cstdint.hpp>
+#include <cstddef>
+#include <climits>
+#include <iterator>
+#include <boost/cstdint.hpp>
+#include <boost/static_assert.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template <class T>
+struct internal_member_value_traits
+{
+ template <class U> static detail::one test(...);
+ template <class U> static detail::two test(typename U::member_value_traits* = 0);
+ static const bool value = sizeof(test<T>(0)) == sizeof(detail::two);
+};
+
+template <class T>
+struct internal_base_hook_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::boost_intrusive_tags::is_base_hook> test (int);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct internal_base_hook_bool_is_true
+{
+ static const bool value = internal_base_hook_bool<T>::value > sizeof(one)*2;
+};
+
+template <class T>
+struct internal_any_hook_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::is_any_hook> test (int);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct internal_any_hook_bool_is_true
+{
+ static const bool value = internal_any_hook_bool<T>::value > sizeof(one)*2;
+};
+
+
+template <class T>
+struct external_value_traits_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::external_value_traits> test (int);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct external_bucket_traits_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::external_bucket_traits> test (int);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct external_value_traits_is_true
+{
+ static const bool value = external_value_traits_bool<T>::value > sizeof(one)*2;
+};
+
+template<class Node, class Tag, link_mode_type LinkMode, int>
+struct node_holder
+ : public Node
+{};
+
+template <class T>
+inline T* to_raw_pointer(T* p)
+{ return p; }
+
+template <class Pointer>
+inline typename boost::intrusive::pointer_traits<Pointer>::element_type*
+to_raw_pointer(const Pointer &p)
+{ return boost::intrusive::detail::to_raw_pointer(p.operator->()); }
+
+//This functor compares a stored value
+//and the one passed as an argument
+template<class ConstReference>
+class equal_to_value
+{
+ ConstReference t_;
+
+ public:
+ equal_to_value(ConstReference t)
+ : t_(t)
+ {}
+
+ bool operator()(ConstReference t)const
+ { return t_ == t; }
+};
+
+class null_disposer
+{
+ public:
+ template <class Pointer>
+ void operator()(Pointer)
+ {}
+};
+
+template<class NodeAlgorithms>
+class init_disposer
+{
+ typedef typename NodeAlgorithms::node_ptr node_ptr;
+
+ public:
+ void operator()(const node_ptr & p)
+ { NodeAlgorithms::init(p); }
+};
+
+template<bool ConstantSize, class SizeType>
+struct size_holder
+{
+ static const bool constant_time_size = ConstantSize;
+ typedef SizeType size_type;
+
+ SizeType get_size() const
+ { return size_; }
+
+ void set_size(SizeType size)
+ { size_ = size; }
+
+ void decrement()
+ { --size_; }
+
+ void increment()
+ { ++size_; }
+
+ SizeType size_;
+};
+
+template<class SizeType>
+struct size_holder<false, SizeType>
+{
+ static const bool constant_time_size = false;
+ typedef SizeType size_type;
+
+ size_type get_size() const
+ { return 0; }
+
+ void set_size(size_type)
+ {}
+
+ void decrement()
+ {}
+
+ void increment()
+ {}
+};
+
+template<class KeyValueCompare, class Container>
+struct key_nodeptr_comp
+ : private detail::ebo_functor_holder<KeyValueCompare>
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::value_type value_type;
+ typedef typename real_value_traits::node_ptr node_ptr;
+ typedef typename real_value_traits::const_node_ptr const_node_ptr;
+ typedef detail::ebo_functor_holder<KeyValueCompare> base_t;
+ key_nodeptr_comp(KeyValueCompare kcomp, const Container *cont)
+ : base_t(kcomp), cont_(cont)
+ {}
+
+ template<class T>
+ struct is_node_ptr
+ {
+ static const bool value = is_same<T, const_node_ptr>::value || is_same<T, node_ptr>::value;
+ };
+
+ template<class T>
+ const value_type & key_forward
+ (const T &node, typename enable_if_c<is_node_ptr<T>::value>::type * = 0) const
+ { return *cont_->get_real_value_traits().to_value_ptr(node); }
+
+ template<class T>
+ const T & key_forward(const T &key, typename enable_if_c<!is_node_ptr<T>::value>::type* = 0) const
+ { return key; }
+
+
+ template<class KeyType, class KeyType2>
+ bool operator()(const KeyType &key1, const KeyType2 &key2) const
+ { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); }
+
+ const Container *cont_;
+};
+
+template<class F, class Container>
+struct node_cloner
+ : private detail::ebo_functor_holder<F>
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::node_algorithms node_algorithms;
+ typedef typename real_value_traits::value_type value_type;
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::node_traits::node node;
+ typedef typename real_value_traits::node_ptr node_ptr;
+ typedef typename real_value_traits::const_node_ptr const_node_ptr;
+ typedef detail::ebo_functor_holder<F> base_t;
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ node_cloner(F f, const Container *cont)
+ : base_t(f), cont_(cont)
+ {}
+
+ node_ptr operator()(const node_ptr & p)
+ { return this->operator()(*p); }
+
+ node_ptr operator()(const node &to_clone)
+ {
+ const value_type &v =
+ *cont_->get_real_value_traits().to_value_ptr
+ (pointer_traits<const_node_ptr>::pointer_to(to_clone));
+ node_ptr n = cont_->get_real_value_traits().to_node_ptr(*base_t::get()(v));
+ //Cloned node must be in default mode if the linking mode requires it
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n));
+ return n;
+ }
+
+ const Container *cont_;
+};
+
+template<class F, class Container>
+struct node_disposer
+ : private detail::ebo_functor_holder<F>
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_ptr node_ptr;
+ typedef detail::ebo_functor_holder<F> base_t;
+ typedef typename Container::node_algorithms node_algorithms;
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ node_disposer(F f, const Container *cont)
+ : base_t(f), cont_(cont)
+ {}
+
+ void operator()(const node_ptr & p)
+ {
+ if(safemode_or_autounlink)
+ node_algorithms::init(p);
+ base_t::get()(cont_->get_real_value_traits().to_value_ptr(p));
+ }
+ const Container *cont_;
+};
+
+struct dummy_constptr
+{
+ dummy_constptr(const void *)
+ {}
+
+ const void *get_ptr() const
+ { return 0; }
+};
+
+template<class VoidPointer>
+struct constptr
+{
+ typedef typename boost::intrusive::pointer_traits<VoidPointer>::
+ template rebind_pointer<const void>::type ConstVoidPtr;
+
+ constptr(const void *ptr)
+ : const_void_ptr_(ptr)
+ {}
+
+ const void *get_ptr() const
+ { return boost::intrusive::detail::to_raw_pointer(const_void_ptr_); }
+
+ ConstVoidPtr const_void_ptr_;
+};
+
+template <class VoidPointer, bool store_ptr>
+struct select_constptr
+{
+ typedef typename detail::if_c
+ < store_ptr
+ , constptr<VoidPointer>
+ , dummy_constptr
+ >::type type;
+};
+
+template<class T, bool Add>
+struct add_const_if_c
+{
+ typedef typename detail::if_c
+ < Add
+ , typename detail::add_const<T>::type
+ , T
+ >::type type;
+};
+
+template <link_mode_type LinkMode>
+struct link_dispatch
+{};
+
+template<class Hook>
+void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>)
+{ //If this assertion raises, you might have destroyed an object
+ //while it was still inserted in a container that is alive.
+ //If so, remove the object from the container before destroying it.
+ (void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked());
+}
+
+template<class Hook>
+void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>)
+{ hook.unlink(); }
+
+template<class Hook>
+void destructor_impl(Hook &, detail::link_dispatch<normal_link>)
+{}
+
+template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, int HookType>
+struct base_hook_traits
+{
+ public:
+ typedef detail::node_holder
+ <typename NodeTraits::node, Tag, LinkMode, HookType> node_holder;
+ typedef typename NodeTraits::node node;
+ typedef NodeTraits node_traits;
+ typedef T value_type;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<T>::type pointer;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<const T>::type const_pointer;
+ //typedef typename pointer_traits<pointer>::reference reference;
+ //typedef typename pointer_traits<const_pointer>::reference const_reference;
+ typedef T & reference;
+ typedef const T & const_reference;
+ typedef node_holder & node_holder_reference;
+ typedef const node_holder & const_node_holder_reference;
+ typedef node& node_reference;
+ typedef const node & const_node_reference;
+
+ static const link_mode_type link_mode = LinkMode;
+
+ static pointer to_value_ptr(const node_ptr & n)
+ {
+ return pointer_traits<pointer>::pointer_to
+ (static_cast<reference>(static_cast<node_holder_reference>(*n)));
+ }
+
+ static const_pointer to_value_ptr(const const_node_ptr & n)
+ {
+ return pointer_traits<const_pointer>::pointer_to
+ (static_cast<const_reference>(static_cast<const_node_holder_reference>(*n)));
+ }
+
+ static node_ptr to_node_ptr(reference value)
+ {
+ return pointer_traits<node_ptr>::pointer_to
+ (static_cast<node_reference>(static_cast<node_holder_reference>(value)));
+ }
+
+ static const_node_ptr to_node_ptr(const_reference value)
+ {
+ return pointer_traits<const_node_ptr>::pointer_to
+ (static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value)));
+ }
+};
+
+template<class T, class Hook, Hook T::* P>
+struct member_hook_traits
+{
+ public:
+ typedef Hook hook_type;
+ typedef typename hook_type::boost_intrusive_tags::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef T value_type;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<T>::type pointer;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<const T>::type const_pointer;
+ typedef T & reference;
+ typedef const T & const_reference;
+ typedef node& node_reference;
+ typedef const node & const_node_reference;
+ typedef hook_type& hook_reference;
+ typedef const hook_type & const_hook_reference;
+
+ static const link_mode_type link_mode = Hook::boost_intrusive_tags::link_mode;
+
+ static node_ptr to_node_ptr(reference value)
+ {
+ return pointer_traits<node_ptr>::pointer_to
+ (static_cast<node_reference>(static_cast<hook_reference>(value.*P)));
+ }
+
+ static const_node_ptr to_node_ptr(const_reference value)
+ {
+ return pointer_traits<const_node_ptr>::pointer_to
+ (static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P)));
+ }
+
+ static pointer to_value_ptr(const node_ptr & n)
+ {
+ return pointer_traits<pointer>::pointer_to
+ (*detail::parent_from_member<T, Hook>
+ (static_cast<Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P));
+ }
+
+ static const_pointer to_value_ptr(const const_node_ptr & n)
+ {
+ return pointer_traits<const_pointer>::pointer_to
+ (*detail::parent_from_member<T, Hook>
+ (static_cast<const Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P));
+ }
+};
+
+template<class Functor>
+struct function_hook_traits
+{
+ public:
+ typedef typename Functor::hook_type hook_type;
+ typedef typename Functor::hook_ptr hook_ptr;
+ typedef typename Functor::const_hook_ptr const_hook_ptr;
+ typedef typename hook_type::boost_intrusive_tags::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename Functor::value_type value_type;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<value_type>::type pointer;
+ typedef typename pointer_traits<node_ptr>::
+ template rebind_pointer<const value_type>::type const_pointer;
+ typedef value_type & reference;
+ typedef const value_type & const_reference;
+ static const link_mode_type link_mode = hook_type::boost_intrusive_tags::link_mode;
+
+ static node_ptr to_node_ptr(reference value)
+ { return static_cast<node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); }
+
+ static const_node_ptr to_node_ptr(const_reference value)
+ { return static_cast<const node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); }
+
+ static pointer to_value_ptr(const node_ptr & n)
+ { return Functor::to_value_ptr(to_hook_ptr(n)); }
+
+ static const_pointer to_value_ptr(const const_node_ptr & n)
+ { return Functor::to_value_ptr(to_hook_ptr(n)); }
+
+ private:
+ static hook_ptr to_hook_ptr(const node_ptr & n)
+ { return hook_ptr(&*static_cast<hook_type*>(&*n)); }
+
+ static const_hook_ptr to_hook_ptr(const const_node_ptr & n)
+ { return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); }
+};
+
+
+//This function uses binary search to discover the
+//highest set bit of the integer
+inline std::size_t floor_log2 (std::size_t x)
+{
+ const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT;
+ const bool Size_t_Bits_Power_2= !(Bits & (Bits-1));
+ BOOST_STATIC_ASSERT(Size_t_Bits_Power_2);
+
+ std::size_t n = x;
+ std::size_t log2 = 0;
+
+ for(std::size_t shift = Bits >> 1; shift; shift >>= 1){
+ std::size_t tmp = n >> shift;
+ if (tmp)
+ log2 += shift, n = tmp;
+ }
+
+ return log2;
+}
+
+inline float fast_log2 (float val)
+{
+ union caster_t
+ {
+ boost::uint32_t x;
+ float val;
+ } caster;
+
+ caster.val = val;
+ boost::uint32_t x = caster.x;
+ const int log_2 = (int)(((x >> 23) & 255) - 128);
+ x &= ~(255 << 23);
+ x += 127 << 23;
+ caster.x = x;
+ val = caster.val;
+ val = ((-1.0f/3) * val + 2) * val - 2.0f/3;
+
+ return (val + log_2);
+}
+
+inline std::size_t ceil_log2 (std::size_t x)
+{
+ return ((x & (x-1))!= 0) + floor_log2(x);
+}
+
+template<class SizeType, std::size_t N>
+struct numbits_eq
+{
+ static const bool value = sizeof(SizeType)*CHAR_BIT == N;
+};
+
+template<class SizeType, class Enabler = void >
+struct sqrt2_pow_max;
+
+template <class SizeType>
+struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 32> >::type>
+{
+ static const boost::uint32_t value = 0xb504f334;
+ static const std::size_t pow = 31;
+};
+
+template <class SizeType>
+struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 64> >::type>
+{
+ static const boost::uint64_t value = 0xb504f333f9de6484ull;
+ static const std::size_t pow = 63;
+};
+
+// Returns floor(pow(sqrt(2), x * 2 + 1)).
+// Defined for X from 0 up to the number of bits in size_t minus 1.
+inline std::size_t sqrt2_pow_2xplus1 (std::size_t x)
+{
+ const std::size_t value = (std::size_t)sqrt2_pow_max<std::size_t>::value;
+ const std::size_t pow = (std::size_t)sqrt2_pow_max<std::size_t>::pow;
+ return (value >> (pow - x)) + 1;
+}
+
+template<class Container, class Disposer>
+class exception_disposer
+{
+ Container *cont_;
+ Disposer &disp_;
+
+ exception_disposer(const exception_disposer&);
+ exception_disposer &operator=(const exception_disposer&);
+
+ public:
+ exception_disposer(Container &cont, Disposer &disp)
+ : cont_(&cont), disp_(disp)
+ {}
+
+ void release()
+ { cont_ = 0; }
+
+ ~exception_disposer()
+ {
+ if(cont_){
+ cont_->clear_and_dispose(disp_);
+ }
+ }
+};
+
+template<class Container, class Disposer, class SizeType>
+class exception_array_disposer
+{
+ Container *cont_;
+ Disposer &disp_;
+ SizeType &constructed_;
+
+ exception_array_disposer(const exception_array_disposer&);
+ exception_array_disposer &operator=(const exception_array_disposer&);
+
+ public:
+
+ exception_array_disposer
+ (Container &cont, Disposer &disp, SizeType &constructed)
+ : cont_(&cont), disp_(disp), constructed_(constructed)
+ {}
+
+ void release()
+ { cont_ = 0; }
+
+ ~exception_array_disposer()
+ {
+ SizeType n = constructed_;
+ if(cont_){
+ while(n--){
+ cont_[n].clear_and_dispose(disp_);
+ }
+ }
+ }
+};
+
+template<class ValueTraits, bool ExternalValueTraits>
+struct store_cont_ptr_on_it_impl
+{
+ static const bool value = is_stateful_value_traits<ValueTraits>::value;
+};
+
+template<class ValueTraits>
+struct store_cont_ptr_on_it_impl<ValueTraits, true>
+{
+ static const bool value = true;
+};
+
+template <class Container>
+struct store_cont_ptr_on_it
+{
+ typedef typename Container::value_traits value_traits;
+ static const bool value = store_cont_ptr_on_it_impl
+ <value_traits, external_value_traits_is_true<value_traits>::value>::value;
+};
+
+template<class Container, bool IsConst>
+struct node_to_value
+ : public detail::select_constptr
+ < typename pointer_traits
+ <typename Container::pointer>::template rebind_pointer<void>::type
+ , detail::store_cont_ptr_on_it<Container>::value
+ >::type
+{
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::value_type value_type;
+ typedef typename detail::select_constptr
+ < typename pointer_traits
+ <typename Container::pointer>::template rebind_pointer<void>::type
+ , store_container_ptr >::type Base;
+ typedef typename real_value_traits::node_traits::node node;
+ typedef typename detail::add_const_if_c
+ <value_type, IsConst>::type vtype;
+ typedef typename detail::add_const_if_c
+ <node, IsConst>::type ntype;
+ typedef typename pointer_traits
+ <typename Container::pointer>::template rebind_pointer<ntype>::type npointer;
+
+ node_to_value(const Container *cont)
+ : Base(cont)
+ {}
+
+ typedef vtype & result_type;
+ typedef ntype & first_argument_type;
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr)
+ return static_cast<const Container*>(Base::get_ptr());
+ else
+ return 0;
+ }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ result_type operator()(first_argument_type arg) const
+ {
+ return *(this->get_real_value_traits()->to_value_ptr
+ (pointer_traits<npointer>::pointer_to(arg)));
+ }
+};
+
+//This is not standard, but should work with all compilers
+union max_align
+{
+ char char_;
+ short short_;
+ int int_;
+ long long_;
+ #ifdef BOOST_HAS_LONG_LONG
+ long long long_long_;
+ #endif
+ float float_;
+ double double_;
+ long double long_double_;
+ void * void_ptr_;
+};
+
+template<class T, std::size_t N>
+class array_initializer
+{
+ public:
+ template<class CommonInitializer>
+ array_initializer(const CommonInitializer &init)
+ {
+ char *init_buf = (char*)rawbuf;
+ std::size_t i = 0;
+ try{
+ for(; i != N; ++i){
+ new(init_buf)T(init);
+ init_buf += sizeof(T);
+ }
+ }
+ catch(...){
+ while(i--){
+ init_buf -= sizeof(T);
+ ((T*)init_buf)->~T();
+ }
+ throw;
+ }
+ }
+
+ operator T* ()
+ { return (T*)(rawbuf); }
+
+ operator const T*() const
+ { return (const T*)(rawbuf); }
+
+ ~array_initializer()
+ {
+ char *init_buf = (char*)rawbuf + N*sizeof(T);
+ for(std::size_t i = 0; i != N; ++i){
+ init_buf -= sizeof(T);
+ ((T*)init_buf)->~T();
+ }
+ }
+
+ private:
+ detail::max_align rawbuf[(N*sizeof(T)-1)/sizeof(detail::max_align)+1];
+};
+
+
+
+
+template<class It>
+class reverse_iterator
+ : public std::iterator<
+ typename std::iterator_traits<It>::iterator_category,
+ typename std::iterator_traits<It>::value_type,
+ typename std::iterator_traits<It>::difference_type,
+ typename std::iterator_traits<It>::pointer,
+ typename std::iterator_traits<It>::reference>
+{
+ public:
+ typedef typename std::iterator_traits<It>::pointer pointer;
+ typedef typename std::iterator_traits<It>::reference reference;
+ typedef typename std::iterator_traits<It>::difference_type difference_type;
+ typedef It iterator_type;
+
+ reverse_iterator(){}
+
+ explicit reverse_iterator(It r)
+ : m_current(r)
+ {}
+
+ template<class OtherIt>
+ reverse_iterator(const reverse_iterator<OtherIt>& r)
+ : m_current(r.base())
+ {}
+
+ It base() const
+ { return m_current; }
+
+ reference operator*() const
+ { It temp(m_current); --temp; return *temp; }
+
+ pointer operator->() const
+ { It temp(m_current); --temp; return temp.operator->(); }
+
+ reference operator[](difference_type off) const
+ { return this->m_current[-off]; }
+
+ reverse_iterator& operator++()
+ { --m_current; return *this; }
+
+ reverse_iterator operator++(int)
+ {
+ reverse_iterator temp = *this;
+ --m_current;
+ return temp;
+ }
+
+ reverse_iterator& operator--()
+ {
+ ++m_current;
+ return *this;
+ }
+
+ reverse_iterator operator--(int)
+ {
+ reverse_iterator temp(*this);
+ ++m_current;
+ return temp;
+ }
+
+ friend bool operator==(const reverse_iterator& l, const reverse_iterator& r)
+ { return l.m_current == r.m_current; }
+
+ friend bool operator!=(const reverse_iterator& l, const reverse_iterator& r)
+ { return l.m_current != r.m_current; }
+
+ friend bool operator<(const reverse_iterator& l, const reverse_iterator& r)
+ { return l.m_current < r.m_current; }
+
+ friend bool operator<=(const reverse_iterator& l, const reverse_iterator& r)
+ { return l.m_current <= r.m_current; }
+
+ friend bool operator>(const reverse_iterator& l, const reverse_iterator& r)
+ { return l.m_current > r.m_current; }
+
+ friend bool operator>=(const reverse_iterator& l, const reverse_iterator& r)
+ { return l.m_current >= r.m_current; }
+
+ reverse_iterator& operator+=(difference_type off)
+ { m_current -= off; return *this; }
+
+ friend reverse_iterator operator+(const reverse_iterator & l, difference_type off)
+ {
+ reverse_iterator tmp(l.m_current);
+ tmp.m_current -= off;
+ return tmp;
+ }
+
+ reverse_iterator& operator-=(difference_type off)
+ { m_current += off; return *this; }
+
+ friend reverse_iterator operator-(const reverse_iterator & l, difference_type off)
+ {
+ reverse_iterator tmp(l.m_current);
+ tmp.m_current += off;
+ return tmp;
+ }
+
+ friend difference_type operator-(const reverse_iterator& l, const reverse_iterator& r)
+ { return r.m_current - l.m_current; }
+
+ private:
+ It m_current; // the wrapped iterator
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP
diff --git a/boost/intrusive/detail/workaround.hpp b/boost/intrusive/detail/workaround.hpp
new file mode 100644
index 0000000..5de529f
--- /dev/null
+++ b/boost/intrusive/detail/workaround.hpp
@@ -0,0 +1,22 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2005-2009. 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/interprocess for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_WRKRND_HPP
+#define BOOST_INTRUSIVE_DETAIL_WRKRND_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+
+#if !defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_NO_VARIADIC_TEMPLATES)
+ #define BOOST_INTRUSIVE_PERFECT_FORWARDING
+#endif
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_DETAIL_WRKRND_HPP