@@ -63,16 +63,44 @@ template <typename T, size_t MinItemsInBlock = 1024> class PoolAllocator
63
63
}
64
64
}
65
65
66
- PoolAllocator (const PoolAllocator &) {}
66
+ PoolAllocator (const PoolAllocator &) = delete ;
67
+ PoolAllocator &operator =(const PoolAllocator &) = delete ;
68
+
69
+ PoolAllocator (PoolAllocator &&other) noexcept
70
+ : free_lists_(std::move(other.free_lists_)),
71
+ blocks_ (std::move(other.blocks_)),
72
+ current_block_ptr_(other.current_block_ptr_),
73
+ current_block_left_items_(other.current_block_left_items_),
74
+ total_allocated_(other.total_allocated_)
75
+ {
76
+ other.current_block_ptr_ = nullptr ;
77
+ other.current_block_left_items_ = 0 ;
78
+ other.total_allocated_ = 0 ;
79
+ }
67
80
68
- PoolAllocator &operator =(const PoolAllocator &){return *this ;}
81
+ PoolAllocator &operator =(PoolAllocator &&other) noexcept
82
+ {
83
+ if (this != &other)
84
+ {
85
+ for (auto block : blocks_)
86
+ {
87
+ std::free (block);
88
+ }
69
89
70
- // You may also want to implement move semantics if needed
71
- PoolAllocator (PoolAllocator &&) noexcept = default ;
72
- PoolAllocator &operator =(PoolAllocator &&) noexcept = default ;
90
+ free_lists_ = std::move (other.free_lists_ );
91
+ blocks_ = std::move (other.blocks_ );
92
+ current_block_ptr_ = other.current_block_ptr_ ;
93
+ current_block_left_items_ = other.current_block_left_items_ ;
94
+ total_allocated_ = other.total_allocated_ ;
73
95
96
+ other.current_block_ptr_ = nullptr ;
97
+ other.current_block_left_items_ = 0 ;
98
+ other.total_allocated_ = 0 ;
99
+ }
100
+ return *this ;
101
+ }
74
102
75
- private:
103
+ private:
76
104
size_t get_next_power_of_two_exponent (size_t n) const
77
105
{
78
106
BOOST_ASSERT (n > 0 );
0 commit comments