Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52065 - in branches/release: . boost/unordered/detail
From: daniel_james_at_[hidden]
Date: 2009-03-30 13:54:52


Author: danieljames
Date: 2009-03-30 13:54:49 EDT (Mon, 30 Mar 2009)
New Revision: 52065
URL: http://svn.boost.org/trac/boost/changeset/52065

Log:
Tweak unordered for some compilers.

Fixes #2756.

Merged revisions 51982-51983,51995 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r51982 | danieljames | 2009-03-26 07:00:21 +0000 (Thu, 26 Mar 2009) | 3 lines
  
  Revert [51409]
  
  It isn't working on Borland.
........
  r51983 | danieljames | 2009-03-26 07:00:46 +0000 (Thu, 26 Mar 2009) | 1 line
  
  Try to destruct values in a way that all compilers might like.
........
  r51995 | danieljames | 2009-03-26 21:09:51 +0000 (Thu, 26 Mar 2009) | 1 line
  
  Give up and use another macro to destruct values.
........

Properties modified:
   branches/release/ (props changed)
Text files modified:
   branches/release/boost/unordered/detail/hash_table.hpp | 48 +---------------
   branches/release/boost/unordered/detail/hash_table_impl.hpp | 109 ++++++++++++++++++++++++++-------------
   2 files changed, 76 insertions(+), 81 deletions(-)

Modified: branches/release/boost/unordered/detail/hash_table.hpp
==============================================================================
--- branches/release/boost/unordered/detail/hash_table.hpp (original)
+++ branches/release/boost/unordered/detail/hash_table.hpp 2009-03-30 13:54:49 EDT (Mon, 30 Mar 2009)
@@ -224,53 +224,15 @@
             functions_ptr func_; // The currently active functions.
         };
         
+#if defined(BOOST_MSVC)
+# define BOOST_UNORDERED_DESTRUCT(x, type) (x)->~type();
+#else
+# define BOOST_UNORDERED_DESTRUCT(x, type) boost::unordered_detail::destroy(x)
         template <typename T>
         void destroy(T* x) {
             x->~T();
         }
-
- // Some classes for the data structure
-
- template <typename Alloc>
- struct bucket_impl
- {
- private:
- bucket_impl& operator=(bucket_impl const&);
- public:
- typedef BOOST_DEDUCED_TYPENAME
- boost::unordered_detail::rebind_wrap<Alloc, bucket_impl>::type
- bucket_allocator;
- typedef BOOST_DEDUCED_TYPENAME
- allocator_pointer<bucket_allocator>::type bucket_ptr;
- typedef bucket_ptr link_ptr;
-
- link_ptr next_;
-
- bucket_impl() : next_()
- {
- BOOST_UNORDERED_MSVC_RESET_PTR(next_);
- }
-
- bucket_impl(bucket_impl const& x) : next_(x.next_)
- {
- // Only copy construct when allocating.
- BOOST_ASSERT(!x.next_);
- }
-
- bool empty() const
- {
- return !this->next_;
- }
- };
-
- template <typename T>
- struct value_base {
- typename boost::aligned_storage<
- sizeof(T),
- boost::alignment_of<T>::value>::type data_;
-
- void* address() { return this; }
- };
+#endif
     }
 }
 

Modified: branches/release/boost/unordered/detail/hash_table_impl.hpp
==============================================================================
--- branches/release/boost/unordered/detail/hash_table_impl.hpp (original)
+++ branches/release/boost/unordered/detail/hash_table_impl.hpp 2009-03-30 13:54:49 EDT (Mon, 30 Mar 2009)
@@ -6,7 +6,6 @@
 
 #if BOOST_UNORDERED_EQUIVALENT_KEYS
 #define BOOST_UNORDERED_TABLE hash_table_equivalent_keys
-#define BOOST_UNORDERED_TABLE_NODE node_equivalent_keys
 #define BOOST_UNORDERED_TABLE_DATA hash_table_data_equivalent_keys
 #define BOOST_UNORDERED_ITERATOR hash_iterator_equivalent_keys
 #define BOOST_UNORDERED_CONST_ITERATOR hash_const_iterator_equivalent_keys
@@ -14,7 +13,6 @@
 #define BOOST_UNORDERED_CONST_LOCAL_ITERATOR hash_const_local_iterator_equivalent_keys
 #else
 #define BOOST_UNORDERED_TABLE hash_table_unique_keys
-#define BOOST_UNORDERED_TABLE_NODE node_unique_keys
 #define BOOST_UNORDERED_TABLE_DATA hash_table_data_unique_keys
 #define BOOST_UNORDERED_ITERATOR hash_iterator_unique_keys
 #define BOOST_UNORDERED_CONST_ITERATOR hash_const_iterator_unique_keys
