Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52747 - sandbox/move/boost/unordered/detail
From: daniel_james_at_[hidden]
Date: 2009-05-03 06:15:35


Author: danieljames
Date: 2009-05-03 06:15:35 EDT (Sun, 03 May 2009)
New Revision: 52747
URL: http://svn.boost.org/trac/boost/changeset/52747

Log:
Put the C++0x emplace implementations before the non-C++0x versions.

I'm going to change the non-C++0x to be macro heavy emulations of the
C++0x versions, so this will put the readable version first.
Text files modified:
   sandbox/move/boost/unordered/detail/hash_table_impl.hpp | 155 ++++++++++++++++++++-------------------
   1 files changed, 78 insertions(+), 77 deletions(-)

Modified: sandbox/move/boost/unordered/detail/hash_table_impl.hpp
==============================================================================
--- sandbox/move/boost/unordered/detail/hash_table_impl.hpp (original)
+++ sandbox/move/boost/unordered/detail/hash_table_impl.hpp 2009-05-03 06:15:35 EDT (Sun, 03 May 2009)
@@ -1599,31 +1599,36 @@
 
 #if BOOST_UNORDERED_EQUIVALENT_KEYS
 
-#if !(defined(BOOST_HAS_RVALUE_REFS) && defined(BOOST_HAS_VARIADIC_TMPL))
- // Insert (equivalent key containers)
+#if defined(BOOST_HAS_RVALUE_REFS) && defined(BOOST_HAS_VARIADIC_TMPL)
+
+ // Emplace (equivalent key containers)
+ // (I'm using an overloaded emplace for both 'insert' and 'emplace')
 
             // if hash function throws, basic exception safety
             // strong otherwise
- iterator_base emplace(value_type const& v)
+ template <class... Args>
+ iterator_base emplace(Args&&... args)
             {
                 // Create the node before rehashing in case it throws an
                 // exception (need strong safety in such a case).
                 node_constructor a(data_.allocators_);
- a.construct(v);
+ a.construct(std::forward<Args>(args)...);
 
                 return emplace_impl(a);
             }
 
- // Insert (equivalent key containers)
+ // Emplace (equivalent key containers)
+ // (I'm using an overloaded emplace for both 'insert' and 'emplace')
 
             // if hash function throws, basic exception safety
             // strong otherwise
- iterator_base emplace_hint(iterator_base const& it, value_type const& v)
+ template <class... Args>
+ iterator_base emplace_hint(iterator_base const& it, Args&&... args)
             {
                 // Create the node before rehashing in case it throws an
                 // exception (need strong safety in such a case).
                 node_constructor a(data_.allocators_);
- a.construct(v);
+ a.construct(std::forward<Args>(args)...);
 
                 return emplace_hint_impl(it, a);
             }
@@ -1631,33 +1636,29 @@
 #else
 
             // Emplace (equivalent key containers)
- // (I'm using an overloaded emplace for both 'insert' and 'emplace')
 
             // if hash function throws, basic exception safety
             // strong otherwise
- template <class... Args>
- iterator_base emplace(Args&&... args)
+ iterator_base emplace(value_type const& v)
             {
                 // Create the node before rehashing in case it throws an
                 // exception (need strong safety in such a case).
                 node_constructor a(data_.allocators_);
- a.construct(std::forward<Args>(args)...);
+ a.construct(v);
 
                 return emplace_impl(a);
             }
 
- // Insert (equivalent key containers)
- // (I'm using an overloaded emplace for both 'insert' and 'emplace')
+ // Emplace (equivalent key containers)
 
             // if hash function throws, basic exception safety
             // strong otherwise
- template <class... Args>
- iterator_base emplace_hint(iterator_base const& it, Args&&... args)
+ iterator_base emplace_hint(iterator_base const& it, value_type const& v)
             {
                 // Create the node before rehashing in case it throws an
                 // exception (need strong safety in such a case).
                 node_constructor a(data_.allocators_);
- a.construct(std::forward<Args>(args)...);
+ a.construct(v);
 
                 return emplace_hint_impl(it, a);
             }
@@ -1689,13 +1690,13 @@
             {
                 // equal can throw, but with no effects
                 if (it == data_.end() || !equal(extract_key(a.get()->value()), *it)) {
- // Use the standard insert if the iterator doesn't point
+ // Use the standard emplace if the iterator doesn't point
                     // to a matching key.
                     return emplace_impl(a);
                 }
                 else {
                     // Find the first node in the group - so that the node
- // will be inserted at the end of the group.
+ // will be added at the end of the group.
 
                     link_ptr start(it.node_);
                     while(data_.prev_in_group(start)->next_ == start)
@@ -1803,64 +1804,10 @@
                 }
             }
 
