[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,344 @@
// Copyright 2006-2011 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)
#if !defined(BOOST_UNORDERED_TEST_CXX11_ALLOCATOR_HEADER)
#define BOOST_UNORDERED_TEST_CXX11_ALLOCATOR_HEADER
#include <boost/config.hpp>
#include <boost/limits.hpp>
#include <cstddef>
#include "../helpers/fwd.hpp"
#include "../helpers/memory.hpp"
namespace test {
struct allocator_false
{
enum
{
is_select_on_copy = 0,
is_propagate_on_swap = 0,
is_propagate_on_assign = 0,
is_propagate_on_move = 0,
cxx11_construct = 0
};
};
struct allocator_flags_all
{
enum
{
is_select_on_copy = 1,
is_propagate_on_swap = 1,
is_propagate_on_assign = 1,
is_propagate_on_move = 1,
cxx11_construct = 1
};
};
struct select_copy : allocator_false
{
enum
{
is_select_on_copy = 1
};
};
struct propagate_swap : allocator_false
{
enum
{
is_propagate_on_swap = 1
};
};
struct propagate_assign : allocator_false
{
enum
{
is_propagate_on_assign = 1
};
};
struct propagate_move : allocator_false
{
enum
{
is_propagate_on_move = 1
};
};
struct no_select_copy : allocator_flags_all
{
enum
{
is_select_on_copy = 0
};
};
struct no_propagate_swap : allocator_flags_all
{
enum
{
is_propagate_on_swap = 0
};
};
struct no_propagate_assign : allocator_flags_all
{
enum
{
is_propagate_on_assign = 0
};
};
struct no_propagate_move : allocator_flags_all
{
enum
{
is_propagate_on_move = 0
};
};
template <typename Flag> struct swap_allocator_base
{
struct propagate_on_container_swap
{
enum
{
value = Flag::is_propagate_on_swap
};
};
};
template <typename Flag> struct assign_allocator_base
{
struct propagate_on_container_copy_assignment
{
enum
{
value = Flag::is_propagate_on_assign
};
};
};
template <typename Flag> struct move_allocator_base
{
struct propagate_on_container_move_assignment
{
enum
{
value = Flag::is_propagate_on_move
};
};
};
namespace {
// boostinspect:nounnamed
bool force_equal_allocator_value = false;
}
struct force_equal_allocator
{
bool old_value_;
explicit force_equal_allocator(bool value)
: old_value_(force_equal_allocator_value)
{
force_equal_allocator_value = value;
}
~force_equal_allocator() { force_equal_allocator_value = old_value_; }
};
template <typename T> struct cxx11_allocator_base
{
int tag_;
int selected_;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T* pointer;
typedef T const* const_pointer;
typedef T& reference;
typedef T const& const_reference;
typedef T value_type;
explicit cxx11_allocator_base(int t) : tag_(t), selected_(0)
{
detail::tracker.allocator_ref();
}
template <typename Y>
cxx11_allocator_base(cxx11_allocator_base<Y> const& x)
: tag_(x.tag_), selected_(x.selected_)
{
detail::tracker.allocator_ref();
}
cxx11_allocator_base(cxx11_allocator_base const& x)
: tag_(x.tag_), selected_(x.selected_)
{
detail::tracker.allocator_ref();
}
~cxx11_allocator_base() { detail::tracker.allocator_unref(); }
pointer address(reference r) { return pointer(&r); }
const_pointer address(const_reference r) { return const_pointer(&r); }
pointer allocate(size_type n)
{
pointer ptr(static_cast<T*>(::operator new(n * sizeof(T))));
detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return ptr;
}
pointer allocate(size_type n, void const*)
{
pointer ptr(static_cast<T*>(::operator new(n * sizeof(T))));
detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return ptr;
}
void deallocate(pointer p, size_type n)
{
// Only checking tags when propagating swap.
// Note that tags will be tested
// properly in the normal allocator.
detail::tracker.track_deallocate(
(void*)p, n, sizeof(T), tag_, !force_equal_allocator_value);
::operator delete((void*)p);
}
void construct(T* p, T const& t)
{
detail::tracker.track_construct((void*)p, sizeof(T), tag_);
new (p) T(t);
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <typename... Args>
void construct(T* p, BOOST_FWD_REF(Args)... args)
{
detail::tracker.track_construct((void*)p, sizeof(T), tag_);
new (p) T(boost::forward<Args>(args)...);
}
#endif
void destroy(T* p)
{
detail::tracker.track_destroy((void*)p, sizeof(T), tag_);
p->~T();
}
size_type max_size() const
{
return (std::numeric_limits<size_type>::max)();
}
};
template <typename T, typename Flags = propagate_swap, typename Enable = void>
struct cxx11_allocator;
template <typename T, typename Flags>
struct cxx11_allocator<T, Flags,
typename boost::disable_if_c<Flags::is_select_on_copy>::type>
: public cxx11_allocator_base<T>,
public swap_allocator_base<Flags>,
public assign_allocator_base<Flags>,
public move_allocator_base<Flags>,
Flags
{
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 402000)
template <typename U> struct rebind
{
typedef cxx11_allocator<U, Flags> other;
};
#endif
explicit cxx11_allocator(int t = 0) : cxx11_allocator_base<T>(t) {}
template <typename Y>
cxx11_allocator(cxx11_allocator<Y, Flags> const& x)
: cxx11_allocator_base<T>(x)
{
}
cxx11_allocator(cxx11_allocator const& x) : cxx11_allocator_base<T>(x) {}
// When not propagating swap, allocators are always equal
// to avoid undefined behaviour.
bool operator==(cxx11_allocator const& x) const
{
return force_equal_allocator_value || (this->tag_ == x.tag_);
}
bool operator!=(cxx11_allocator const& x) const { return !(*this == x); }
};
template <typename T, typename Flags>
struct cxx11_allocator<T, Flags,
typename boost::enable_if_c<Flags::is_select_on_copy>::type>
: public cxx11_allocator_base<T>,
public swap_allocator_base<Flags>,
public assign_allocator_base<Flags>,
public move_allocator_base<Flags>,
Flags
{
cxx11_allocator select_on_container_copy_construction() const
{
cxx11_allocator tmp(*this);
++tmp.selected_;
return tmp;
}
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 402000)
template <typename U> struct rebind
{
typedef cxx11_allocator<U, Flags> other;
};
#endif
explicit cxx11_allocator(int t = 0) : cxx11_allocator_base<T>(t) {}
template <typename Y>
cxx11_allocator(cxx11_allocator<Y, Flags> const& x)
: cxx11_allocator_base<T>(x)
{
}
cxx11_allocator(cxx11_allocator const& x) : cxx11_allocator_base<T>(x) {}
// When not propagating swap, allocators are always equal
// to avoid undefined behaviour.
bool operator==(cxx11_allocator const& x) const
{
return force_equal_allocator_value || (this->tag_ == x.tag_);
}
bool operator!=(cxx11_allocator const& x) const { return !(*this == x); }
};
template <typename T, typename Flags>
bool equivalent_impl(cxx11_allocator<T, Flags> const& x,
cxx11_allocator<T, Flags> const& y, test::derived_type)
{
return x.tag_ == y.tag_;
}
// Function to check how many times an allocator has been selected,
// return 0 for other allocators.
struct convert_from_anything
{
template <typename T> convert_from_anything(T const&) {}
};
inline int selected_count(convert_from_anything) { return 0; }
template <typename T, typename Flags>
int selected_count(cxx11_allocator<T, Flags> const& x)
{
return x.selected_;
}
}
#endif

