1 template <
typename T,
class Arena,
class ...Args>
2 inline T*
new_one(
size_t alignment,
const char* file,
size_t line, Arena& arena, Args&&... args) {
3 void* ptr = arena.allocate(
sizeof(T), alignment, 0, file, line);
9 return new (ptr) T{std::forward<Args>(args)...};
12 template <
typename T,
class Arena>
21 template <
typename T,
class Arena,
class ...Args,
typename std::enable_if<!std::is_pod<T>::value,
int>::type>
22 inline T*
new_array(
size_t alignment,
size_t nb,
const char* file,
size_t line, Arena& arena, Args&&... args) {
27 void*
const ptr = arena.allocate(
sizeof(T) * nb +
sizeof(
size_t), alignment,
sizeof(
size_t), file, line);
34 size_t* size_ptr =
static_cast<size_t*
>(ptr);
38 T*
const user_ptr =
reinterpret_cast<T*
>(size_ptr + 1);
39 for (
size_t i = 0; i < nb; ++i) {
40 new (&user_ptr[i]) T{std::forward<Args>(args)...};
46 template <typename T, class Arena, typename std::enable_if<!std::is_pod<T>::value,
int>::type>
54 size_t* size_ptr =
reinterpret_cast<size_t*
>(ptr);
55 const size_t nb = size_ptr[-1];
58 for (
size_t i = nb; i > 0; --i) {
62 arena.free(&(size_ptr[-1]));
65 template <typename T, class Arena, typename std::enable_if<std::is_pod<T>::value,
int>::type>
66 inline T*
new_array(
size_t alignment,
size_t nb,
const char* file,
size_t line, Arena& arena) {
67 void* ptr = arena.allocate(
sizeof(T) * nb, alignment, 0, file, line);
76 template <typename T, class Arena, typename std::enable_if<std::is_pod<T>::value,
int>::type>
83 template <
typename T,
class Arena,
typename ...Args>
84 inline typename priv::make_unique_if<T>::SingleObject
make_unique(Arena& arena, Args&&... args) {
85 return make_unique_align<T>(arena,
alignof(T), std::forward<Args>(args)...);
88 template <
typename T,
class Arena,
typename ...Args>
89 typename priv::make_unique_if<T>::SingleObject
make_unique_align(Arena& arena,
size_t alignment, Args&&... args) {
90 auto deleter = [&arena](T* ptr) {
94 return typename priv::make_unique_if<T>::SingleObject(
95 LUG_NEW_ALIGN(T, alignment, arena, std::forward<Args>(args)...),
101 template <
typename T,
class Arena,
typename ...Args,
typename std::enable_if<!std::is_pod<T>::value,
int>::type>
102 inline typename priv::make_unique_if<T>::UnknownBound
make_unique(Arena& arena,
size_t size, Args&&... args) {
103 return make_unique_align<T>(arena,
alignof(T), size, std::forward<Args>(args)...);
106 template <
typename T,
class Arena,
typename ...Args,
typename std::enable_if<!std::is_pod<T>::value,
int>::type>
107 typename priv::make_unique_if<T>::UnknownBound
make_unique_align(Arena& arena,
size_t alignment,
size_t size, Args&&... args) {
108 using U =
typename std::remove_all_extents<T>::type;
110 auto deleter = [&arena](U* ptr) {
114 return typename priv::make_unique_if<T>::UnknownBound(
120 template <typename T, class Arena, typename std::enable_if<std::is_pod<T>::value,
int>::type>
121 inline typename priv::make_unique_if<T>::UnknownBound
make_unique(Arena& arena,
size_t size) {
122 return make_unique_align<T>(arena,
alignof(T), size);
125 template <typename T, class Arena, typename std::enable_if<std::is_pod<T>::value,
int>::type>
126 typename priv::make_unique_if<T>::UnknownBound
make_unique_align(Arena& arena,
size_t alignment,
size_t size) {
127 using U =
typename std::remove_all_extents<T>::type;
129 auto deleter = [&arena](U* ptr) {
133 return typename priv::make_unique_if<T>::UnknownBound(
140 template <
typename T,
class Arena,
typename ...Args,
typename std::enable_if<!std::is_pod<T>::value,
int>::type>
141 inline typename priv::make_unique_if<T>::KnownBound
make_unique(Arena& arena, Args&&... args) {
142 return make_unique_align<T>(arena,
alignof(T), std::forward<Args>(args)...);
145 template <
typename T,
class Arena,
typename ...Args,
typename std::enable_if<!std::is_pod<T>::value,
int>::type>
146 typename priv::make_unique_if<T>::KnownBound
make_unique_align(Arena& arena,
size_t alignment, Args&&... args) {
147 using U =
typename std::remove_all_extents<T>::type;
149 auto deleter = [&arena](U* ptr) {
153 return typename priv::make_unique_if<T>::KnownBound(
159 template <typename T, class Arena, typename std::enable_if<std::is_pod<T>::value,
int>::type>
160 typename priv::make_unique_if<T>::KnownBound
make_unique(Arena& arena) {
161 return make_unique_align<T>(arena,
alignof(T));
164 template <typename T, class Arena, typename std::enable_if<std::is_pod<T>::value,
int>::type>
165 typename priv::make_unique_if<T>::KnownBound
make_unique_align(Arena& arena,
size_t alignment) {
166 using U =
typename std::remove_all_extents<T>::type;
168 auto deleter = [&arena](U* ptr) {
172 return typename priv::make_unique_if<T>::KnownBound(
void delete_one(T *object, Arena &arena)
#define LUG_NEW_ARRAY_ALIGN(T, alignment,...)
#define LUG_NEW_ARRAY_ALIGN_SIZE(T, alignment, size,...)
T * new_array(size_t alignment, size_t nb, const char *file, size_t line, Arena &arena, Args &&... args)
#define LUG_DELETE(object, arena)
#define LUG_DELETE_ARRAY(object, arena)
T * new_one(size_t alignment, const char *file, size_t line, Arena &arena, Args &&... args)
#define LUG_NEW_ALIGN(T, alignment,...)
priv::make_unique_if< T >::SingleObject make_unique_align(Arena &arena, size_t alignment, Args &&... args)
priv::make_unique_if< T >::SingleObject make_unique(Arena &arena, Args &&... args)
void delete_array(T *ptr, Arena &arena)