-#if !(defined(BOOST_HAS_RVALUE_REFS) && defined(BOOST_HAS_VARIADIC_TMPL))
-
- // Insert (unique keys)
-
- // if hash function throws, basic exception safety
- // strong otherwise
- std::pair<iterator_base, bool> emplace(value_type const& v)
- {
- // No side effects in this initial code
- key_type const& k = extract_key(v);
- size_type hash_value = hash_function()(k);
- bucket_ptr bucket = data_.bucket_ptr_from_hash(hash_value);
- link_ptr pos = find_iterator(bucket, k);
-
- if (BOOST_UNORDERED_BORLAND_BOOL(pos)) {
- // Found an existing key, return it (no throw).
- return std::pair<iterator_base, bool>(
- iterator_base(bucket, pos), false);
-
- } else {
- // Doesn't already exist, add to bucket.
- // Side effects only in this block.
-
- // Create the node before rehashing in case it throws an
- // exception (need strong safety in such a case).
- node_constructor a(data_.allocators_);
- a.construct(v);
-
- // reserve has basic exception safety if the hash function
- // throws, strong otherwise.
- if(reserve_for_insert(size() + 1))
- bucket = data_.bucket_ptr_from_hash(hash_value);
-
- // Nothing after this point can throw.
-
- link_ptr n = data_.link_node_in_bucket(a, bucket);
-
- return std::pair<iterator_base, bool>(
- iterator_base(bucket, n), true);
- }
- }
-
- // Insert (unique keys)
+#if defined(BOOST_HAS_RVALUE_REFS) && defined(BOOST_HAS_VARIADIC_TMPL)
 
- // if hash function throws, basic exception safety
- // strong otherwise
- iterator_base emplace_hint(iterator_base const& it, value_type const& v)
- {
- if(it != data_.end() && equal(extract_key(v), *it))
- return it;
- else
- return emplace(v).first;
- }
-
-#else
-
- // Insert (unique keys)
- // (I'm using an overloaded insert for both 'insert' and 'emplace')
+ // Emplace (unique keys)
+ // (I'm using an overloaded emplace for both 'insert' and 'emplace')
             //
             // TODO:
             // For sets: create a local key without creating the node?
@@ -1941,8 +1888,8 @@
                 }
             }
 
- // Insert (unique keys)
- // (I'm using an overloaded insert for both 'insert' and 'emplace')
+ // Emplace (unique keys)
+ // (I'm using an overloaded emplace for both 'insert' and 'emplace')
 
             // if hash function throws, basic exception safety
             // strong otherwise
@@ -1952,6 +1899,60 @@
                 // Life is complicated - just call the normal implementation.
                 return emplace(std::forward<Args>(args)...).first;
             }
+#else
+
+ // Emplace (unique keys)
+
+ // if hash function throws, basic exception safety
+ // strong otherwise
+ std::pair<iterator_base, bool> emplace(value_type const& v)
+ {
+ // No side effects in this initial code
+ key_type const& k = extract_key(v);
+ size_type hash_value = hash_function()(k);
+ bucket_ptr bucket = data_.bucket_ptr_from_hash(hash_value);
+ link_ptr pos = find_iterator(bucket, k);
+
+ if (BOOST_UNORDERED_BORLAND_BOOL(pos)) {
+ // Found an existing key, return it (no throw).
+ return std::pair<iterator_base, bool>(
+ iterator_base(bucket, pos), false);
+
+ } else {
+ // Doesn't already exist, add to bucket.
+ // Side effects only in this block.
+
+ // Create the node before rehashing in case it throws an
+ // exception (need strong safety in such a case).
+ node_constructor a(data_.allocators_);
+ a.construct(v);
+
+ // reserve has basic exception safety if the hash function
+ // throws, strong otherwise.
+ if(reserve_for_insert(size() + 1))
+ bucket = data_.bucket_ptr_from_hash(hash_value);
+
+ // Nothing after this point can throw.
+
+ link_ptr n = data_.link_node_in_bucket(a, bucket);
+
+ return std::pair<iterator_base, bool>(
+ iterator_base(bucket, n), true);
+ }
+ }
+
+ // Emplace (unique keys)
+
+ // if hash function throws, basic exception safety
+ // strong otherwise
+ iterator_base emplace_hint(iterator_base const& it, value_type const& v)
+ {
+ if(it != data_.end() && equal(extract_key(v), *it))
+ return it;
+ else
+ return emplace(v).first;
+ }
+
 #endif
 
             // Insert from iterators (unique keys)


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