Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81208 - trunk/boost/unordered/detail
From: dnljms_at_[hidden]
Date: 2012-11-05 13:33:16


Author: danieljames
Date: 2012-11-05 13:33:15 EST (Mon, 05 Nov 2012)
New Revision: 81208
URL: http://svn.boost.org/trac/boost/changeset/81208

Log:
Unordered: Clean up the pointer silliness.
Text files modified:
   trunk/boost/unordered/detail/buckets.hpp | 126 +++++++++++++++++++++------------------
   trunk/boost/unordered/detail/equivalent.hpp | 59 ++++++++----------
   trunk/boost/unordered/detail/table.hpp | 15 +--
   trunk/boost/unordered/detail/unique.hpp | 8 +
   4 files changed, 105 insertions(+), 103 deletions(-)

Modified: trunk/boost/unordered/detail/buckets.hpp
==============================================================================
--- trunk/boost/unordered/detail/buckets.hpp (original)
+++ trunk/boost/unordered/detail/buckets.hpp 2012-11-05 13:33:15 EST (Mon, 05 Nov 2012)
@@ -37,49 +37,50 @@
     //
     // all no throw
 
- template <typename NodePointer, typename Value> struct iterator;
- template <typename ConstNodePointer, typename NodePointer,
- typename Value> struct c_iterator;
- template <typename NodePointer, typename Value, typename Policy>
- struct l_iterator;
- template <typename ConstNodePointer, typename NodePointer,
- typename Value, typename Policy> struct cl_iterator;
+ template <typename Node> struct iterator;
+ template <typename Node, typename ConstNodePointer> struct c_iterator;
+ template <typename Node, typename Policy> struct l_iterator;
+ template <typename Node, typename ConstNodePointer, typename Policy>
+ struct cl_iterator;
 
     // Local Iterators
     //
     // all no throw
 
- template <typename NodePointer, typename Value, typename Policy>
+ template <typename Node, typename Policy>
     struct l_iterator
         : public boost::iterator<
