Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-01-08 08:59:01


Author: danieljames
Date: 2008-01-08 08:59:01 EST (Tue, 08 Jan 2008)
New Revision: 42612
URL: http://svn.boost.org/trac/boost/changeset/42612

Log:
Merge in latest unordered developments (revisions 42607-42611).

Text files modified:
   trunk/boost/unordered/detail/allocator.hpp | 2 +-
   trunk/boost/unordered/detail/hash_table.hpp | 6 +++---
   trunk/libs/unordered/test/objects/exception.hpp | 32 ++++++++++++++++++--------------
   trunk/libs/unordered/test/objects/minimal.hpp | 35 ++++++++++++++---------------------
   trunk/libs/unordered/test/objects/test.hpp | 2 +-
   5 files changed, 37 insertions(+), 40 deletions(-)

Modified: trunk/boost/unordered/detail/allocator.hpp
==============================================================================
--- trunk/boost/unordered/detail/allocator.hpp (original)
+++ trunk/boost/unordered/detail/allocator.hpp 2008-01-08 08:59:01 EST (Tue, 08 Jan 2008)
@@ -207,7 +207,7 @@
                 BOOST_ASSERT(!ptr_);
                 length_ = l;
                 ptr_ = alloc_.allocate(length_);
- pointer end = ptr_ + length_;
+ pointer end = ptr_ + static_cast<std::ptrdiff_t>(length_);
                 for(constructed_ = ptr_; constructed_ != end; ++constructed_)
                     alloc_.construct(constructed_, v);
             }

Modified: trunk/boost/unordered/detail/hash_table.hpp
==============================================================================
--- trunk/boost/unordered/detail/hash_table.hpp (original)
+++ trunk/boost/unordered/detail/hash_table.hpp 2008-01-08 08:59:01 EST (Tue, 08 Jan 2008)
@@ -48,8 +48,8 @@
     namespace unordered_detail {
         template <class T> struct type_wrapper {};
 
- const static std::size_t default_initial_bucket_count = 50;
- const static float minimum_max_load_factor = 1e-3f;
+ static const std::size_t default_initial_bucket_count = 50;
+ static const float minimum_max_load_factor = 1e-3f;
         inline std::size_t next_prime(std::size_t n);
 
         template <class T>
@@ -65,7 +65,7 @@
 
         inline std::size_t float_to_size_t(float f)
         {
- return f > static_cast<float>((std::numeric_limits<std::size_t>::max)()) ?
+ return f >= static_cast<float>((std::numeric_limits<std::size_t>::max)()) ?
                 (std::numeric_limits<std::size_t>::max)() :
                 static_cast<std::size_t>(f);
         }

Modified: trunk/libs/unordered/test/objects/exception.hpp
==============================================================================
--- trunk/libs/unordered/test/objects/exception.hpp (original)
+++ trunk/libs/unordered/test/objects/exception.hpp 2008-01-08 08:59:01 EST (Tue, 08 Jan 2008)
@@ -192,18 +192,7 @@
                 memory_area(void const* s, void const* e)
                     : start(s), end(e)
                 {
- }
-
- // This is a bit dodgy as it defines overlapping
- // areas as 'equal', so this isn't a total ordering.
- // But it is for non-overlapping memory regions - which
- // is what'll be stored.
- //
- // All searches will be for areas entirely contained by
- // a member of the set - so it should find the area that contains
- // the region that is searched for.
- bool operator<(memory_area const& other) const {
- return end < other.start;
+ BOOST_ASSERT(start != end);
                 }
             };
 
@@ -214,7 +203,22 @@
                 int tag_;
             };
 
- typedef std::map<memory_area, memory_track, std::less<memory_area>,
+ // This is a bit dodgy as it defines overlapping
+ // areas as 'equal', so this isn't a total ordering.
+ // But it is for non-overlapping memory regions - which
+ // is what'll be stored.
+ //
+ // All searches will be for areas entirely contained by
+ // a member of the set - so it should find the area that contains
+ // the region that is searched for.
+
+ struct memory_area_compare {
+ bool operator()(memory_area const& x, memory_area const& y) const {
+ return x.end <= y.start;
+ }
+ };
+
+ typedef std::map<memory_area, memory_track, memory_area_compare,
                 test::malloc_allocator<std::pair<memory_area const, memory_track> > >
                 allocated_memory_type;
             allocated_memory_type allocated_memory;