View File

@@ -0,0 +1,752 @@
// Copyright 2006-2009 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)
#if !defined(BOOST_UNORDERED_EXCEPTION_TEST_OBJECTS_HEADER)
#define BOOST_UNORDERED_EXCEPTION_TEST_OBJECTS_HEADER
#include "../helpers/exception_test.hpp"
#include "../helpers/count.hpp"
#include "../helpers/fwd.hpp"
#include "../helpers/generators.hpp"
#include "../helpers/memory.hpp"
#include "./fwd.hpp"
#include <boost/limits.hpp>
#include <cstddef>
#include <new>
namespace test {
namespace exception {
class object;
class hash;
class equal_to;
template <class T> class allocator;
object generate(object const*, random_generator);
std::pair<object, object> generate(
std::pair<object, object> const*, random_generator);
struct true_type
{
enum
{
value = true
};
};
struct false_type
{
enum
{
value = false
};
};
class object : private counted_object
{
public:
int tag1_, tag2_;
explicit object() : tag1_(0), tag2_(0)
{
UNORDERED_SCOPE(object::object())
{
UNORDERED_EPOINT("Mock object default constructor.");
}
}
explicit object(int t1, int t2 = 0) : tag1_(t1), tag2_(t2)
{
UNORDERED_SCOPE(object::object(int))
{
UNORDERED_EPOINT("Mock object constructor by value.");
}
}
object(object const& x)
: counted_object(x), tag1_(x.tag1_), tag2_(x.tag2_)
{
UNORDERED_SCOPE(object::object(object))
{
UNORDERED_EPOINT("Mock object copy constructor.");
}
}
~object()
{
tag1_ = -1;
tag2_ = -1;
}
object& operator=(object const& x)
{
UNORDERED_SCOPE(object::operator=(object))
{
tag1_ = x.tag1_;
UNORDERED_EPOINT("Mock object assign operator 1.");
tag2_ = x.tag2_;
// UNORDERED_EPOINT("Mock object assign operator 2.");
}
return *this;
}
friend bool operator==(object const& x1, object const& x2)
{
UNORDERED_SCOPE(operator==(object, object))
{
UNORDERED_EPOINT("Mock object equality operator.");
}
return x1.tag1_ == x2.tag1_ && x1.tag2_ == x2.tag2_;
}
friend bool operator!=(object const& x1, object const& x2)
{
UNORDERED_SCOPE(operator!=(object, object))
{
UNORDERED_EPOINT("Mock object inequality operator.");
}
return !(x1.tag1_ == x2.tag1_ && x1.tag2_ == x2.tag2_);
}
// None of the last few functions are used by the unordered associative
// containers - so there aren't any exception points.
friend bool operator<(object const& x1, object const& x2)
{
return x1.tag1_ < x2.tag1_ ||
(x1.tag1_ == x2.tag1_ && x1.tag2_ < x2.tag2_);
}
friend object generate(object const*, random_generator g)
{
int* x = 0;
return object(::test::generate(x, g), ::test::generate(x, g));
}
friend std::ostream& operator<<(std::ostream& out, object const& o)
{
return out << "(" << o.tag1_ << "," << o.tag2_ << ")";
}
};
std::pair<object, object> generate(
std::pair<object, object> const*, random_generator g)
{
int* x = 0;
return std::make_pair(
object(::test::generate(x, g), ::test::generate(x, g)),
object(::test::generate(x, g), ::test::generate(x, g)));
}
class hash
{
int tag_;
public:
hash(int t = 0) : tag_(t)
{
UNORDERED_SCOPE(hash::object())
{
UNORDERED_EPOINT("Mock hash default constructor.");
}
}
hash(hash const& x) : tag_(x.tag_)
{
UNORDERED_SCOPE(hash::hash(hash))
{
UNORDERED_EPOINT("Mock hash copy constructor.");
}
}
hash& operator=(hash const& x)
{
UNORDERED_SCOPE(hash::operator=(hash))
{
UNORDERED_EPOINT("Mock hash assign operator 1.");
tag_ = x.tag_;
UNORDERED_EPOINT("Mock hash assign operator 2.");
}
return *this;
}
std::size_t operator()(object const& x) const
{
UNORDERED_SCOPE(hash::operator()(object))
{
UNORDERED_EPOINT("Mock hash function.");
}
return hash_impl(x);
}
std::size_t operator()(std::pair<object, object> const& x) const
{
UNORDERED_SCOPE(hash::operator()(std::pair<object, object>))
{
UNORDERED_EPOINT("Mock hash pair function.");
}
return hash_impl(x.first) * 193ul + hash_impl(x.second) * 97ul + 29ul;
}
std::size_t hash_impl(object const& x) const
{
int result;
switch (tag_) {
case 1:
result = x.tag1_;
break;
case 2:
result = x.tag2_;
break;
default:
result = x.tag1_ + x.tag2_;
}
return static_cast<std::size_t>(result);
}
friend bool operator==(hash const& x1, hash const& x2)
{
UNORDERED_SCOPE(operator==(hash, hash))
{
UNORDERED_EPOINT("Mock hash equality function.");
}
return x1.tag_ == x2.tag_;
}
friend bool operator!=(hash const& x1, hash const& x2)
{
UNORDERED_SCOPE(hash::operator!=(hash, hash))
{
UNORDERED_EPOINT("Mock hash inequality function.");
}
return x1.tag_ != x2.tag_;
}
};
class less
{
int tag_;
public:
less(int t = 0) : tag_(t) {}
less(less const& x) : tag_(x.tag_) {}
bool operator()(object const& x1, object const& x2) const
{
return less_impl(x1, x2);
}
bool operator()(std::pair<object, object> const& x1,
std::pair<object, object> const& x2) const
{
if (less_impl(x1.first, x2.first)) {
return true;
}
if (!less_impl(x1.first, x2.first)) {
return false;
}
return less_impl(x1.second, x2.second);
}
bool less_impl(object const& x1, object const& x2) const
{
switch (tag_) {
case 1:
return x1.tag1_ < x2.tag1_;
case 2:
return x1.tag2_ < x2.tag2_;
default:
return x1 < x2;
}
}
friend bool operator==(less const& x1, less const& x2)
{
return x1.tag_ == x2.tag_;
}
friend bool operator!=(less const& x1, less const& x2)
{
return x1.tag_ != x2.tag_;
}
};
class equal_to
{
int tag_;
public:
equal_to(int t = 0) : tag_(t)
{
UNORDERED_SCOPE(equal_to::equal_to())
{
UNORDERED_EPOINT("Mock equal_to default constructor.");
}
}
equal_to(equal_to const& x) : tag_(x.tag_)
{
UNORDERED_SCOPE(equal_to::equal_to(equal_to))
{
UNORDERED_EPOINT("Mock equal_to copy constructor.");
}
}
equal_to& operator=(equal_to const& x)
{
UNORDERED_SCOPE(equal_to::operator=(equal_to))
{
UNORDERED_EPOINT("Mock equal_to assign operator 1.");
tag_ = x.tag_;
UNORDERED_EPOINT("Mock equal_to assign operator 2.");
}
return *this;
}
bool operator()(object const& x1, object const& x2) const
{
UNORDERED_SCOPE(equal_to::operator()(object, object))
{
UNORDERED_EPOINT("Mock equal_to function.");
}
return equal_impl(x1, x2);
}
bool operator()(std::pair<object, object> const& x1,
std::pair<object, object> const& x2) const
{
UNORDERED_SCOPE(equal_to::operator()(
std::pair<object, object>, std::pair<object, object>))
{
UNORDERED_EPOINT("Mock equal_to function.");
}
return equal_impl(x1.first, x2.first) &&
equal_impl(x1.second, x2.second);
}
bool equal_impl(object const& x1, object const& x2) const
{
switch (tag_) {
case 1:
return x1.tag1_ == x2.tag1_;
case 2:
return x1.tag2_ == x2.tag2_;
default:
return x1 == x2;
}
}
friend bool operator==(equal_to const& x1, equal_to const& x2)
{
UNORDERED_SCOPE(operator==(equal_to, equal_to))
{
UNORDERED_EPOINT("Mock equal_to equality function.");
}
return x1.tag_ == x2.tag_;
}
friend bool operator!=(equal_to const& x1, equal_to const& x2)
{
UNORDERED_SCOPE(operator!=(equal_to, equal_to))
{
UNORDERED_EPOINT("Mock equal_to inequality function.");
}
return x1.tag_ != x2.tag_;
}
friend less create_compare(equal_to x) { return less(x.tag_); }
};
template <class T> class allocator
{
public:
int tag_;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T* pointer;
typedef T const* const_pointer;
typedef T& reference;
typedef T const& const_reference;
typedef T value_type;
template <class U> struct rebind
{
typedef allocator<U> other;
};
explicit allocator(int t = 0) : tag_(t)
{
UNORDERED_SCOPE(allocator::allocator())
{
UNORDERED_EPOINT("Mock allocator default constructor.");
}
test::detail::tracker.allocator_ref();
}
template <class Y> allocator(allocator<Y> const& x) : tag_(x.tag_)
{
test::detail::tracker.allocator_ref();
}
allocator(allocator const& x) : tag_(x.tag_)
{
test::detail::tracker.allocator_ref();
}
~allocator() { test::detail::tracker.allocator_unref(); }
allocator& operator=(allocator const& x)
{
tag_ = x.tag_;
return *this;
}
// If address throws, then it can't be used in erase or the
// destructor, which is very limiting. I need to check up on
// this.
pointer address(reference r)
{
// UNORDERED_SCOPE(allocator::address(reference)) {
// UNORDERED_EPOINT("Mock allocator address function.");
//}
return pointer(&r);
}
const_pointer address(const_reference r)
{
// UNORDERED_SCOPE(allocator::address(const_reference)) {
// UNORDERED_EPOINT("Mock allocator const address function.");
//}
return const_pointer(&r);
}
pointer allocate(size_type n)
{
T* ptr = 0;
UNORDERED_SCOPE(allocator::allocate(size_type))
{
UNORDERED_EPOINT("Mock allocator allocate function.");
using namespace std;
ptr = (T*)malloc(n * sizeof(T));
if (!ptr)
throw std::bad_alloc();
}
test::detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return pointer(ptr);
// return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
pointer allocate(size_type n, void const*)
{
T* ptr = 0;
UNORDERED_SCOPE(allocator::allocate(size_type, const_pointer))
{
UNORDERED_EPOINT("Mock allocator allocate function.");
using namespace std;
ptr = (T*)malloc(n * sizeof(T));
if (!ptr)
throw std::bad_alloc();
}
test::detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return pointer(ptr);
// return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type n)
{
//::operator delete((void*) p);
if (p) {
test::detail::tracker.track_deallocate((void*)p, n, sizeof(T), tag_);
using namespace std;
free(p);
}
}
void construct(pointer p, T const& t)
{
UNORDERED_SCOPE(allocator::construct(T*, T))
{
UNORDERED_EPOINT("Mock allocator construct function.");
new (p) T(t);
}
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_);
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{
UNORDERED_SCOPE(allocator::construct(pointer, BOOST_FWD_REF(Args)...))
{
UNORDERED_EPOINT("Mock allocator construct function.");
new (p) T(boost::forward<Args>(args)...);
}
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_);
}
#endif
void destroy(T* p)
{
test::detail::tracker.track_destroy((void*)p, sizeof(T), tag_);
p->~T();
}
size_type max_size() const
{
UNORDERED_SCOPE(allocator::construct(pointer, T))
{
UNORDERED_EPOINT("Mock allocator max_size function.");
}
return (std::numeric_limits<std::size_t>::max)();
}
typedef true_type propagate_on_container_copy_assignment;
typedef true_type propagate_on_container_move_assignment;
typedef true_type propagate_on_container_swap;
};
template <class T> void swap(allocator<T>& x, allocator<T>& y)
{
std::swap(x.tag_, y.tag_);
}
// It's pretty much impossible to write a compliant swap when these
// two can throw. So they don't.
template <class T>
inline bool operator==(allocator<T> const& x, allocator<T> const& y)
{
// UNORDERED_SCOPE(operator==(allocator, allocator)) {
// UNORDERED_EPOINT("Mock allocator equality operator.");
//}
return x.tag_ == y.tag_;
}
template <class T>
inline bool operator!=(allocator<T> const& x, allocator<T> const& y)
{
// UNORDERED_SCOPE(operator!=(allocator, allocator)) {
// UNORDERED_EPOINT("Mock allocator inequality operator.");
//}
return x.tag_ != y.tag_;
}
template <class T> class allocator2
{
public:
int tag_;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T* pointer;
typedef T const* const_pointer;
typedef T& reference;
typedef T const& const_reference;
typedef T value_type;
template <class U> struct rebind
{
typedef allocator2<U> other;
};
explicit allocator2(int t = 0) : tag_(t)
{
UNORDERED_SCOPE(allocator2::allocator2())
{
UNORDERED_EPOINT("Mock allocator2 default constructor.");
}
test::detail::tracker.allocator_ref();
}
allocator2(allocator<T> const& x) : tag_(x.tag_)
{
test::detail::tracker.allocator_ref();
}
template <class Y> allocator2(allocator2<Y> const& x) : tag_(x.tag_)
{
test::detail::tracker.allocator_ref();
}
allocator2(allocator2 const& x) : tag_(x.tag_)
{
test::detail::tracker.allocator_ref();
}
~allocator2() { test::detail::tracker.allocator_unref(); }
allocator2& operator=(allocator2 const&) { return *this; }
// If address throws, then it can't be used in erase or the
// destructor, which is very limiting. I need to check up on
// this.
pointer address(reference r)
{
// UNORDERED_SCOPE(allocator2::address(reference)) {
// UNORDERED_EPOINT("Mock allocator2 address function.");
//}
return pointer(&r);
}
const_pointer address(const_reference r)
{
// UNORDERED_SCOPE(allocator2::address(const_reference)) {
// UNORDERED_EPOINT("Mock allocator2 const address function.");
//}
return const_pointer(&r);
}
pointer allocate(size_type n)
{
T* ptr = 0;
UNORDERED_SCOPE(allocator2::allocate(size_type))
{
UNORDERED_EPOINT("Mock allocator2 allocate function.");
using namespace std;
ptr = (T*)malloc(n * sizeof(T));
if (!ptr)
throw std::bad_alloc();
}
test::detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return pointer(ptr);
// return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
pointer allocate(size_type n, void const*)
{
T* ptr = 0;
UNORDERED_SCOPE(allocator2::allocate(size_type, const_pointer))
{
UNORDERED_EPOINT("Mock allocator2 allocate function.");
using namespace std;
ptr = (T*)malloc(n * sizeof(T));
if (!ptr)
throw std::bad_alloc();
}
test::detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return pointer(ptr);
// return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type n)
{
//::operator delete((void*) p);
if (p) {
test::detail::tracker.track_deallocate((void*)p, n, sizeof(T), tag_);
using namespace std;
free(p);
}
}
void construct(pointer p, T const& t)
{
UNORDERED_SCOPE(allocator2::construct(T*, T))
{
UNORDERED_EPOINT("Mock allocator2 construct function.");
new (p) T(t);
}
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_);
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{
UNORDERED_SCOPE(allocator2::construct(pointer, BOOST_FWD_REF(Args)...))
{
UNORDERED_EPOINT("Mock allocator2 construct function.");
new (p) T(boost::forward<Args>(args)...);
}
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_);
}
#endif
void destroy(T* p)
{
test::detail::tracker.track_destroy((void*)p, sizeof(T), tag_);
p->~T();
}
size_type max_size() const
{
UNORDERED_SCOPE(allocator2::construct(pointer, T))
{
UNORDERED_EPOINT("Mock allocator2 max_size function.");
}
return (std::numeric_limits<std::size_t>::max)();
}
typedef false_type propagate_on_container_copy_assignment;
typedef false_type propagate_on_container_move_assignment;
typedef false_type propagate_on_container_swap;
};
template <class T> void swap(allocator2<T>& x, allocator2<T>& y)
{
std::swap(x.tag_, y.tag_);
}
// It's pretty much impossible to write a compliant swap when these
// two can throw. So they don't.
template <class T>
inline bool operator==(allocator2<T> const& x, allocator2<T> const& y)
{
// UNORDERED_SCOPE(operator==(allocator2, allocator2)) {
// UNORDERED_EPOINT("Mock allocator2 equality operator.");
//}
return x.tag_ == y.tag_;
}
template <class T>
inline bool operator!=(allocator2<T> const& x, allocator2<T> const& y)
{
// UNORDERED_SCOPE(operator!=(allocator2, allocator2)) {
// UNORDERED_EPOINT("Mock allocator2 inequality operator.");
//}
return x.tag_ != y.tag_;
}
}
}
namespace test {
template <typename X> struct equals_to_compare;
template <> struct equals_to_compare<test::exception::equal_to>
{
typedef test::exception::less type;
};
}
// Workaround for ADL deficient compilers
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace test {
test::exception::object generate(
test::exception::object const* x, random_generator g)
{
return test::exception::generate(x, g);
}
std::pair<test::exception::object, test::exception::object> generate(
std::pair<test::exception::object, test::exception::object> const* x,
random_generator g)
{
return test::exception::generate(x, g);
}
}
#endif
#endif

View File

@@ -0,0 +1,17 @@
// Copyright 2006-2009 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)
#if !defined(BOOST_UNORDERED_TEST_OBJECTS_FWD_HEADER)
#define BOOST_UNORDERED_TEST_OBJECTS_FWD_HEADER
namespace test {
class object;
class hash;
class less;
class equal_to;
template <class T> class allocator;
}
#endif

View File

@@ -0,0 +1,627 @@
// Copyright 2006-2009 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)
// 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
#include <boost/move/move.hpp>
#include <cstddef>
#include <utility>
#if defined(BOOST_MSVC)
#pragma warning(push)
#pragma warning(disable : 4100) // unreferenced formal parameter
#endif
#if !BOOST_WORKAROUND(BOOST_MSVC, == 1500)
#define BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED 1
#else
#define BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED 0
#endif
namespace test {
namespace minimal {
class destructible;
class copy_constructible;
class copy_constructible_equality_comparable;
class default_assignable;
class assignable;
struct ampersand_operator_used
{
ampersand_operator_used() { BOOST_TEST(false); }
};
template <class T> class hash;
template <class T> class equal_to;
template <class T> class ptr;
template <class T> class const_ptr;
template <class T> class allocator;
template <class T> class cxx11_allocator;
struct constructor_param
{
operator int() const { return 0; }
};
class destructible
{
public:
destructible(constructor_param const&) {}
~destructible() {}
void dummy_member() const {}
private:
destructible(destructible const&);
destructible& operator=(destructible const&);
};
class copy_constructible
{
public:
copy_constructible(constructor_param const&) {}
copy_constructible(copy_constructible const&) {}
~copy_constructible() {}
void dummy_member() const {}
private:
copy_constructible& operator=(copy_constructible const&);
copy_constructible() {}
};
class copy_constructible_equality_comparable
{
public:
copy_constructible_equality_comparable(constructor_param const&) {}
copy_constructible_equality_comparable(
copy_constructible_equality_comparable const&)
{
}
~copy_constructible_equality_comparable() {}
void dummy_member() const {}
private:
copy_constructible_equality_comparable& operator=(
copy_constructible_equality_comparable const&);
copy_constructible_equality_comparable() {}
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
bool operator==(copy_constructible_equality_comparable,
copy_constructible_equality_comparable)
{
return true;
}
bool operator!=(copy_constructible_equality_comparable,
copy_constructible_equality_comparable)
{
return false;
}
class default_assignable
{
public:
default_assignable(constructor_param const&) {}
default_assignable() {}
default_assignable(default_assignable const&) {}
default_assignable& operator=(default_assignable const&) { return *this; }
~default_assignable() {}
void dummy_member() const {}
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
class assignable
{
public:
assignable(constructor_param const&) {}
assignable(assignable const&) {}
assignable& operator=(assignable const&) { return *this; }
~assignable() {}
void dummy_member() const {}
private:
assignable() {}
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
struct movable_init
{
};
class movable1
{
BOOST_MOVABLE_BUT_NOT_COPYABLE(movable1)
public:
movable1(constructor_param const&) {}
movable1() {}
explicit movable1(movable_init) {}
movable1(BOOST_RV_REF(movable1)) {}
movable1& operator=(BOOST_RV_REF(movable1)) { return *this; }
~movable1() {}
void dummy_member() const {}
};
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
class movable2
{
public:
movable2(constructor_param const&) {}
explicit movable2(movable_init) {}
movable2(movable2&&) {}
~movable2() {}
movable2& operator=(movable2&&) { return *this; }
void dummy_member() const {}
private:
movable2() {}
movable2(movable2 const&);
movable2& operator=(movable2 const&);
};
#else
typedef movable1 movable2;
#endif
template <class T> class hash
{
public:
hash(constructor_param const&) {}
hash() {}
hash(hash const&) {}
hash& operator=(hash const&) { return *this; }
~hash() {}
std::size_t operator()(T const&) const { return 0; }
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
template <class T> class equal_to
{
public:
equal_to(constructor_param const&) {}
equal_to() {}
equal_to(equal_to const&) {}
equal_to& operator=(equal_to const&) { return *this; }
~equal_to() {}
bool operator()(T const&, T const&) const { return true; }
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
template <class T> class ptr;
template <class T> class const_ptr;
struct void_ptr
{
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template <typename T> friend class ptr;
private:
#endif
void* ptr_;
public:
void_ptr() : ptr_(0) {}
template <typename T> explicit void_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
// 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==(void_ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(void_ptr const& x) const { return ptr_ != x.ptr_; }
};
class void_const_ptr
{
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template <typename T> friend class const_ptr;
private:
#endif
void* ptr_;
public:
void_const_ptr() : ptr_(0) {}
template <typename T>
explicit void_const_ptr(const_ptr<T> const& x) : ptr_(x.ptr_)
{
}
// 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==(void_const_ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(void_const_ptr const& x) const { return ptr_ != x.ptr_; }
};
template <class T> class ptr
{
friend class allocator<T>;
friend class const_ptr<T>;
friend struct void_ptr;
T* ptr_;
ptr(T* x) : ptr_(x) {}
public:
ptr() : ptr_(0) {}
explicit ptr(void_ptr const& x) : ptr_((T*)x.ptr_) {}
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+(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_; }
// 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_; }
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_; }
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
template <class T> class const_ptr
{
friend class allocator<T>;
friend struct const_void_ptr;
T const* ptr_;
const_ptr(T const* ptr) : ptr_(ptr) {}
public:
const_ptr() : ptr_(0) {}
const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
explicit const_ptr(void_const_ptr const& x) : ptr_((T const*)x.ptr_) {}
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+(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() const { return !!ptr_; }
bool operator==(const_ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(const_ptr const& x) const { return ptr_ != x.ptr_; }
bool operator<(const_ptr const& x) const { return ptr_ < x.ptr_; }
bool operator>(const_ptr const& x) const { return ptr_ > x.ptr_; }
bool operator<=(const_ptr const& x) const { return ptr_ <= x.ptr_; }
bool operator>=(const_ptr const& x) const { return ptr_ >= x.ptr_; }
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
template <class T> class allocator
{
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef void_ptr void_pointer;
typedef void_const_ptr const_void_pointer;
typedef ptr<T> pointer;
typedef const_ptr<T> const_pointer;
typedef T& reference;
typedef T const& const_reference;
typedef T value_type;
template <class U> struct rebind
{
typedef allocator<U> other;
};
allocator() {}
template <class Y> allocator(allocator<Y> const&) {}
allocator(allocator const&) {}
~allocator() {}
pointer address(reference r) { return pointer(&r); }
const_pointer address(const_reference r) { return const_pointer(&r); }
pointer allocate(size_type n)
{
return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
template <class Y> pointer allocate(size_type n, const_ptr<Y>)
{
return pointer(static_cast<T*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type)
{
::operator delete((void*)p.ptr_);
}
void construct(T* p, T const& t) { new ((void*)p) T(t); }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{
new ((void*)p) T(boost::forward<Args>(args)...);
}
#endif
void destroy(T* p) { p->~T(); }
size_type max_size() const { return 1000; }
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || \
BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
public:
allocator& operator=(allocator const&) { return *this; }
#else
private:
allocator& operator=(allocator const&);
#endif
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
template <class T> class allocator<T const>
{
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef void_ptr void_pointer;
typedef void_const_ptr const_void_pointer;
// Maybe these two should be const_ptr<T>
typedef ptr<T const> pointer;
typedef const_ptr<T const> const_pointer;
typedef T const& reference;
typedef T const& const_reference;
typedef T const value_type;
template <class U> struct rebind
{
typedef allocator<U> other;
};
allocator() {}
template <class Y> allocator(allocator<Y> const&) {}
allocator(allocator const&) {}
~allocator() {}
const_pointer address(const_reference r) { return const_pointer(&r); }
pointer allocate(size_type n)
{
return pointer(static_cast<T const*>(::operator new(n * sizeof(T))));
}
template <class Y> pointer allocate(size_type n, const_ptr<Y>)
{
return pointer(static_cast<T const*>(::operator new(n * sizeof(T))));
}
void deallocate(pointer p, size_type)
{
::operator delete((void*)p.ptr_);
}
void construct(T const* p, T const& t) { new ((void*)p) T(t); }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args>
void construct(T const* p, BOOST_FWD_REF(Args)... args)
{
new ((void*)p) T(boost::forward<Args>(args)...);
}
#endif
void destroy(T const* p) { p->~T(); }
size_type max_size() const { return 1000; }
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || \
BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
public:
allocator& operator=(allocator const&) { return *this; }
#else
private:
allocator& operator=(allocator const&);
#endif
#if BOOST_UNORDERED_CHECK_ADDR_OPERATOR_NOT_USED
ampersand_operator_used operator&() const
{
return ampersand_operator_used();
}
#endif
};
template <class T>
inline bool operator==(allocator<T> const&, allocator<T> const&)
{
return true;
}
template <class T>
inline bool operator!=(allocator<T> const&, allocator<T> const&)
{
return false;
}
template <class T> void swap(allocator<T>&, allocator<T>&) {}
// C++11 allocator
//
// Not a fully minimal C++11 allocator, just what I support. Hopefully will
// cut down further in the future.
template <class T> class cxx11_allocator
{
public:
typedef T value_type;
// template <class U> struct rebind { typedef cxx11_allocator<U> other; };
cxx11_allocator() {}
template <class Y> cxx11_allocator(cxx11_allocator<Y> const&) {}
cxx11_allocator(cxx11_allocator const&) {}
~cxx11_allocator() {}
T* address(T& r) { return &r; }
T const* address(T const& r) { return &r; }
T* allocate(std::size_t n)
{
return static_cast<T*>(::operator new(n * sizeof(T)));
}
template <class Y> T* allocate(std::size_t n, const_ptr<Y>)
{
return static_cast<T*>(::operator new(n * sizeof(T)));
}
void deallocate(T* p, std::size_t) { ::operator delete((void*)p); }
void construct(T* p, T const& t) { new ((void*)p) T(t); }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{
new ((void*)p) T(boost::forward<Args>(args)...);
}
#endif
void destroy(T* p) { p->~T(); }
std::size_t max_size() const { return 1000u; }
};
template <class T>
inline bool operator==(cxx11_allocator<T> const&, cxx11_allocator<T> const&)
{
return true;
}
template <class T>
inline bool operator!=(cxx11_allocator<T> const&, cxx11_allocator<T> const&)
{
return false;
}
template <class T> void swap(cxx11_allocator<T>&, cxx11_allocator<T>&) {}
}
}
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace boost {
#else
namespace test {
namespace minimal {
#endif
std::size_t hash_value(test::minimal::copy_constructible_equality_comparable)
{
return 1;
}
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
}
}
#else
}
#endif
#if defined(BOOST_MSVC)
#pragma warning(pop)
#endif
#endif

View File

@@ -0,0 +1,698 @@
// Copyright 2006-2009 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)
#if !defined(BOOST_UNORDERED_TEST_OBJECTS_HEADER)
#define BOOST_UNORDERED_TEST_OBJECTS_HEADER
#include "../helpers/count.hpp"
#include "../helpers/fwd.hpp"
#include "../helpers/memory.hpp"
#include <boost/config.hpp>
#include <boost/limits.hpp>
#include <cstddef>
namespace test {
// Note that the default hash function will work for any equal_to (but not
// very well).
class object;
class movable;
class implicitly_convertible;
class hash;
class less;
class equal_to;
template <class T> class allocator1;
template <class T> class allocator2;
object generate(object const*, random_generator);
movable generate(movable const*, random_generator);
implicitly_convertible generate(
implicitly_convertible const*, random_generator);
inline void ignore_variable(void const*) {}
class object : private counted_object
{
friend class hash;
friend class equal_to;
friend class less;
int tag1_, tag2_;
public:
explicit object(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {}
~object()
{
tag1_ = -1;
tag2_ = -1;
}
friend bool operator==(object const& x1, object const& x2)
{
return x1.tag1_ == x2.tag1_ && x1.tag2_ == x2.tag2_;
}
friend bool operator!=(object const& x1, object const& x2)
{
return x1.tag1_ != x2.tag1_ || x1.tag2_ != x2.tag2_;
}
friend bool operator<(object const& x1, object const& x2)
{
return x1.tag1_ < x2.tag1_ ||
(x1.tag1_ == x2.tag1_ && x1.tag2_ < x2.tag2_);
}
friend object generate(object const*, random_generator g)
{
int* x = 0;
return object(generate(x, g), generate(x, g));
}
friend std::ostream& operator<<(std::ostream& out, object const& o)
{
return out << "(" << o.tag1_ << "," << o.tag2_ << ")";
}
};
class movable : private counted_object
{
friend class hash;
friend class equal_to;
friend class less;
int tag1_, tag2_;
BOOST_COPYABLE_AND_MOVABLE(movable)
public:
explicit movable(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {}
movable(movable const& x)
: counted_object(x), tag1_(x.tag1_), tag2_(x.tag2_)
{
BOOST_TEST(x.tag1_ != -1);
}
movable(BOOST_RV_REF(movable) x)
: counted_object(x), tag1_(x.tag1_), tag2_(x.tag2_)
{
BOOST_TEST(x.tag1_ != -1);
x.tag1_ = -1;
x.tag2_ = -1;
}
movable& operator=(BOOST_COPY_ASSIGN_REF(movable) x) // Copy assignment
{
BOOST_TEST(x.tag1_ != -1);
tag1_ = x.tag1_;
tag2_ = x.tag2_;
return *this;
}
movable& operator=(BOOST_RV_REF(movable) x) // Move assignment
{
BOOST_TEST(x.tag1_ != -1);
tag1_ = x.tag1_;
tag2_ = x.tag2_;
x.tag1_ = -1;
x.tag2_ = -1;
return *this;
}
~movable()
{
tag1_ = -1;
tag2_ = -1;
}
friend bool operator==(movable const& x1, movable const& x2)
{
BOOST_TEST(x1.tag1_ != -1 && x2.tag1_ != -1);
return x1.tag1_ == x2.tag1_ && x1.tag2_ == x2.tag2_;
}
friend bool operator!=(movable const& x1, movable const& x2)
{
BOOST_TEST(x1.tag1_ != -1 && x2.tag1_ != -1);
return x1.tag1_ != x2.tag1_ || x1.tag2_ != x2.tag2_;
}
friend bool operator<(movable const& x1, movable const& x2)
{
BOOST_TEST(x1.tag1_ != -1 && x2.tag1_ != -1);
return x1.tag1_ < x2.tag1_ ||
(x1.tag1_ == x2.tag1_ && x1.tag2_ < x2.tag2_);
}
friend movable generate(movable const*, random_generator g)
{
int* x = 0;
return movable(generate(x, g), generate(x, g));
}
friend std::ostream& operator<<(std::ostream& out, movable const& o)
{
return out << "(" << o.tag1_ << "," << o.tag2_ << ")";
}
};
class implicitly_convertible : private counted_object
{
int tag1_, tag2_;
public:
explicit implicitly_convertible(int t1 = 0, int t2 = 0)
: tag1_(t1), tag2_(t2)
{
}
operator object() const { return object(tag1_, tag2_); }
operator movable() const { return movable(tag1_, tag2_); }
friend implicitly_convertible generate(
implicitly_convertible const*, random_generator g)
{
int* x = 0;
return implicitly_convertible(generate(x, g), generate(x, g));
}
friend std::ostream& operator<<(
std::ostream& out, implicitly_convertible const& o)
{
return out << "(" << o.tag1_ << "," << o.tag2_ << ")";
}
};
// Note: This is a deliberately bad hash function.
class hash
{
int type_;
public:
explicit hash(int t = 0) : type_(t) {}
std::size_t operator()(object const& x) const
{
int result;
switch (type_) {
case 1:
result = x.tag1_;
break;
case 2:
result = x.tag2_;
break;
default:
result = x.tag1_ + x.tag2_;
}
return static_cast<std::size_t>(result);
}
std::size_t operator()(movable const& x) const
{
int result;
switch (type_) {
case 1:
result = x.tag1_;
break;
case 2:
result = x.tag2_;
break;
default:
result = x.tag1_ + x.tag2_;
}
return static_cast<std::size_t>(result);
}
std::size_t operator()(int x) const
{
int result;
switch (type_) {
case 1:
result = x;
break;
case 2:
result = x * 7;
break;
default:
result = x * 256;
}
return static_cast<std::size_t>(result);
}
friend bool operator==(hash const& x1, hash const& x2)
{
return x1.type_ == x2.type_;
}
friend bool operator!=(hash const& x1, hash const& x2)
{
return x1.type_ != x2.type_;
}
};
std::size_t hash_value(test::object const& x) { return hash()(x); }
std::size_t hash_value(test::movable const& x) { return hash()(x); }
class less
{
int type_;
public:
explicit less(int t = 0) : type_(t) {}
bool operator()(object const& x1, object const& x2) const
{
switch (type_) {
case 1:
return x1.tag1_ < x2.tag1_;
case 2:
return x1.tag2_ < x2.tag2_;
default:
return x1 < x2;
}
}
bool operator()(movable const& x1, movable const& x2) const
{
switch (type_) {
case 1:
return x1.tag1_ < x2.tag1_;
case 2:
return x1.tag2_ < x2.tag2_;
default:
return x1 < x2;
}
}
std::size_t operator()(int x1, int x2) const { return x1 < x2; }
friend bool operator==(less const& x1, less const& x2)
{
return x1.type_ == x2.type_;
}
};
class equal_to
{
int type_;
public:
explicit equal_to(int t = 0) : type_(t) {}
bool operator()(object const& x1, object const& x2) const
{
switch (type_) {
case 1:
return x1.tag1_ == x2.tag1_;
case 2:
return x1.tag2_ == x2.tag2_;
default:
return x1 == x2;
}
}
bool operator()(movable const& x1, movable const& x2) const
{
switch (type_) {
case 1:
return x1.tag1_ == x2.tag1_;
case 2:
return x1.tag2_ == x2.tag2_;
default:
return x1 == x2;
}
}
std::size_t operator()(int x1, int x2) const { return x1 == x2; }
friend bool operator==(equal_to const& x1, equal_to const& x2)
{
return x1.type_ == x2.type_;
}
friend bool operator!=(equal_to const& x1, equal_to const& x2)
{
return x1.type_ != x2.type_;
}
friend less create_compare(equal_to x) { return less(x.type_); }
};
// allocator1 only has the old fashioned 'construct' method and has
// a few less typedefs. allocator2 uses a custom pointer class.
template <class T> class allocator1
{
public:
int tag_;
typedef T value_type;
template <class U> struct rebind
{
typedef allocator1<U> other;
};
explicit allocator1(int t = 0) : tag_(t)
{
detail::tracker.allocator_ref();
}
template <class Y> allocator1(allocator1<Y> const& x) : tag_(x.tag_)
{
detail::tracker.allocator_ref();
}
allocator1(allocator1 const& x) : tag_(x.tag_)
{
detail::tracker.allocator_ref();
}
~allocator1() { detail::tracker.allocator_unref(); }
T* allocate(std::size_t n)
{
T* ptr(static_cast<T*>(::operator new(n * sizeof(T))));
detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return ptr;
}
T* allocate(std::size_t n, void const*)
{
T* ptr(static_cast<T*>(::operator new(n * sizeof(T))));
detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return ptr;
}
void deallocate(T* p, std::size_t n)
{
detail::tracker.track_deallocate((void*)p, n, sizeof(T), tag_);
::operator delete((void*)p);
}
#if BOOST_UNORDERED_CXX11_CONSTRUCTION
template <typename U, typename... Args> void construct(U* p, Args&&... args)
{
detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) U(boost::forward<Args>(args)...);
}
template <typename U> void destroy(U* p)
{
detail::tracker.track_destroy((void*)p, sizeof(U), tag_);
p->~U();
// Work around MSVC buggy unused parameter warning.
ignore_variable(&p);
}
#else
private:
// I'm going to claim in the documentation that construct/destroy
// is never used when C++11 support isn't available, so might as
// well check that in the text.
// TODO: Or maybe just disallow them for values?
template <typename U> void construct(U* p);
template <typename U, typename A0> void construct(U* p, A0 const&);
template <typename U, typename A0, typename A1>
void construct(U* p, A0 const&, A1 const&);
template <typename U, typename A0, typename A1, typename A2>
void construct(U* p, A0 const&, A1 const&, A2 const&);
template <typename U> void destroy(U* p);
public:
#endif
bool operator==(allocator1 const& x) const { return tag_ == x.tag_; }
bool operator!=(allocator1 const& x) const { return tag_ != x.tag_; }
enum
{
is_select_on_copy = false,
is_propagate_on_swap = false,
is_propagate_on_assign = false,
is_propagate_on_move = false
};
};
template <class T> class ptr;
template <class T> class const_ptr;
struct void_ptr
{
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template <typename T> friend class ptr;
private:
#endif
void* ptr_;
public:
void_ptr() : ptr_(0) {}
template <typename T> explicit void_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
// 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==(void_ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(void_ptr const& x) const { return ptr_ != x.ptr_; }
};
class void_const_ptr
{
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template <typename T> friend class const_ptr;
private:
#endif
void* ptr_;
public:
void_const_ptr() : ptr_(0) {}
template <typename T>
explicit void_const_ptr(const_ptr<T> const& x) : ptr_(x.ptr_)
{
}
// 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==(void_const_ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(void_const_ptr const& x) const { return ptr_ != x.ptr_; }
};
template <class T> class ptr
{
friend class allocator2<T>;
friend class const_ptr<T>;
friend struct void_ptr;
T* ptr_;
ptr(T* x) : ptr_(x) {}
public:
ptr() : ptr_(0) {}
explicit ptr(void_ptr const& x) : ptr_((T*)x.ptr_) {}
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+(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_; }
// 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_; }
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_; }
};
template <class T> class const_ptr
{
friend class allocator2<T>;
friend struct const_void_ptr;
T const* ptr_;
const_ptr(T const* ptr) : ptr_(ptr) {}
public:
const_ptr() : ptr_(0) {}
const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
explicit const_ptr(void_const_ptr const& x) : ptr_((T const*)x.ptr_) {}
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+(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() const { return !!ptr_; }
bool operator==(const_ptr const& x) const { return ptr_ == x.ptr_; }
bool operator!=(const_ptr const& x) const { return ptr_ != x.ptr_; }
bool operator<(const_ptr const& x) const { return ptr_ < x.ptr_; }
bool operator>(const_ptr const& x) const { return ptr_ > x.ptr_; }
bool operator<=(const_ptr const& x) const { return ptr_ <= x.ptr_; }
bool operator>=(const_ptr const& x) const { return ptr_ >= x.ptr_; }
};
template <class T> class allocator2
{
#ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
public:
#else
template <class> friend class allocator2;
#endif
int tag_;
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef void_ptr void_pointer;
typedef void_const_ptr const_void_pointer;
typedef ptr<T> pointer;
typedef const_ptr<T> const_pointer;
typedef T& reference;
typedef T const& const_reference;
typedef T value_type;
template <class U> struct rebind
{
typedef allocator2<U> other;
};
explicit allocator2(int t = 0) : tag_(t)
{
detail::tracker.allocator_ref();
}
template <class Y> allocator2(allocator2<Y> const& x) : tag_(x.tag_)
{
detail::tracker.allocator_ref();
}
allocator2(allocator2 const& x) : tag_(x.tag_)
{
detail::tracker.allocator_ref();
}
~allocator2() { detail::tracker.allocator_unref(); }
pointer address(reference r) { return pointer(&r); }
const_pointer address(const_reference r) { return const_pointer(&r); }
pointer allocate(size_type n)
{
pointer p(static_cast<T*>(::operator new(n * sizeof(T))));
detail::tracker.track_allocate((void*)p.ptr_, n, sizeof(T), tag_);
return p;
}
pointer allocate(size_type n, void const*)
{
pointer ptr(static_cast<T*>(::operator new(n * sizeof(T))));
detail::tracker.track_allocate((void*)ptr, n, sizeof(T), tag_);
return ptr;
}
void deallocate(pointer p, size_type n)
{
detail::tracker.track_deallocate((void*)p.ptr_, n, sizeof(T), tag_);
::operator delete((void*)p.ptr_);
}
void construct(T* p, T const& t)
{
detail::tracker.track_construct((void*)p, sizeof(T), tag_);
new (p) T(t);
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{
detail::tracker.track_construct((void*)p, sizeof(T), tag_);
new (p) T(boost::forward<Args>(args)...);
}
#endif
void destroy(T* p)
{
detail::tracker.track_destroy((void*)p, sizeof(T), tag_);
p->~T();
}
size_type max_size() const
{
return (std::numeric_limits<size_type>::max)();
}
bool operator==(allocator2 const& x) const { return tag_ == x.tag_; }
bool operator!=(allocator2 const& x) const { return tag_ != x.tag_; }
enum
{
is_select_on_copy = false,
is_propagate_on_swap = false,
is_propagate_on_assign = false,
is_propagate_on_move = false
};
};
template <class T>
bool equivalent_impl(
allocator1<T> const& x, allocator1<T> const& y, test::derived_type)
{
return x == y;
}
template <class T>
bool equivalent_impl(
allocator2<T> const& x, allocator2<T> const& y, test::derived_type)
{
return x == y;
}
}
#endif