-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllocatorHelpers.h
42 lines (29 loc) · 910 Bytes
/
AllocatorHelpers.h
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
#ifndef EXPERIMENTS_ALLOCATORHELPERS_H
#define EXPERIMENTS_ALLOCATORHELPERS_H
#include "FixedSizeAllocator.h"
template<class T, class Alloc>
struct DeleterForAllocator;
template<class T>
struct DeleterForAllocator<T, std::nullptr_t> {
void operator()(T *__ptr) const noexcept {
delete[] __ptr;
}
};
template<class T, size_t Size>
struct DeleterForAllocator<T, StdFixedSizeArrayAllocator<T, Size>> {
inline static auto &allocator_ = StdFixedSizeArrayAllocator<T, Size>::oneAndOnly();
DeleterForAllocator() {}
void operator()(T *__ptr) {
allocator_.deallocate(__ptr, 1);
}
};
template<class T>
struct DeleterForFixedAllocator {
DeleterForFixedAllocator() {}
void operator()(T *__ptr) {
auto &allocator = StdFixedAllocator<T>::oneAndOnly();
allocator.destroy(__ptr);
allocator.deallocate(__ptr, 1);
}
};
#endif //EXPERIMENTS_ALLOCATORHELPERS_H