-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathallocator_utils.hpp
More file actions
32 lines (29 loc) · 1.03 KB
/
Copy pathallocator_utils.hpp
File metadata and controls
32 lines (29 loc) · 1.03 KB
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
#pragma once
#ifndef ALLOCATOR_UTILS_HPP_GU8I6HCJ
#define ALLOCATOR_UTILS_HPP_GU8I6HCJ
#include "type_traits.hpp"
#include "utils.hpp"
namespace ftl {
template <typename Allocator>
class AllocatorUtils {
public:
template <typename T>
static T* realloc(T* ptr, size_t new_size, size_t initialized_size) { return Reallocator<T, is_pod<T>::value>::realloc(ptr, new_size, initialized_size); }
private:
template <typename T, bool pod> struct Reallocator { static T* realloc(T* ptr, size_t new_size, size_t initialized_size); };
template <typename T> struct Reallocator<T, true> {
static T* realloc(T* ptr, size_t new_size, size_t initialized_size) {
return Allocator::realloc(ptr, new_size);
}
};
template <typename T> struct Reallocator<T, false> {
static T* realloc(T* ptr, size_t new_size, size_t initialized_size) {
T* data = Allocator::alloc(new_size);
move_range(data, ptr, initialized_size);
Allocator::free(ptr);
return data;
}
};
};
}
#endif /* end of include guard: ALLOCATOR_UTILS_HPP_GU8I6HCJ */