- std::forward_iterator_tag, Value, std::ptrdiff_t,
- NodePointer, Value&>
+ std::forward_iterator_tag,
+ typename Node::value_type,
+ std::ptrdiff_t,
+ typename Node::node_pointer,
+ typename Node::value_type&>
     {
 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
- template <typename ConstNodePointer, typename NodePointer2,
- typename Value2, typename Policy2>
+ template <typename Node2, typename ConstNodePointer, typename Policy2>
         friend struct boost::unordered::iterator_detail::cl_iterator;
     private:
 #endif
- typedef NodePointer node_pointer;
- typedef boost::unordered::iterator_detail::iterator<NodePointer, Value>
- iterator;
+ typedef typename Node::node_pointer node_pointer;
+ typedef boost::unordered::iterator_detail::iterator<Node> iterator;
         node_pointer ptr_;
         std::size_t bucket_;
         std::size_t bucket_count_;
 
     public:
 
+ typedef typename Node::value_type value_type;
+
         l_iterator() : ptr_() {}
 
         l_iterator(iterator x, std::size_t b, std::size_t c)
             : ptr_(x.node_), bucket_(b), bucket_count_(c) {}
 
- Value& operator*() const {
+ value_type& operator*() const {
             return ptr_->value();
         }
 
- Value* operator->() const {
+ value_type* operator->() const {
             return ptr_->value_ptr();
         }
 
@@ -106,42 +107,44 @@
         }
     };
 
- template <typename ConstNodePointer, typename NodePointer, typename Value,
- typename Policy>
+ template <typename Node, typename ConstNodePointer, typename Policy>
     struct cl_iterator
         : public boost::iterator<
- std::forward_iterator_tag, Value, std::ptrdiff_t,
- ConstNodePointer, Value const&>
+ std::forward_iterator_tag,
+ typename Node::value_type,
+ std::ptrdiff_t,
+ ConstNodePointer,
+ typename Node::value_type const&>
     {
         friend struct boost::unordered::iterator_detail::l_iterator
- <NodePointer, Value, Policy>;
+ <Node, Policy>;
     private:
 
- typedef NodePointer node_pointer;
- typedef boost::unordered::iterator_detail::iterator<NodePointer, Value>
- iterator;
+ typedef typename Node::node_pointer node_pointer;
+ typedef boost::unordered::iterator_detail::iterator<Node> iterator;
         node_pointer ptr_;
         std::size_t bucket_;
         std::size_t bucket_count_;
 
     public:
 
+ typedef typename Node::value_type value_type;
+
         cl_iterator() : ptr_() {}
 
         cl_iterator(iterator x, std::size_t b, std::size_t c) :
             ptr_(x.node_), bucket_(b), bucket_count_(c) {}
 
         cl_iterator(boost::unordered::iterator_detail::l_iterator<
- NodePointer, Value, Policy> const& x) :
+ Node, Policy> const& x) :
             ptr_(x.ptr_), bucket_(x.bucket_), bucket_count_(x.bucket_count_)
         {}
 
- Value const&
- operator*() const {
+ value_type const& operator*() const {
             return ptr_->value();
         }
 
- Value const* operator->() const {
+ value_type const* operator->() const {
             return ptr_->value_ptr();
         }
 
@@ -168,18 +171,21 @@
         }
     };
 
- template <typename NodePointer, typename Value>
+ template <typename Node>
     struct iterator
         : public boost::iterator<
- std::forward_iterator_tag, Value, std::ptrdiff_t,
- NodePointer, Value&>
+ std::forward_iterator_tag,
+ typename Node::value_type,
+ std::ptrdiff_t,
+ typename Node::node_pointer,
+ typename Node::value_type&>
     {
 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
- template <typename, typename, typename>
+ template <typename, typename>
         friend struct boost::unordered::iterator_detail::c_iterator;
- template <typename, typename, typename>
+ template <typename, typename>
         friend struct boost::unordered::iterator_detail::l_iterator;
- template <typename, typename, typename, typename>
+ template <typename, typename, typename>
         friend struct boost::unordered::iterator_detail::cl_iterator;
         template <typename>
         friend struct boost::unordered::detail::table;
@@ -189,20 +195,23 @@
         friend struct boost::unordered::detail::grouped_table_impl;
     private:
 #endif
- typedef NodePointer node_pointer;
+ typedef typename Node::node_pointer node_pointer;
         node_pointer node_;
 
     public:
 
+ typedef typename Node::value_type value_type;
+
         iterator() : node_() {}
 
- explicit iterator(node_pointer const& x) : node_(x) {}
+ explicit iterator(typename Node::link_pointer x) :
+ node_(static_cast<node_pointer>(x)) {}
 
- Value& operator*() const {
+ value_type& operator*() const {
             return node_->value();
         }
 
- Value* operator->() const {
+ value_type* operator->() const {
             return &node_->value();
         }
 
@@ -226,14 +235,16 @@
         }
     };
 
- template <typename ConstNodePointer, typename NodePointer, typename Value>
+ template <typename Node, typename ConstNodePointer>
     struct c_iterator
         : public boost::iterator<
- std::forward_iterator_tag, Value, std::ptrdiff_t,
- ConstNodePointer, Value const&>
+ std::forward_iterator_tag,
+ typename Node::value_type,
+ std::ptrdiff_t,
+ ConstNodePointer,
+ typename Node::value_type const&>
     {
- friend struct boost::unordered::iterator_detail::iterator<
- NodePointer, Value>;
+ friend struct boost::unordered::iterator_detail::iterator<Node>;
 
 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
         template <typename>
@@ -245,26 +256,26 @@
 
     private:
 #endif
-
- typedef NodePointer node_pointer;
- typedef boost::unordered::iterator_detail::iterator<NodePointer, Value>
- iterator;
+ typedef typename Node::node_pointer node_pointer;
+ typedef boost::unordered::iterator_detail::iterator<Node> iterator;
         node_pointer node_;
 
     public:
 
+ typedef typename Node::value_type value_type;
+
         c_iterator() : node_() {}
 
- explicit c_iterator(node_pointer const& x) : node_(x) {}
+ explicit c_iterator(typename Node::link_pointer x) :
+ node_(static_cast<node_pointer>(x)) {}
 
- c_iterator(boost::unordered::iterator_detail::iterator<
- NodePointer, Value> const& x) : node_(x.node_) {}
+ c_iterator(iterator const& x) : node_(x.node_) {}
 
- Value const& operator*() const {
+ value_type const& operator*() const {
             return node_->value();
         }
 
- Value const* operator->() const {
+ value_type const* operator->() const {
             return &node_->value();
         }
 
@@ -398,7 +409,7 @@
 
             node_allocator_traits::construct(alloc_,
                 boost::addressof(*node_), node());
- node_->init(static_cast<typename node::link_pointer>(node_));
+ node_->init(node_);
             node_constructed_ = true;
         }
         else {
@@ -432,8 +443,7 @@
         typedef typename node_allocator_traits::pointer node_pointer;
         typedef typename node::value_type value_type;
         typedef typename node::link_pointer link_pointer;
- typedef boost::unordered::iterator_detail::
- iterator<node_pointer, value_type> iterator;
+ typedef boost::unordered::iterator_detail::iterator<node> iterator;
 
         node_pointer nodes_;
 
@@ -484,7 +494,7 @@
                 assign_impl(v);
                 node_pointer p = nodes_;
                 nodes_ = static_cast<node_pointer>(p->next_);
- p->init(static_cast<typename node::link_pointer>(p));
+ p->init(p);
                 p->next_ = link_pointer();
                 return p;
             }
@@ -500,7 +510,7 @@
                 move_assign_impl(v);
                 node_pointer p = nodes_;
                 nodes_ = static_cast<node_pointer>(p->next_);
- p->init(static_cast<typename node::link_pointer>(p));
+ p->init(p);
                 p->next_ = link_pointer();
                 return p;
             }

Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp (original)
+++ trunk/boost/unordered/detail/equivalent.hpp 2012-11-05 13:33:15 EST (Mon, 05 Nov 2012)
@@ -25,10 +25,13 @@
         boost::unordered::detail::value_base<T>
     {
         typedef typename ::boost::unordered::detail::rebind_wrap<
- A, grouped_node<A, T> >::type::pointer link_pointer;
+ A, grouped_node<A, T> >::type allocator;
+ typedef typename ::boost::unordered::detail::
+ allocator_traits<allocator>::pointer node_pointer;
+ typedef node_pointer link_pointer;
 
         link_pointer next_;
- link_pointer group_prev_;
+ node_pointer group_prev_;
         std::size_t hash_;
 
         grouped_node() :
@@ -37,7 +40,7 @@
             hash_(0)
         {}
 
- void init(link_pointer self)
+ void init(node_pointer self)
         {
             group_prev_ = self;
         }
@@ -52,9 +55,10 @@
         boost::unordered::detail::ptr_bucket
     {
         typedef boost::unordered::detail::ptr_bucket bucket_base;
+ typedef grouped_ptr_node<T>* node_pointer;
         typedef ptr_bucket* link_pointer;
 
- link_pointer group_prev_;
+ node_pointer group_prev_;
         std::size_t hash_;
 
         grouped_ptr_node() :
@@ -63,7 +67,7 @@
             hash_(0)
         {}
 
- void init(link_pointer self)
+ void init(node_pointer self)
         {
             group_prev_ = self;
         }
@@ -254,8 +258,7 @@
                         return iterator();
                 }
 
- n = iterator(static_cast<node_pointer>(
- static_cast<node_pointer>(n.node_->group_prev_)->next_));
+ n = iterator(n.node_->group_prev_->next_);
             }
         }
 
@@ -267,7 +270,7 @@
             std::size_t x = 0;
             node_pointer it = n.node_;
             do {
- it = static_cast<node_pointer>(it->group_prev_);
+ it = it->group_prev_;
                 ++x;
             } while(it != n.node_);
 
@@ -279,10 +282,7 @@
         {
             iterator n = this->find_node(k);
             return std::make_pair(
- n, n.node_ ? iterator(
- static_cast<node_pointer>(
- static_cast<node_pointer>(n.node_->group_prev_)->next_
- )) : n);
+ n, n.node_ ? iterator(n.node_->group_prev_->next_) : n);
         }
 
         // Equality
@@ -295,10 +295,8 @@
             {
                 iterator n2 = other.find_matching_node(n1);
                 if (!n2.node_) return false;
- iterator end1(static_cast<node_pointer>(
- static_cast<node_pointer>(n1.node_->group_prev_)->next_));
- iterator end2(static_cast<node_pointer>(
- static_cast<node_pointer>(n2.node_->group_prev_)->next_));
+ iterator end1(n1.node_->group_prev_->next_);
+ iterator end2(n2.node_->group_prev_->next_);
                 if (!group_equals(n1, end1, n2, end2)) return false;
                 n1 = end1;
             }
@@ -394,9 +392,9 @@
                 node_pointer n,
                 node_pointer pos)
         {
- n->next_ = static_cast<node_pointer>(pos->group_prev_)->next_;
+ n->next_ = pos->group_prev_->next_;
             n->group_prev_ = pos->group_prev_;
- static_cast<node_pointer>(pos->group_prev_)->next_ = n;
+ pos->group_prev_->next_ = n;
             pos->group_prev_ = n;
         }
 
