From e847046f9553f04e5f6bfa3712194136f1dbff6d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 8 Jan 2008 13:59:01 +0000 Subject: [PATCH] Merge in latest unordered developments (revisions 42607-42611). [SVN r42612] --- include/boost/unordered/detail/allocator.hpp | 2 +- include/boost/unordered/detail/hash_table.hpp | 6 ++-- test/objects/exception.hpp | 32 +++++++++-------- test/objects/minimal.hpp | 35 ++++++++----------- test/objects/test.hpp | 2 +- 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/include/boost/unordered/detail/allocator.hpp b/include/boost/unordered/detail/allocator.hpp index e7dd8d11..0d873a17 100644 --- a/include/boost/unordered/detail/allocator.hpp +++ b/include/boost/unordered/detail/allocator.hpp @@ -207,7 +207,7 @@ namespace boost { BOOST_ASSERT(!ptr_); length_ = l; ptr_ = alloc_.allocate(length_); - pointer end = ptr_ + length_; + pointer end = ptr_ + static_cast(length_); for(constructed_ = ptr_; constructed_ != end; ++constructed_) alloc_.construct(constructed_, v); } diff --git a/include/boost/unordered/detail/hash_table.hpp b/include/boost/unordered/detail/hash_table.hpp index 9f9e4e49..7eb895de 100644 --- a/include/boost/unordered/detail/hash_table.hpp +++ b/include/boost/unordered/detail/hash_table.hpp @@ -48,8 +48,8 @@ namespace boost { namespace unordered_detail { template 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 @@ -65,7 +65,7 @@ namespace boost { inline std::size_t float_to_size_t(float f) { - return f > static_cast((std::numeric_limits::max)()) ? + return f >= static_cast((std::numeric_limits::max)()) ? (std::numeric_limits::max)() : static_cast(f); } diff --git a/test/objects/exception.hpp b/test/objects/exception.hpp index 8bb50a7b..abdf1f8e 100644 --- a/test/objects/exception.hpp +++ b/test/objects/exception.hpp @@ -192,18 +192,7 @@ namespace exception 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 @@ namespace exception int tag_; }; - typedef std::map, + // 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 > > allocated_memory_type; allocated_memory_type allocated_memory; @@ -270,7 +274,7 @@ namespace exception 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 { diff --git a/test/objects/minimal.hpp b/test/objects/minimal.hpp index 2932b387..257a5d75 100644 --- a/test/objects/minimal.hpp +++ b/test/objects/minimal.hpp @@ -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 @@ namespace minimal 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(ptr_ + s); } - T& operator[](int s) const { return ptr_[s]; } + ptr operator+(std::ptrdiff_t s) const { return ptr(ptr_ + s); } + friend ptr operator+(std::ptrdiff_t s, ptr p) { return ptr(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 @@ namespace minimal const_ptr() : ptr_(0) {} const_ptr(ptr 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(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 const& x) const { return ptr_ == x.ptr_; } bool operator!=(ptr const& x) const { return ptr_ != x.ptr_; } diff --git a/test/objects/test.hpp b/test/objects/test.hpp index abea10e9..584ff0fe 100644 --- a/test/objects/test.hpp +++ b/test/objects/test.hpp @@ -297,7 +297,7 @@ namespace test 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 {