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

[SVN r42612]
This commit is contained in:
Daniel James
2008-01-08 13:59:01 +00:00
parent dfac5aab41
commit e847046f95
5 changed files with 37 additions and 40 deletions
+18 -14
View File
@@ -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<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 @@ 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 {
+14 -21
View File
@@ -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<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 @@ namespace minimal
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_; }
+1 -1
View File
@@ -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 {