1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
///////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2013. 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)
//
// See http://www.boost.org/libs/container for documentation.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
#define BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/container/throw_exception.hpp>
#include <boost/container/detail/addressof.hpp>
#include <boost/container/detail/allocation_type.hpp>
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/multiallocation_chain.hpp>
#include <boost/container/detail/type_traits.hpp>
#include <boost/container/detail/version_type.hpp>
#include <boost/container/detail/operator_new_helpers.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/move/adl_move_swap.hpp>
#include <boost/assert.hpp>
#include <memory>
#include <algorithm>
#include <cstddef>
#include <cassert>
namespace boost {
namespace container {
namespace test {
//Very simple version 1 allocator
template<class T>
class simple_allocator
{
public:
typedef T value_type;
simple_allocator()
{}
template<class U>
simple_allocator(const simple_allocator<U> &)
{}
value_type* allocate(std::size_t count)
{ return boost::container::dtl::operator_new_allocate<value_type>(count); }
void deallocate(value_type *ptr, std::size_t n)
{ return boost::container::dtl::operator_delete_deallocate<T>(ptr, n); }
friend bool operator==(const simple_allocator &, const simple_allocator &)
{ return true; }
friend bool operator!=(const simple_allocator &, const simple_allocator &)
{ return false; }
};
template< class T
, bool PropagateOnContCopyAssign
, bool PropagateOnContMoveAssign
, bool PropagateOnContSwap
, bool CopyOnPropagateOnContSwap
, bool EqualIfEqualIds
>
class propagation_test_allocator
{
BOOST_COPYABLE_AND_MOVABLE(propagation_test_allocator)
public:
typedef T value_type;
typedef boost::container::dtl::bool_<PropagateOnContCopyAssign>
propagate_on_container_copy_assignment;
typedef boost::container::dtl::bool_<PropagateOnContMoveAssign>
propagate_on_container_move_assignment;
typedef boost::container::dtl::bool_<PropagateOnContSwap>
propagate_on_container_swap;
template<class T2>
struct rebind
{ typedef propagation_test_allocator
< T2
, PropagateOnContCopyAssign
, PropagateOnContMoveAssign
, PropagateOnContSwap
, CopyOnPropagateOnContSwap
, EqualIfEqualIds> other;
};
propagation_test_allocator select_on_container_copy_construction() const
{ return CopyOnPropagateOnContSwap ? propagation_test_allocator(*this) : propagation_test_allocator(); }
explicit propagation_test_allocator()
: id_(++unique_id_)
, ctr_copies_(0)
, ctr_moves_(0)
, assign_copies_(0)
, assign_moves_(0)
, swaps_(0)
{}
propagation_test_allocator(const propagation_test_allocator &x)
: id_(x.id_)
, ctr_copies_(x.ctr_copies_+1)
, ctr_moves_(x.ctr_moves_)
, assign_copies_(x.assign_copies_)
, assign_moves_(x.assign_moves_)
, swaps_(x.swaps_)
{}
template<class U>
propagation_test_allocator(const propagation_test_allocator
< U
, PropagateOnContCopyAssign
, PropagateOnContMoveAssign
, PropagateOnContSwap
, CopyOnPropagateOnContSwap
, EqualIfEqualIds> &x)
: id_(x.id_)
, ctr_copies_(x.ctr_copies_+1)
, ctr_moves_(0)
, assign_copies_(0)
, assign_moves_(0)
, swaps_(0)
{}
propagation_test_allocator(BOOST_RV_REF(propagation_test_allocator) x)
: id_(x.id_)
, ctr_copies_(x.ctr_copies_)
, ctr_moves_(x.ctr_moves_ + 1)
, assign_copies_(x.assign_copies_)
, assign_moves_(x.assign_moves_)
, swaps_(x.swaps_)
{}
propagation_test_allocator &operator=(BOOST_COPY_ASSIGN_REF(propagation_test_allocator) x)
{
id_ = x.id_;
ctr_copies_ = x.ctr_copies_;
ctr_moves_ = x.ctr_moves_;
assign_copies_ = x.assign_copies_+1;
assign_moves_ = x.assign_moves_;
swaps_ = x.swaps_;
return *this;
}
propagation_test_allocator &operator=(BOOST_RV_REF(propagation_test_allocator) x)
{
id_ = x.id_;
ctr_copies_ = x.ctr_copies_;
ctr_moves_ = x.ctr_moves_;
assign_copies_ = x.assign_copies_;
assign_moves_ = x.assign_moves_+1;
swaps_ = x.swaps_;
return *this;
}
static void reset_unique_id(unsigned id = 0)
{ unique_id_ = id; }
value_type* allocate(std::size_t count)
{ return boost::container::dtl::operator_new_allocate<value_type>(count); }
void deallocate(value_type *ptr, std::size_t n)
{ return boost::container::dtl::operator_delete_deallocate<T>(ptr, n); }
friend bool operator==(const propagation_test_allocator &a, const propagation_test_allocator &b)
{ return EqualIfEqualIds ? a.id_ == b.id_ : true; }
friend bool operator!=(const propagation_test_allocator &a, const propagation_test_allocator &b)
{ return EqualIfEqualIds ? a.id_ != b.id_ : false; }
void swap(propagation_test_allocator &r)
{
++this->swaps_; ++r.swaps_;
boost::adl_move_swap(this->id_, r.id_);
boost::adl_move_swap(this->ctr_copies_, r.ctr_copies_);
boost::adl_move_swap(this->ctr_moves_, r.ctr_moves_);
boost::adl_move_swap(this->assign_copies_, r.assign_copies_);
boost::adl_move_swap(this->assign_moves_, r.assign_moves_);
boost::adl_move_swap(this->swaps_, r.swaps_);
}
friend void swap(propagation_test_allocator &l, propagation_test_allocator &r)
{
l.swap(r);
}
unsigned int id_;
unsigned int ctr_copies_;
unsigned int ctr_moves_;
unsigned int assign_copies_;
unsigned int assign_moves_;
unsigned int swaps_;
static unsigned unique_id_;
};
template< class T
, bool PropagateOnContCopyAssign
, bool PropagateOnContMoveAssign
, bool PropagateOnContSwap
, bool CopyOnPropagateOnContSwap
, bool EqualIfEqualIds
>
unsigned int propagation_test_allocator< T
, PropagateOnContCopyAssign
, PropagateOnContMoveAssign
, PropagateOnContSwap
, CopyOnPropagateOnContSwap
, EqualIfEqualIds
>::unique_id_ = 0;
template<class T>
class small_size_type_allocator
{
public:
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef unsigned short size_type;
typedef short difference_type;
small_size_type_allocator()
{}
template<class U>
small_size_type_allocator(const small_size_type_allocator<U>&)
{}
pointer allocate(size_type count)
{ return static_cast<value_type*>(::operator new(count * sizeof(value_type))); }
void deallocate(pointer ptr, size_type n)
{
(void)n;
# if defined(__cpp_sized_deallocation)
::operator delete((void*)ptr, n * sizeof(value_type));
#else
::operator delete((void*)ptr);
# endif
}
friend bool operator==(small_size_type_allocator const&, small_size_type_allocator const&) BOOST_NOEXCEPT
{ return true; }
friend bool operator!=(small_size_type_allocator const& x, small_size_type_allocator const& y) BOOST_NOEXCEPT
{ return !(x == y); }
};
} //namespace test {
} //namespace container {
} //namespace boost {
#include <boost/container/detail/config_end.hpp>
#endif //BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
|