@@ -25,32 +23,6 @@
 namespace boost {
     namespace unordered_detail {
 
- template <typename Alloc>
- struct BOOST_UNORDERED_TABLE_NODE :
- value_base<BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type>,
- bucket_impl<Alloc>
- {
- typedef BOOST_DEDUCED_TYPENAME bucket_impl<Alloc>::link_ptr link_ptr;
- typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type value_type;
-
- typedef BOOST_DEDUCED_TYPENAME
- boost::unordered_detail::rebind_wrap<Alloc, BOOST_UNORDERED_TABLE_NODE>::type
- node_allocator;
-
-#if BOOST_UNORDERED_EQUIVALENT_KEYS
- BOOST_UNORDERED_TABLE_NODE() : group_prev_()
- {
- BOOST_UNORDERED_MSVC_RESET_PTR(group_prev_);
- }
-
- link_ptr group_prev_;
-#endif
-
- value_type& value() {
- return *static_cast<value_type*>(this->address());
- }
- };
-
         //
         // Hash Table Data
         //
@@ -62,24 +34,86 @@
         public:
             typedef BOOST_UNORDERED_TABLE_DATA data;
 
+ struct node;
+ struct bucket;
             typedef std::size_t size_type;
             typedef std::ptrdiff_t difference_type;
 
             typedef Alloc value_allocator;
 
- typedef bucket_impl<Alloc> bucket;
- typedef BOOST_DEDUCED_TYPENAME bucket::bucket_allocator bucket_allocator;
- typedef BOOST_DEDUCED_TYPENAME bucket::bucket_ptr bucket_ptr;
- typedef BOOST_DEDUCED_TYPENAME bucket::link_ptr link_ptr;
-
- typedef BOOST_UNORDERED_TABLE_NODE<Alloc> node;
- typedef BOOST_DEDUCED_TYPENAME node::node_allocator node_allocator;
+ typedef BOOST_DEDUCED_TYPENAME
+ boost::unordered_detail::rebind_wrap<Alloc, node>::type
+ node_allocator;
+ typedef BOOST_DEDUCED_TYPENAME
+ boost::unordered_detail::rebind_wrap<Alloc, bucket>::type
+ bucket_allocator;
 
             typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Alloc>::type value_type;
             typedef BOOST_DEDUCED_TYPENAME allocator_pointer<node_allocator>::type node_ptr;
+ typedef BOOST_DEDUCED_TYPENAME allocator_pointer<bucket_allocator>::type bucket_ptr;
             typedef BOOST_DEDUCED_TYPENAME allocator_reference<value_allocator>::type reference;
             typedef BOOST_DEDUCED_TYPENAME allocator_reference<bucket_allocator>::type bucket_reference;
 
+ typedef bucket_ptr link_ptr;
+
+ // Hash Bucket
+ //
+ // all no throw
+
+ struct bucket
+ {
+ private:
+ bucket& operator=(bucket const&);
+ public:
+ link_ptr next_;
+
+ bucket() : next_()
+ {
+ BOOST_UNORDERED_MSVC_RESET_PTR(next_);
+ }
+
+ bucket(bucket const& x) : next_(x.next_)
+ {
+ // Only copy construct when allocating.
+ BOOST_ASSERT(!x.next_);
+ }
+
+ bool empty() const
+ {
+ return !this->next_;
+ }
+ };
+
+ // Value Base
+
+ struct value_base {
+ typename boost::aligned_storage<
+ sizeof(value_type),
+ boost::alignment_of<value_type>::value>::type data_;
+
+ void* address() { return this; }
+ };
+
+ // Hash Node
+ //
+ // all no throw
+
+ struct node : value_base, bucket {
+#if BOOST_UNORDERED_EQUIVALENT_KEYS
+ public:
+ node() : group_prev_()
+ {
+ BOOST_UNORDERED_MSVC_RESET_PTR(group_prev_);
+ }
+
+ link_ptr group_prev_;
+#endif
+
+ value_type& value() {
+ return *static_cast<value_type*>(this->address());
+ }
+ };
+
             // allocators
             //
             // Stores all the allocators that we're going to need.
@@ -96,7 +130,7 @@
                 void destroy(link_ptr ptr)
                 {
                     node* raw_ptr = static_cast<node*>(&*ptr);
- boost::unordered_detail::destroy(&raw_ptr->value());
+ BOOST_UNORDERED_DESTRUCT(&raw_ptr->value(), value_type);
                     node_ptr n(node_alloc_.address(*raw_ptr));
                     node_alloc_.destroy(n);
                     node_alloc_.deallocate(n, 1);
@@ -138,7 +172,7 @@
                 {
                     if (node_) {
                         if (value_constructed_) {
- boost::unordered_detail::destroy(&node_->value());
+ BOOST_UNORDERED_DESTRUCT(&node_->value(), value_type);
                         }
 
                         if (node_constructed_)
@@ -2291,7 +2325,6 @@
 }
 
 #undef BOOST_UNORDERED_TABLE
-#undef BOOST_UNORDERED_TABLE_NODE
 #undef BOOST_UNORDERED_TABLE_DATA
 #undef BOOST_UNORDERED_ITERATOR
 #undef BOOST_UNORDERED_CONST_ITERATOR


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