|
Boost-Commit : |
From: daniel_james_at_[hidden]
Date: 2008-04-20 08:10:59
Author: danieljames
Date: 2008-04-20 08:10:56 EDT (Sun, 20 Apr 2008)
New Revision: 44614
URL: http://svn.boost.org/trac/boost/changeset/44614
Log:
Merge in fix for the swap tests, and rename allocator.
Merged revisions 44512-44515,44517-44536 via svnmerge from
https://svn.boost.org/svn/boost/branches/unordered/trunk
................
r44512 | danieljames | 2008-04-17 20:03:00 +0100 (Thu, 17 Apr 2008) | 11 lines
Rename allocator.hpp.
................
r44536 | danieljames | 2008-04-18 11:27:50 +0100 (Fri, 18 Apr 2008) | 1 line
Check that hash_table_impl::swap isn't swapping with itself - which is causing the buffered functions to be set with the same value twice, resulting in an assertion.
................
Added:
trunk/boost/unordered/detail/allocator_helpers.hpp
- copied unchanged from r44512, /branches/unordered/trunk/boost/unordered/detail/allocator_helpers.hpp
Removed:
trunk/boost/unordered/detail/allocator.hpp
Properties modified:
trunk/ (props changed)
Text files modified:
trunk/boost/unordered/detail/hash_table.hpp | 2 +-
trunk/boost/unordered/detail/hash_table_impl.hpp | 17 ++++++++++++-----
2 files changed, 13 insertions(+), 6 deletions(-)
Deleted: trunk/boost/unordered/detail/allocator.hpp
==============================================================================
--- trunk/boost/unordered/detail/allocator.hpp 2008-04-20 08:10:56 EDT (Sun, 20 Apr 2008)
+++ (empty file)
@@ -1,237 +0,0 @@
-
-// Copyright 2005-2008 Daniel James.
-// 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)
-
-#ifndef BOOST_UNORDERED_DETAIL_ALLOCATOR_UTILITIES_HPP_INCLUDED
-#define BOOST_UNORDERED_DETAIL_ALLOCATOR_UTILITIES_HPP_INCLUDED
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#include <boost/config.hpp>
-
-#if (defined(BOOST_NO_STD_ALLOCATOR) || defined(BOOST_DINKUMWARE_STDLIB)) \
- && !defined(__BORLANDC__)
-# define BOOST_UNORDERED_USE_ALLOCATOR_UTILITIES
-#endif
-
-#if defined(BOOST_UNORDERED_USE_ALLOCATOR_UTILITIES)
-# include <boost/detail/allocator_utilities.hpp>
-#endif
-
-#include <boost/mpl/aux_/config/eti.hpp>
-
-namespace boost {
- namespace unordered_detail {
-
-#if defined(BOOST_UNORDERED_USE_ALLOCATOR_UTILITIES)
- template <class Alloc, class T>
- struct rebind_wrap : ::boost::detail::allocator::rebind_to<Alloc, T> {};
-#else
- template <class Alloc, class T>
- struct rebind_wrap
- {
- typedef BOOST_DEDUCED_TYPENAME
- Alloc::BOOST_NESTED_TEMPLATE rebind<T>::other
- type;
- };
-#endif
-
-#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- template <class T>
- inline void reset(T& x) { x = T(); }
-
- template <class Ptr>
- inline Ptr null_ptr() { return Ptr(); }
-#else
- template <class T>
- inline void reset_impl(T& x, ...) { x = T(); }
- template <class T>
- inline void reset_impl(T*& x, int) { x = 0; }
- template <class T>
- inline void reset(T& x) { reset_impl(x); }
-
- template <class Ptr>
- inline Ptr null_ptr() { Ptr x; reset(x); return x; }
-#endif
-
- // Work around for Microsoft's ETI bug.
-
- template <class Allocator> struct allocator_value_type
- {
- typedef BOOST_DEDUCED_TYPENAME Allocator::value_type type;
- };
-
- template <class Allocator> struct allocator_pointer
- {
- typedef BOOST_DEDUCED_TYPENAME Allocator::pointer type;
- };
-
- template <class Allocator> struct allocator_const_pointer
- {
- typedef BOOST_DEDUCED_TYPENAME Allocator::const_pointer type;
- };
-
- template <class Allocator> struct allocator_reference
- {
- typedef BOOST_DEDUCED_TYPENAME Allocator::reference type;
- };
-
- template <class Allocator> struct allocator_const_reference
- {
- typedef BOOST_DEDUCED_TYPENAME Allocator::const_reference type;
- };
-
-#if defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
-
- template <>
- struct allocator_value_type<int>
- {
- typedef int type;
- };
-
- template <>
- struct allocator_pointer<int>
- {
- typedef int type;
- };
-
- template <>
- struct allocator_const_pointer<int>
- {
- typedef int type;
- };
-
- template <>
- struct allocator_reference<int>
- {
- typedef int type;
- };
-
- template <>
- struct allocator_const_reference<int>
- {
- typedef int type;
- };
-
-#endif
-
- template <class Allocator>
- struct allocator_constructor
- {
- typedef BOOST_DEDUCED_TYPENAME allocator_value_type<Allocator>::type value_type;
- typedef BOOST_DEDUCED_TYPENAME allocator_pointer<Allocator>::type pointer;
-
- Allocator& alloc_;
- pointer ptr_;
- bool constructed_;
-
- allocator_constructor(Allocator& a)
- : alloc_(a), ptr_(), constructed_(false)
- {
-#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- unordered_detail::reset(ptr_);
-#endif
- }
-
- ~allocator_constructor() {
- if(ptr_) {
- if(constructed_) alloc_.destroy(ptr_);
- alloc_.deallocate(ptr_, 1);
- }
- }
-
- template <class V>
- void construct(V const& v) {
- BOOST_ASSERT(!ptr_ && !constructed_);
- ptr_ = alloc_.allocate(1);
- alloc_.construct(ptr_, value_type(v));
- constructed_ = true;
- }
-
- void construct(value_type const& v) {
- BOOST_ASSERT(!ptr_ && !constructed_);
- ptr_ = alloc_.allocate(1);
- alloc_.construct(ptr_, v);
- constructed_ = true;
- }
-
- pointer get() const
- {
- return ptr_;
- }
-
- // no throw
- pointer release()
- {
- pointer p = ptr_;
- constructed_ = false;
- unordered_detail::reset(ptr_);
- return p;
- }
- };
-
- template <class Allocator>
- struct allocator_array_constructor
- {
- typedef BOOST_DEDUCED_TYPENAME allocator_pointer<Allocator>::type pointer;
-
- Allocator& alloc_;
- pointer ptr_;
- pointer constructed_;
- std::size_t length_;
-
- allocator_array_constructor(Allocator& a)
- : alloc_(a), ptr_(), constructed_(), length_(0)
- {
-#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- unordered_detail::reset(constructed_);
- unordered_detail::reset(ptr_);
-#endif
- }
-
- ~allocator_array_constructor() {
- if (ptr_) {
- for(pointer p = ptr_; p != constructed_; ++p)
- alloc_.destroy(p);
-
- alloc_.deallocate(ptr_, length_);
- }
- }
-
- template <class V>
- void construct(V const& v, std::size_t l)
- {
- BOOST_ASSERT(!ptr_);
- length_ = l;
- ptr_ = alloc_.allocate(length_);
- pointer end = ptr_ + static_cast<std::ptrdiff_t>(length_);
- for(constructed_ = ptr_; constructed_ != end; ++constructed_)
- alloc_.construct(constructed_, v);
- }
-
- pointer get() const
- {
- return ptr_;
- }
-
- pointer release()
- {
- pointer p(ptr_);
- unordered_detail::reset(ptr_);
- return p;
- }
- private:
- allocator_array_constructor(allocator_array_constructor const&);
- allocator_array_constructor& operator=(allocator_array_constructor const&);
- };
- }
-}
-
-#if defined(BOOST_UNORDERED_USE_ALLOCATOR_UTILITIES)
-# undef BOOST_UNORDERED_USE_ALLOCATOR_UTILITIES
-#endif
-
-#endif
Modified: trunk/boost/unordered/detail/hash_table.hpp
==============================================================================
--- trunk/boost/unordered/detail/hash_table.hpp (original)
+++ trunk/boost/unordered/detail/hash_table.hpp 2008-04-20 08:10:56 EDT (Sun, 20 Apr 2008)
@@ -24,7 +24,7 @@
#include <boost/limits.hpp>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
-#include <boost/unordered/detail/allocator.hpp>
+#include <boost/unordered/detail/allocator_helpers.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/and.hpp>
Modified: trunk/boost/unordered/detail/hash_table_impl.hpp
==============================================================================
--- trunk/boost/unordered/detail/hash_table_impl.hpp (original)
+++ trunk/boost/unordered/detail/hash_table_impl.hpp 2008-04-20 08:10:56 EDT (Sun, 20 Apr 2008)
@@ -694,7 +694,7 @@
BOOST_ASSERT(base == end.bucket_);
split_group(end.node_);
-
+
link_ptr ptr(base->next_);
base->next_ = end.node_;
@@ -1147,7 +1147,7 @@
//
// Swap's behaviour when allocators aren't equal is in dispute, for
// details see:
- //
+ //
// http://unordered.nfshost.com/doc/html/unordered/rationale.html#swapping_containers_with_unequal_allocators
//
// ----------------------------------------------------------------
@@ -1159,6 +1159,13 @@
void swap(BOOST_UNORDERED_TABLE& x)
{
+ // The swap code can work when swapping a container with itself
+ // but it triggers an assertion in buffered_functions.
+ // At the moment, I'd rather leave that assertion in and add a
+ // check here, rather than remove the assertion. I might change
+ // this at a later date.
+ if(this == &x) return;
+
// These can throw, but they only affect the function objects
// that aren't in use so it is strongly exception safe, via.
// double buffering.
@@ -1669,7 +1676,7 @@
size_type hash_value = hash_function()(k);
bucket_ptr bucket = data_.bucket_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>(
@@ -1744,7 +1751,7 @@
size_type hash_value = hash_function()(extract_key(*i));
bucket_ptr bucket = data_.bucket_from_hash(hash_value);
link_ptr pos = find_iterator(bucket, extract_key(*i));
-
+
if (!BOOST_UNORDERED_BORLAND_BOOL(pos)) {
// Doesn't already exist, add to bucket.
// Side effects only in this block.
@@ -1871,7 +1878,7 @@
};
// Iterators
-
+
template <typename Alloc> class BOOST_UNORDERED_ITERATOR;
template <typename Alloc> class BOOST_UNORDERED_CONST_ITERATOR;
template <typename Alloc> class BOOST_UNORDERED_LOCAL_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