@@ -564,7 +562,7 @@
             }
 
             node_pointer first_node = static_cast<node_pointer>(prev->next_);
- link_pointer end = static_cast<node_pointer>(first_node->group_prev_)->next_;
+ link_pointer end = first_node->group_prev_->next_;
 
             std::size_t count = this->delete_nodes(prev, end);
             this->fix_bucket(bucket_index, prev);
@@ -609,8 +607,7 @@
             // Delete the nodes.
             do {
                 link_pointer group_end =
- static_cast<node_pointer>(
- static_cast<node_pointer>(prev->next_)->group_prev_)->next_;
+ static_cast<node_pointer>(prev->next_)->group_prev_->next_;
                 this->delete_nodes(prev, group_end);
                 bucket_index = this->fix_bucket(bucket_index, prev);
             } while(prev->next_ != end);
@@ -620,13 +617,13 @@
 
         static link_pointer split_groups(node_pointer begin, node_pointer end)
         {
- node_pointer prev = static_cast<node_pointer>(begin->group_prev_);
+ node_pointer prev = begin->group_prev_;
             if (prev->next_ != begin) prev = node_pointer();
 
             if (end) {
                 node_pointer first = end;
- while (first != begin && static_cast<node_pointer>(first->group_prev_)->next_ == first) {
- first = static_cast<node_pointer>(first->group_prev_);
+ while (first != begin && first->group_prev_->next_ == first) {
+ first = first->group_prev_;
                 }
 
                 boost::swap(first->group_prev_, end->group_prev_);
@@ -635,8 +632,8 @@
 
             if (prev) {
                 node_pointer first = prev;
- while (static_cast<node_pointer>(first->group_prev_)->next_ == first) {
- first = static_cast<node_pointer>(first->group_prev_);
+ while (first->group_prev_->next_ == first) {
+ first = first->group_prev_;
                 }
                 boost::swap(first->group_prev_, begin->group_prev_);
             }
@@ -655,10 +652,7 @@
 
             while (n.node_) {
                 std::size_t key_hash = n.node_->hash_;
- iterator group_end(
- static_cast<node_pointer>(
- static_cast<node_pointer>(n.node_->group_prev_)->next_
- ));
+ iterator group_end(n.node_->group_prev_->next_);
 
                 node_pointer first_node = creator.create(*n);
                 node_pointer end = first_node;
@@ -687,8 +681,7 @@
             link_pointer prev = this->get_previous_start();
             while (prev->next_)
                 prev = place_in_bucket(*this, prev,
- static_cast<node_pointer>(
- static_cast<node_pointer>(prev->next_)->group_prev_));
+ static_cast<node_pointer>(prev->next_)->group_prev_);
         }
 
         // Iterate through the nodes placing them in the correct buckets.
@@ -700,7 +693,7 @@
                         dst.bucket_count_, end->hash_));
 
             if (!b->next_) {
- b->next_ = static_cast<node_pointer>(prev);
+ b->next_ = prev;
                 return end;
             }
             else {

Modified: trunk/boost/unordered/detail/table.hpp
==============================================================================
--- trunk/boost/unordered/detail/table.hpp (original)
+++ trunk/boost/unordered/detail/table.hpp 2012-11-05 13:33:15 EST (Mon, 05 Nov 2012)
@@ -168,14 +168,13 @@
             node_constructor;
 
         typedef boost::unordered::iterator_detail::
- iterator<node_pointer, value_type> iterator;
+ iterator<node> iterator;
         typedef boost::unordered::iterator_detail::
- c_iterator<const_node_pointer, node_pointer, value_type> c_iterator;
+ c_iterator<node, const_node_pointer> c_iterator;
         typedef boost::unordered::iterator_detail::
- l_iterator<node_pointer, value_type, policy> l_iterator;
+ l_iterator<node, policy> l_iterator;
         typedef boost::unordered::iterator_detail::
- cl_iterator<const_node_pointer, node_pointer, value_type, policy>
- cl_iterator;
+ cl_iterator<node, const_node_pointer, policy> cl_iterator;
 
         ////////////////////////////////////////////////////////////////////////
         // Members
@@ -236,16 +235,14 @@
 
         iterator begin() const
         {
- return size_ ? iterator(static_cast<node_pointer>(
- get_previous_start()->next_)) : iterator();
+ return size_ ? iterator(get_previous_start()->next_) : iterator();
         }
 
         iterator begin(std::size_t bucket_index) const
         {
             if (!size_) return iterator();
             link_pointer prev = get_previous_start(bucket_index);
- return prev ? iterator(static_cast<node_pointer>(prev->next_)) :
- iterator();
+ return prev ? iterator(prev->next_) : iterator();
         }
 
         float load_factor() const

Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp (original)
+++ trunk/boost/unordered/detail/unique.hpp 2012-11-05 13:33:15 EST (Mon, 05 Nov 2012)
@@ -27,7 +27,8 @@
         boost::unordered::detail::value_base<T>
     {
         typedef typename ::boost::unordered::detail::rebind_wrap<
- A, unique_node<A, T> >::type::pointer link_pointer;
+ A, unique_node<A, T> >::type::pointer node_pointer;
+ typedef node_pointer link_pointer;
 
         link_pointer next_;
         std::size_t hash_;
@@ -37,7 +38,7 @@
             hash_(0)
         {}
 
- void init(link_pointer)
+ void init(node_pointer)
         {
         }
 
@@ -51,6 +52,7 @@
         boost::unordered::detail::ptr_bucket
     {
         typedef boost::unordered::detail::ptr_bucket bucket_base;
+ typedef ptr_node<T>* node_pointer;
         typedef ptr_bucket* link_pointer;
 
         std::size_t hash_;
@@ -60,7 +62,7 @@
             hash_(0)
         {}
 
- void init(link_pointer)
+ void init(node_pointer)
         {
         }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk