2011-08-26 18:26:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-12-23 10:47:20 +01:00
|
|
|
// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
|
2011-08-26 18:26:44 +00:00
|
|
|
// 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
|
|
|
|
|
2013-12-23 10:47:20 +01:00
|
|
|
#if defined(_MSC_VER)
|
2011-08-26 18:26:44 +00:00
|
|
|
# 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/detail/allocation_type.hpp>
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
#include <boost/container/detail/utilities.hpp>
|
|
|
|
#include <boost/container/detail/type_traits.hpp>
|
2011-12-22 20:15:57 +00:00
|
|
|
#include <boost/container/detail/mpl.hpp>
|
2011-08-26 18:26:44 +00:00
|
|
|
#include <boost/container/detail/version_type.hpp>
|
2011-12-22 20:15:57 +00:00
|
|
|
#include <boost/container/detail/multiallocation_chain.hpp>
|
2013-01-10 10:55:50 +00:00
|
|
|
#include <boost/container/throw_exception.hpp>
|
2014-09-17 23:36:23 +02:00
|
|
|
#include <boost/move/utility_core.hpp>
|
2014-11-28 15:41:44 +01:00
|
|
|
#include <boost/move/adl_move_swap.hpp>
|
2011-08-26 18:26:44 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace container {
|
|
|
|
namespace test {
|
|
|
|
|
2011-12-22 20:15:57 +00:00
|
|
|
//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> &)
|
|
|
|
{}
|
|
|
|
|
|
|
|
T* allocate(std::size_t n)
|
2012-11-24 21:09:10 +00:00
|
|
|
{ return (T*)::new char[sizeof(T)*n]; }
|
2011-12-22 20:15:57 +00:00
|
|
|
|
|
|
|
void deallocate(T*p, std::size_t)
|
|
|
|
{ delete[] ((char*)p);}
|
|
|
|
|
|
|
|
friend bool operator==(const simple_allocator &, const simple_allocator &)
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
friend bool operator!=(const simple_allocator &, const simple_allocator &)
|
|
|
|
{ return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//Version 2 allocator with rebind
|
2011-08-26 18:26:44 +00:00
|
|
|
template<class T>
|
2012-05-20 10:03:06 +00:00
|
|
|
class dummy_test_allocator
|
2011-08-26 18:26:44 +00:00
|
|
|
{
|
|
|
|
private:
|
2011-12-22 20:15:57 +00:00
|
|
|
typedef dummy_test_allocator<T> self_t;
|
2011-08-26 18:26:44 +00:00
|
|
|
typedef void * aux_pointer_t;
|
|
|
|
typedef const void * cvoid_ptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T value_type;
|
|
|
|
typedef T * pointer;
|
|
|
|
typedef const T * const_pointer;
|
2011-12-22 20:15:57 +00:00
|
|
|
typedef typename container_detail::add_reference
|
2011-08-26 18:26:44 +00:00
|
|
|
<value_type>::type reference;
|
2011-12-22 20:15:57 +00:00
|
|
|
typedef typename container_detail::add_reference
|
2011-08-26 18:26:44 +00:00
|
|
|
<const value_type>::type const_reference;
|
|
|
|
typedef std::size_t size_type;
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
|
2011-12-22 20:15:57 +00:00
|
|
|
typedef container_detail::basic_multiallocation_chain
|
|
|
|
<void*> multialloc_cached_counted;
|
|
|
|
typedef boost::container::container_detail::transform_multiallocation_chain
|
|
|
|
<multialloc_cached_counted, value_type> multiallocation_chain;
|
|
|
|
|
|
|
|
typedef boost::container::container_detail::version_type<dummy_test_allocator, 2> version;
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
template<class T2>
|
|
|
|
struct rebind
|
|
|
|
{ typedef dummy_test_allocator<T2> other; };
|
|
|
|
|
|
|
|
//!Default constructor. Never throws
|
|
|
|
dummy_test_allocator()
|
2012-05-20 10:03:06 +00:00
|
|
|
{}
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
//!Constructor from other dummy_test_allocator. Never throws
|
|
|
|
dummy_test_allocator(const dummy_test_allocator &)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//!Constructor from related dummy_test_allocator. Never throws
|
|
|
|
template<class T2>
|
|
|
|
dummy_test_allocator(const dummy_test_allocator<T2> &)
|
|
|
|
{}
|
|
|
|
|
2012-05-20 10:03:06 +00:00
|
|
|
pointer address(reference value)
|
2012-03-22 18:48:57 +00:00
|
|
|
{ return pointer(container_detail::addressof(value)); }
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
const_pointer address(const_reference value) const
|
2012-03-22 18:48:57 +00:00
|
|
|
{ return const_pointer(container_detail::addressof(value)); }
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
pointer allocate(size_type, cvoid_ptr = 0)
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
void deallocate(const pointer &, size_type)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<class Convertible>
|
|
|
|
void construct(pointer, const Convertible &)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void destroy(pointer)
|
|
|
|
{}
|
|
|
|
|
|
|
|
size_type max_size() const
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
friend void swap(self_t &, self_t &)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//Experimental version 2 dummy_test_allocator functions
|
|
|
|
|
|
|
|
std::pair<pointer, bool>
|
|
|
|
allocation_command(boost::container::allocation_type,
|
2012-05-20 10:03:06 +00:00
|
|
|
size_type,
|
2011-08-26 18:26:44 +00:00
|
|
|
size_type,
|
|
|
|
size_type &, const pointer & = 0)
|
2011-12-22 20:15:57 +00:00
|
|
|
{ return std::pair<pointer, bool>(pointer(), true); }
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
//!Returns maximum the number of objects the previously allocated memory
|
|
|
|
//!pointed by p can hold.
|
|
|
|
size_type size(const pointer &) const
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
//!Allocates just one object. Memory allocated with this function
|
|
|
|
//!must be deallocated only with deallocate_one().
|
|
|
|
//!Throws boost::container::bad_alloc if there is no enough memory
|
|
|
|
pointer allocate_one()
|
2011-12-22 20:15:57 +00:00
|
|
|
{ return pointer(); }
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
//!Deallocates memory previously allocated with allocate_one().
|
|
|
|
//!You should never use deallocate_one to deallocate memory allocated
|
|
|
|
//!with other functions different from allocate_one(). Never throws
|
|
|
|
void deallocate_one(const pointer &)
|
|
|
|
{}
|
2011-12-22 20:15:57 +00:00
|
|
|
|
|
|
|
//!Allocates many elements of size == 1 in a contiguous block
|
|
|
|
//!of memory. The minimum number to be allocated is min_elements,
|
|
|
|
//!the preferred and maximum number is
|
|
|
|
//!preferred_elements. The number of actually allocated elements is
|
|
|
|
//!will be assigned to received_size. Memory allocated with this function
|
|
|
|
//!must be deallocated only with deallocate_one().
|
2012-11-24 21:09:10 +00:00
|
|
|
void allocate_individual(size_type, multiallocation_chain &)
|
|
|
|
{}
|
2011-12-22 20:15:57 +00:00
|
|
|
|
|
|
|
//!Allocates many elements of size == 1 in a contiguous block
|
|
|
|
//!of memory. The minimum number to be allocated is min_elements,
|
|
|
|
//!the preferred and maximum number is
|
|
|
|
//!preferred_elements. The number of actually allocated elements is
|
|
|
|
//!will be assigned to received_size. Memory allocated with this function
|
|
|
|
//!must be deallocated only with deallocate_one().
|
2012-11-24 21:09:10 +00:00
|
|
|
void deallocate_individual(multiallocation_chain &)
|
2011-12-22 20:15:57 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
//!Allocates many elements of size elem_size in a contiguous block
|
|
|
|
//!of memory. The minimum number to be allocated is min_elements,
|
|
|
|
//!the preferred and maximum number is
|
|
|
|
//!preferred_elements. The number of actually allocated elements is
|
|
|
|
//!will be assigned to received_size. The elements must be deallocated
|
|
|
|
//!with deallocate(...)
|
2012-11-24 21:09:10 +00:00
|
|
|
void deallocate_many(multiallocation_chain &)
|
2011-12-22 20:15:57 +00:00
|
|
|
{}
|
2011-08-26 18:26:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//!Equality test for same type of dummy_test_allocator
|
|
|
|
template<class T> inline
|
2012-05-20 10:03:06 +00:00
|
|
|
bool operator==(const dummy_test_allocator<T> &,
|
2011-08-26 18:26:44 +00:00
|
|
|
const dummy_test_allocator<T> &)
|
2011-12-22 20:15:57 +00:00
|
|
|
{ return true; }
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
//!Inequality test for same type of dummy_test_allocator
|
|
|
|
template<class T> inline
|
2012-05-20 10:03:06 +00:00
|
|
|
bool operator!=(const dummy_test_allocator<T> &,
|
2011-08-26 18:26:44 +00:00
|
|
|
const dummy_test_allocator<T> &)
|
2011-12-22 20:15:57 +00:00
|
|
|
{ return false; }
|
|
|
|
|
|
|
|
|
|
|
|
template< class T
|
2012-05-20 10:03:06 +00:00
|
|
|
, bool PropagateOnContCopyAssign
|
2011-12-22 20:15:57 +00:00
|
|
|
, bool PropagateOnContMoveAssign
|
|
|
|
, bool PropagateOnContSwap
|
|
|
|
, bool CopyOnPropagateOnContSwap
|
|
|
|
>
|
|
|
|
class propagation_test_allocator
|
|
|
|
{
|
|
|
|
BOOST_COPYABLE_AND_MOVABLE(propagation_test_allocator)
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T value_type;
|
|
|
|
typedef boost::container::container_detail::bool_<PropagateOnContCopyAssign>
|
|
|
|
propagate_on_container_copy_assignment;
|
|
|
|
typedef boost::container::container_detail::bool_<PropagateOnContMoveAssign>
|
|
|
|
propagate_on_container_move_assignment;
|
|
|
|
typedef boost::container::container_detail::bool_<PropagateOnContSwap>
|
|
|
|
propagate_on_container_swap;
|
|
|
|
|
|
|
|
template<class T2>
|
|
|
|
struct rebind
|
|
|
|
{ typedef propagation_test_allocator
|
|
|
|
< T2
|
|
|
|
, PropagateOnContCopyAssign
|
|
|
|
, PropagateOnContMoveAssign
|
|
|
|
, PropagateOnContSwap
|
|
|
|
, CopyOnPropagateOnContSwap> 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> &x)
|
|
|
|
: id_(x.id_)
|
|
|
|
, ctr_copies_(0)
|
|
|
|
, 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()
|
|
|
|
{ unique_id_ = 0; }
|
|
|
|
|
|
|
|
T* allocate(std::size_t n)
|
|
|
|
{ return (T*)::new char[sizeof(T)*n]; }
|
|
|
|
|
|
|
|
void deallocate(T*p, std::size_t)
|
|
|
|
{ delete[] ((char*)p);}
|
|
|
|
|
|
|
|
friend bool operator==(const propagation_test_allocator &, const propagation_test_allocator &)
|
|
|
|
{ return true; }
|
|
|
|
|
|
|
|
friend bool operator!=(const propagation_test_allocator &, const propagation_test_allocator &)
|
|
|
|
{ return false; }
|
|
|
|
|
2013-03-03 12:26:48 +00:00
|
|
|
void swap(propagation_test_allocator &r)
|
|
|
|
{
|
|
|
|
++this->swaps_; ++r.swaps_;
|
2014-11-28 15:41:44 +01:00
|
|
|
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_);
|
2013-03-03 12:26:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 20:15:57 +00:00
|
|
|
friend void swap(propagation_test_allocator &l, propagation_test_allocator &r)
|
|
|
|
{
|
2013-03-03 12:26:48 +00:00
|
|
|
l.swap(r);
|
2011-12-22 20:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2012-05-20 10:03:06 +00:00
|
|
|
, bool PropagateOnContCopyAssign
|
2011-12-22 20:15:57 +00:00
|
|
|
, bool PropagateOnContMoveAssign
|
|
|
|
, bool PropagateOnContSwap
|
|
|
|
, bool CopyOnPropagateOnContSwap
|
|
|
|
>
|
|
|
|
unsigned int propagation_test_allocator< T
|
|
|
|
, PropagateOnContCopyAssign
|
|
|
|
, PropagateOnContMoveAssign
|
|
|
|
, PropagateOnContSwap
|
|
|
|
, CopyOnPropagateOnContSwap>::unique_id_ = 0;
|
|
|
|
|
2011-08-26 18:26:44 +00:00
|
|
|
|
|
|
|
} //namespace test {
|
|
|
|
} //namespace container {
|
|
|
|
} //namespace boost {
|
|
|
|
|
|
|
|
#include <boost/container/detail/config_end.hpp>
|
|
|
|
|
|
|
|
#endif //BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
|
|
|
|
|