@@ -270,7 +274,7 @@
         void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
         {
             allocated_memory_type::iterator pos
- = allocated_memory.find(memory_area(ptr, ptr));
+ = allocated_memory.find(memory_area(ptr, (char*) ptr + n * size));
             if(pos == allocated_memory.end()) {
                 BOOST_ERROR("Deallocating unknown pointer.");
             } else {

Modified: trunk/libs/unordered/test/objects/minimal.hpp
==============================================================================
--- trunk/libs/unordered/test/objects/minimal.hpp (original)
+++ trunk/libs/unordered/test/objects/minimal.hpp 2008-01-08 08:59:01 EST (Tue, 08 Jan 2008)
@@ -3,6 +3,10 @@
 // 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)
 
+// Define some minimal classes which provide the bare minimum concepts to
+// test that the containers don't rely on something that they shouldn't.
+// They are not intended to be good examples of how to implement the concepts.
+
 #if !defined(BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER)
 #define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
 
@@ -100,22 +104,18 @@
     public:
         ptr() : ptr_(0) {}
 
- typedef void (ptr::*bool_type)() const;
- void this_type_does_not_support_comparisons() const {}
-
         T& operator*() const { return *ptr_; }
         T* operator->() const { return ptr_; }
         ptr& operator++() { ++ptr_; return *this; }
         ptr operator++(int) { ptr tmp(*this); ++ptr_; return tmp; }
- ptr operator+(int s) const { return ptr<T>(ptr_ + s); }
- T& operator[](int s) const { return ptr_[s]; }
+ ptr operator+(std::ptrdiff_t s) const { return ptr<T>(ptr_ + s); }
+ friend ptr operator+(std::ptrdiff_t s, ptr p) { return ptr<T>(s + p.ptr_); }
+ T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
         bool operator!() const { return !ptr_; }
-
- operator bool_type() const {
- return ptr_ ?
- &ptr::this_type_does_not_support_comparisons
- : 0;
- }
+
+ // I'm not using the safe bool idiom because the containers should be
+ // able to cope with bool conversions.
+ operator bool() const { return !!ptr_; }
 
         bool operator==(ptr const& x) const { return ptr_ == x.ptr_; }
         bool operator!=(ptr const& x) const { return ptr_ != x.ptr_; }
@@ -144,22 +144,15 @@
         const_ptr() : ptr_(0) {}
         const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
 
- typedef void (const_ptr::*bool_type)() const;
- void this_type_does_not_support_comparisons() const {}
-
         T const& operator*() const { return *ptr_; }
         T const* operator->() const { return ptr_; }
         const_ptr& operator++() { ++ptr_; return *this; }
         const_ptr operator++(int) { const_ptr tmp(*this); ++ptr_; return tmp; }
- const_ptr operator+(int s) const { return const_ptr(ptr_ + s); }
+ const_ptr operator+(std::ptrdiff_t s) const { return const_ptr(ptr_ + s); }
+ friend const_ptr operator+(std::ptrdiff_t s, const_ptr p) { return ptr<T>(s + p.ptr_); }
         T const& operator[](int s) const { return ptr_[s]; }
         bool operator!() const { return !ptr_; }
-
- operator bool_type() const {
- return ptr_ ?
- &const_ptr::this_type_does_not_support_comparisons
- : 0;
- }
+ operator bool() const { return !!ptr_; }
 
         bool operator==(ptr<T> const& x) const { return ptr_ == x.ptr_; }
         bool operator!=(ptr<T> const& x) const { return ptr_ != x.ptr_; }

Modified: trunk/libs/unordered/test/objects/test.hpp
==============================================================================
--- trunk/libs/unordered/test/objects/test.hpp (original)
+++ trunk/libs/unordered/test/objects/test.hpp 2008-01-08 08:59:01 EST (Tue, 08 Jan 2008)
@@ -297,7 +297,7 @@
         void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
         {
             allocated_memory_type::iterator pos
- = allocated_memory.find(memory_area(ptr, (char*) ptr + n));
+ = allocated_memory.find(memory_area(ptr, (char*) ptr + n * size));
             if(pos == allocated_memory.end()) {
                 BOOST_ERROR("Deallocating unknown pointer.");
             } else {


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