-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_allocator.hpp
More file actions
48 lines (38 loc) · 974 Bytes
/
handler_allocator.hpp
File metadata and controls
48 lines (38 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef HANDLER_ALLOCATOR_HPP
#define HANDLER_ALLOCATOR_HPP
#include "handler_memory.hpp"
template<typename T>
class handler_allocator
{
private:
handler_memory& memory_;
template <typename> friend class handler_allocator;
public:
using value_type = T;
explicit handler_allocator(handler_memory& memory_) :
memory_(memory_)
{
}
template <typename U>
handler_allocator(const handler_allocator<U>& other) noexcept :
memory_(other.memory_)
{
}
bool operator==(const handler_allocator& other) const noexcept
{
return &memory_ == &other.memory_;
}
bool operator!=(const handler_allocator& other) const noexcept
{
return &memory_ != &other.memory_;
}
T* allocate(size_t n) const
{
return static_cast<T*>(memory_.allocate(n * sizeof(T)));
}
void deallocate(T* ptr, size_t) const
{
memory_.deallocate(ptr);
}
};
#endif // HANDLER_ALLOCATOR_HPP