1 /* Used in Boost.MultiIndex tests.
3 * Copyright 2003-2020 Joaquin M Lopez Munoz.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org/libs/multi_index for library home page.
11 #ifndef BOOST_MULTI_INDEX_TEST_COUNT_ALLOCATOR_HPP
12 #define BOOST_MULTI_INDEX_TEST_COUNT_ALLOCATOR_HPP
14 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
18 struct count_allocator:std::allocator<T>
20 typedef std::allocator<T> super;
22 struct rebind{typedef count_allocator<U> other;};
24 count_allocator(std::size_t& element_count,std::size_t& allocator_count):
25 pelement_count(&element_count),pallocator_count(&allocator_count)
26 {++(*pallocator_count);}
27 count_allocator(const count_allocator<T>& x):
29 pelement_count(x.pelement_count),pallocator_count(x.pallocator_count)
30 {++(*pallocator_count);}
31 template<class U>count_allocator(const count_allocator<U>& x):
33 pelement_count(x.pelement_count),pallocator_count(x.pallocator_count)
34 {++(*pallocator_count);}
36 {--(*pallocator_count);}
38 count_allocator& operator=(const count_allocator<T>& x)
40 pelement_count=x.pelement_count;
41 pallocator_count=x.pallocator_count;
45 T* allocate(std::size_t n)
48 return super::allocate(n);
51 void deallocate(T* p,std::size_t n)
53 super::deallocate(p,n);
57 std::size_t* pelement_count;
58 std::size_t* pallocator_count;