1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2015-2015. 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_TEST_DERIVED_FROM_MEMORY_RESOURCE_HPP
12 #define BOOST_CONTAINER_TEST_DERIVED_FROM_MEMORY_RESOURCE_HPP
14 #include <boost/container/pmr/memory_resource.hpp>
16 class derived_from_memory_resource
17 : public boost::container::pmr::memory_resource
20 explicit derived_from_memory_resource(unsigned i = 0u)
24 virtual ~derived_from_memory_resource() BOOST_OVERRIDE
25 { destructor_called = true; }
27 virtual void* do_allocate(std::size_t bytes, std::size_t alignment) BOOST_OVERRIDE
29 do_allocate_called = true;
30 do_allocate_bytes = bytes;
31 do_allocate_alignment = alignment;
32 return do_allocate_return;
35 virtual void do_deallocate(void* p, std::size_t bytes, std::size_t alignment) BOOST_OVERRIDE
37 do_deallocate_called = true;
39 do_deallocate_bytes = bytes;
40 do_deallocate_alignment = alignment;
43 virtual bool do_is_equal(const boost::container::pmr::memory_resource& other) const BOOST_NOEXCEPT BOOST_OVERRIDE
45 do_is_equal_called = true;
46 do_is_equal_other = &other;
47 return static_cast<const derived_from_memory_resource&>(other).id == this->id;
52 destructor_called = false;
54 do_allocate_return = 0;
55 do_allocate_called = false;
56 do_allocate_bytes = 0u;
57 do_allocate_alignment = 0u;
59 do_deallocate_called = false;
61 do_deallocate_bytes = 0u;
62 do_deallocate_alignment = 0u;
64 do_is_equal_called = false;
65 do_is_equal_other = 0;
68 static bool destructor_called;
71 void *do_allocate_return;
72 mutable bool do_allocate_called;
73 mutable std::size_t do_allocate_bytes;
74 mutable std::size_t do_allocate_alignment;
76 mutable bool do_deallocate_called;
77 mutable void *do_deallocate_p;
78 mutable std::size_t do_deallocate_bytes;
79 mutable std::size_t do_deallocate_alignment;
81 mutable bool do_is_equal_called;
82 mutable const boost::container::pmr::memory_resource *do_is_equal_other;
85 bool derived_from_memory_resource::destructor_called = false;
87 #endif //#ifndef BOOST_CONTAINER_TEST_DERIVED_FROM_MEMORY_RESOURCE_HPP