Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75158 - trunk/boost/unordered/detail
From: dnljms_at_[hidden]
Date: 2011-10-28 13:42:52


Author: danieljames
Date: 2011-10-28 13:42:51 EDT (Fri, 28 Oct 2011)
New Revision: 75158
URL: http://svn.boost.org/trac/boost/changeset/75158

Log:
Unordered: Return iterators in pairs instead of node_pointers.

It looks like the current version doesn't work with a correct
implementation of C++11 pairs since they don't use explicit conversions.
So just return the correct type in the first place.

Should probably be using iterators in other places as well. I was using
node_pointers everywhere due to some legacy from older versions.
Text files modified:
   trunk/boost/unordered/detail/equivalent.hpp | 11 +++++++----
   trunk/boost/unordered/detail/unique.hpp | 19 ++++++++++---------
   2 files changed, 17 insertions(+), 13 deletions(-)

Modified: trunk/boost/unordered/detail/equivalent.hpp
==============================================================================
--- trunk/boost/unordered/detail/equivalent.hpp (original)
+++ trunk/boost/unordered/detail/equivalent.hpp 2011-10-28 13:42:51 EDT (Fri, 28 Oct 2011)
@@ -178,6 +178,7 @@
         typedef typename table::key_type key_type;
         typedef typename table::node_constructor node_constructor;
         typedef typename table::extractor extractor;
+ typedef typename table::iterator iterator;
 
         // Constructors
 
@@ -255,13 +256,15 @@
             return count;
         }
 
- std::pair<node_pointer, node_pointer>
+ std::pair<iterator, iterator>
             equal_range(key_type const& k) const
         {
             node_pointer n = this->find_node(k);
- return std::make_pair(n,
- n ? static_cast<node_pointer>(
- static_cast<node_pointer>(n->group_prev_)->next_) : n);
+ return std::make_pair(
+ iterator(n), iterator(n ?
+ static_cast<node_pointer>(
+ static_cast<node_pointer>(n->group_prev_)->next_) :
+ n));
         }
 
         // Equality

Modified: trunk/boost/unordered/detail/unique.hpp
==============================================================================
--- trunk/boost/unordered/detail/unique.hpp (original)
+++ trunk/boost/unordered/detail/unique.hpp 2011-10-28 13:42:51 EDT (Fri, 28 Oct 2011)
@@ -174,8 +174,9 @@
         typedef typename table::key_type key_type;
         typedef typename table::node_constructor node_constructor;
         typedef typename table::extractor extractor;
+ typedef typename table::iterator iterator;
 
- typedef std::pair<node_pointer, bool> emplace_return;
+ typedef std::pair<iterator, bool> emplace_return;
 
         // Constructors
 
@@ -253,12 +254,12 @@
                 std::out_of_range("Unable to find key in unordered_map."));
         }
 
- std::pair<node_pointer, node_pointer>
+ std::pair<iterator, iterator>
             equal_range(key_type const& k) const
         {
             node_pointer n = this->find_node(k);
- return std::make_pair(n,
- n ? static_cast<node_pointer>(n->next_) : n);
+ return std::make_pair(iterator(n),
+ iterator(n ? static_cast<node_pointer>(n->next_) : n));
         }
 
         // equals
@@ -354,7 +355,7 @@
                 boost::unordered::detail::please_ignore_this_overload> const&)
         {
             BOOST_ASSERT(false);
- return emplace_return(this->begin(), false);
+ return emplace_return(iterator(this->begin()), false);
         }
 #endif
 
@@ -389,7 +390,7 @@
             std::size_t hash = this->hash_function()(k);
             node_pointer pos = this->find_node(hash, k);
     
- if (pos) return emplace_return(pos, false);
+ if (pos) return emplace_return(iterator(pos), false);
     
             // Create the node before rehashing in case it throws an
             // exception (need strong safety in such a case).
@@ -400,7 +401,7 @@
             // reserve has basic exception safety if the hash function
             // throws, strong otherwise.
             this->reserve_for_insert(this->size_ + 1);
- return emplace_return(this->add_node(a, hash), true);
+ return emplace_return(iterator(this->add_node(a, hash)), true);
         }
 
         emplace_return emplace_impl_with_node(node_constructor& a)
@@ -409,12 +410,12 @@
             std::size_t hash = this->hash_function()(k);
             node_pointer pos = this->find_node(hash, k);
 
- if (pos) return emplace_return(pos, false);
+ if (pos) return emplace_return(iterator(pos), false);
 
             // reserve has basic exception safety if the hash function
             // throws, strong otherwise.
             this->reserve_for_insert(this->size_ + 1);
- return emplace_return(this->add_node(a, hash), true);
+ return emplace_return(iterator(this->add_node(a, hash)), true);
         }
 
         template <BOOST_UNORDERED_EMPLACE_TEMPLATE>


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