mirror of
https://github.com/boostorg/unordered.git
synced 2025-08-01 04:14:29 +02:00
Merge in latest unordered developments (revisions 42607-42611).
[SVN r42612]
This commit is contained in:
@@ -207,7 +207,7 @@ namespace boost {
|
|||||||
BOOST_ASSERT(!ptr_);
|
BOOST_ASSERT(!ptr_);
|
||||||
length_ = l;
|
length_ = l;
|
||||||
ptr_ = alloc_.allocate(length_);
|
ptr_ = alloc_.allocate(length_);
|
||||||
pointer end = ptr_ + length_;
|
pointer end = ptr_ + static_cast<std::ptrdiff_t>(length_);
|
||||||
for(constructed_ = ptr_; constructed_ != end; ++constructed_)
|
for(constructed_ = ptr_; constructed_ != end; ++constructed_)
|
||||||
alloc_.construct(constructed_, v);
|
alloc_.construct(constructed_, v);
|
||||||
}
|
}
|
||||||
|
@@ -48,8 +48,8 @@ namespace boost {
|
|||||||
namespace unordered_detail {
|
namespace unordered_detail {
|
||||||
template <class T> struct type_wrapper {};
|
template <class T> struct type_wrapper {};
|
||||||
|
|
||||||
const static std::size_t default_initial_bucket_count = 50;
|
static const std::size_t default_initial_bucket_count = 50;
|
||||||
const static float minimum_max_load_factor = 1e-3f;
|
static const float minimum_max_load_factor = 1e-3f;
|
||||||
inline std::size_t next_prime(std::size_t n);
|
inline std::size_t next_prime(std::size_t n);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -65,7 +65,7 @@ namespace boost {
|
|||||||
|
|
||||||
inline std::size_t float_to_size_t(float f)
|
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)() :
|
(std::numeric_limits<std::size_t>::max)() :
|
||||||
static_cast<std::size_t>(f);
|
static_cast<std::size_t>(f);
|
||||||
}
|
}
|
||||||
|
@@ -192,18 +192,7 @@ namespace exception
|
|||||||
memory_area(void const* s, void const* e)
|
memory_area(void const* s, void const* e)
|
||||||
: start(s), end(e)
|
: start(s), end(e)
|
||||||
{
|
{
|
||||||
}
|
BOOST_ASSERT(start != end);
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -214,7 +203,22 @@ namespace exception
|
|||||||
int tag_;
|
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> > >
|
test::malloc_allocator<std::pair<memory_area const, memory_track> > >
|
||||||
allocated_memory_type;
|
allocated_memory_type;
|
||||||
allocated_memory_type allocated_memory;
|
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)
|
void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
|
||||||
{
|
{
|
||||||
allocated_memory_type::iterator pos
|
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()) {
|
if(pos == allocated_memory.end()) {
|
||||||
BOOST_ERROR("Deallocating unknown pointer.");
|
BOOST_ERROR("Deallocating unknown pointer.");
|
||||||
} else {
|
} else {
|
||||||
|
@@ -3,6 +3,10 @@
|
|||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
// 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)
|
// 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)
|
#if !defined(BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER)
|
||||||
#define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
|
#define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
|
||||||
|
|
||||||
@@ -100,22 +104,18 @@ namespace minimal
|
|||||||
public:
|
public:
|
||||||
ptr() : ptr_(0) {}
|
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_; }
|
||||||
T* operator->() const { return ptr_; }
|
T* operator->() const { return ptr_; }
|
||||||
ptr& operator++() { ++ptr_; return *this; }
|
ptr& operator++() { ++ptr_; return *this; }
|
||||||
ptr operator++(int) { ptr tmp(*this); ++ptr_; return tmp; }
|
ptr operator++(int) { ptr tmp(*this); ++ptr_; return tmp; }
|
||||||
ptr operator+(int s) const { return ptr<T>(ptr_ + s); }
|
ptr operator+(std::ptrdiff_t s) const { return ptr<T>(ptr_ + s); }
|
||||||
T& operator[](int s) const { return 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_; }
|
bool operator!() const { return !ptr_; }
|
||||||
|
|
||||||
operator bool_type() const {
|
// I'm not using the safe bool idiom because the containers should be
|
||||||
return ptr_ ?
|
// able to cope with bool conversions.
|
||||||
&ptr::this_type_does_not_support_comparisons
|
operator bool() const { return !!ptr_; }
|
||||||
: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(ptr const& x) const { return ptr_ == x.ptr_; }
|
bool operator==(ptr const& x) const { return ptr_ == x.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_(0) {}
|
||||||
const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
|
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_; }
|
||||||
T const* operator->() const { return ptr_; }
|
T const* operator->() const { return ptr_; }
|
||||||
const_ptr& operator++() { ++ptr_; return *this; }
|
const_ptr& operator++() { ++ptr_; return *this; }
|
||||||
const_ptr operator++(int) { const_ptr tmp(*this); ++ptr_; return tmp; }
|
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]; }
|
T const& operator[](int s) const { return ptr_[s]; }
|
||||||
bool operator!() const { return !ptr_; }
|
bool operator!() const { return !ptr_; }
|
||||||
|
operator bool() const { return !!ptr_; }
|
||||||
operator bool_type() const {
|
|
||||||
return ptr_ ?
|
|
||||||
&const_ptr::this_type_does_not_support_comparisons
|
|
||||||
: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(ptr<T> const& x) const { return ptr_ == x.ptr_; }
|
bool operator==(ptr<T> const& x) const { return ptr_ == x.ptr_; }
|
||||||
bool operator!=(ptr<T> const& x) const { return ptr_ != x.ptr_; }
|
bool operator!=(ptr<T> const& x) const { return ptr_ != x.ptr_; }
|
||||||
|
@@ -297,7 +297,7 @@ namespace test
|
|||||||
void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
|
void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
|
||||||
{
|
{
|
||||||
allocated_memory_type::iterator pos
|
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()) {
|
if(pos == allocated_memory.end()) {
|
||||||
BOOST_ERROR("Deallocating unknown pointer.");
|
BOOST_ERROR("Deallocating unknown pointer.");
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user