1 ///////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
12 #define BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 #include <boost/container/container_fwd.hpp>
26 #include <boost/container/throw_exception.hpp>
28 #include <boost/container/detail/addressof.hpp>
29 #include <boost/container/detail/allocation_type.hpp>
30 #include <boost/container/detail/mpl.hpp>
31 #include <boost/container/detail/multiallocation_chain.hpp>
32 #include <boost/container/detail/type_traits.hpp>
33 #include <boost/container/detail/version_type.hpp>
35 #include <boost/move/utility_core.hpp>
36 #include <boost/move/adl_move_swap.hpp>
38 #include <boost/assert.hpp>
49 //Very simple version 1 allocator
51 class simple_allocator
60 simple_allocator(const simple_allocator<U> &)
63 T* allocate(std::size_t n)
64 { return (T*)::new char[sizeof(T)*n]; }
66 void deallocate(T*p, std::size_t)
67 { delete[] ((char*)p);}
69 friend bool operator==(const simple_allocator &, const simple_allocator &)
72 friend bool operator!=(const simple_allocator &, const simple_allocator &)
77 , bool PropagateOnContCopyAssign
78 , bool PropagateOnContMoveAssign
79 , bool PropagateOnContSwap
80 , bool CopyOnPropagateOnContSwap
82 class propagation_test_allocator
84 BOOST_COPYABLE_AND_MOVABLE(propagation_test_allocator)
88 typedef boost::container::container_detail::bool_<PropagateOnContCopyAssign>
89 propagate_on_container_copy_assignment;
90 typedef boost::container::container_detail::bool_<PropagateOnContMoveAssign>
91 propagate_on_container_move_assignment;
92 typedef boost::container::container_detail::bool_<PropagateOnContSwap>
93 propagate_on_container_swap;
97 { typedef propagation_test_allocator
99 , PropagateOnContCopyAssign
100 , PropagateOnContMoveAssign
101 , PropagateOnContSwap
102 , CopyOnPropagateOnContSwap> other;
105 propagation_test_allocator select_on_container_copy_construction() const
106 { return CopyOnPropagateOnContSwap ? propagation_test_allocator(*this) : propagation_test_allocator(); }
108 explicit propagation_test_allocator()
117 propagation_test_allocator(const propagation_test_allocator &x)
119 , ctr_copies_(x.ctr_copies_+1)
120 , ctr_moves_(x.ctr_moves_)
121 , assign_copies_(x.assign_copies_)
122 , assign_moves_(x.assign_moves_)
127 propagation_test_allocator(const propagation_test_allocator
129 , PropagateOnContCopyAssign
130 , PropagateOnContMoveAssign
131 , PropagateOnContSwap
132 , CopyOnPropagateOnContSwap> &x)
134 , ctr_copies_(x.ctr_copies_+1)
141 propagation_test_allocator(BOOST_RV_REF(propagation_test_allocator) x)
143 , ctr_copies_(x.ctr_copies_)
144 , ctr_moves_(x.ctr_moves_ + 1)
145 , assign_copies_(x.assign_copies_)
146 , assign_moves_(x.assign_moves_)
150 propagation_test_allocator &operator=(BOOST_COPY_ASSIGN_REF(propagation_test_allocator) x)
153 ctr_copies_ = x.ctr_copies_;
154 ctr_moves_ = x.ctr_moves_;
155 assign_copies_ = x.assign_copies_+1;
156 assign_moves_ = x.assign_moves_;
161 propagation_test_allocator &operator=(BOOST_RV_REF(propagation_test_allocator) x)
164 ctr_copies_ = x.ctr_copies_;
165 ctr_moves_ = x.ctr_moves_;
166 assign_copies_ = x.assign_copies_;
167 assign_moves_ = x.assign_moves_+1;
172 static void reset_unique_id(unsigned id = 0)
175 T* allocate(std::size_t n)
176 { return (T*)::new char[sizeof(T)*n]; }
178 void deallocate(T*p, std::size_t)
179 { delete[] ((char*)p);}
181 friend bool operator==(const propagation_test_allocator &, const propagation_test_allocator &)
184 friend bool operator!=(const propagation_test_allocator &, const propagation_test_allocator &)
187 void swap(propagation_test_allocator &r)
189 ++this->swaps_; ++r.swaps_;
190 boost::adl_move_swap(this->id_, r.id_);
191 boost::adl_move_swap(this->ctr_copies_, r.ctr_copies_);
192 boost::adl_move_swap(this->ctr_moves_, r.ctr_moves_);
193 boost::adl_move_swap(this->assign_copies_, r.assign_copies_);
194 boost::adl_move_swap(this->assign_moves_, r.assign_moves_);
195 boost::adl_move_swap(this->swaps_, r.swaps_);
198 friend void swap(propagation_test_allocator &l, propagation_test_allocator &r)
204 unsigned int ctr_copies_;
205 unsigned int ctr_moves_;
206 unsigned int assign_copies_;
207 unsigned int assign_moves_;
209 static unsigned unique_id_;
213 , bool PropagateOnContCopyAssign
214 , bool PropagateOnContMoveAssign
215 , bool PropagateOnContSwap
216 , bool CopyOnPropagateOnContSwap
218 unsigned int propagation_test_allocator< T
219 , PropagateOnContCopyAssign
220 , PropagateOnContMoveAssign
221 , PropagateOnContSwap
222 , CopyOnPropagateOnContSwap>::unique_id_ = 0;
226 } //namespace container {
227 } //namespace boost {
229 #include <boost/container/detail/config_end.hpp>
231 #endif //BOOST_CONTAINER_DUMMY_TEST_ALLOCATOR_HPP