aboutsummaryrefslogtreecommitdiffstats
path: root/common/almalloc.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-10-08 11:05:36 -0700
committerChris Robinson <[email protected]>2021-10-08 11:05:36 -0700
commite3b8f8fe272503ef7f738da2f577f68b0fe16eeb (patch)
treedbcedc04132f1471f651984f9b5726678cca3443 /common/almalloc.h
parent8da4eaff29972aca8932c75084d1f1698da5e762 (diff)
Make a construct_at method amd use it
Diffstat (limited to 'common/almalloc.h')
-rw-r--r--common/almalloc.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/common/almalloc.h b/common/almalloc.h
index e0847eb1..df24c4a9 100644
--- a/common/almalloc.h
+++ b/common/almalloc.h
@@ -104,6 +104,11 @@ bool operator!=(const allocator<T,N>&, const allocator<U,M>&) noexcept { return
template<size_t alignment, typename T>
[[gnu::assume_aligned(alignment)]] inline T* assume_aligned(T *ptr) noexcept { return ptr; }
+
+template<typename T, typename ...Args>
+constexpr T* construct_at(T *ptr, Args&&...args) noexcept(noexcept(T{std::forward<Args>(args)...}))
+{ return ::new(static_cast<void*>(ptr)) T{std::forward<Args>(args)...}; }
+
/* At least VS 2015 complains that 'ptr' is unused when the given type's
* destructor is trivial (a no-op). So disable that warning for this call.
*/
@@ -250,7 +255,7 @@ struct FlexArray {
static std::unique_ptr<FlexArray> Create(index_type count)
{
void *ptr{al_calloc(alignof(FlexArray), Sizeof(count))};
- return std::unique_ptr<FlexArray>{new(ptr) FlexArray{count}};
+ return std::unique_ptr<FlexArray>{al::construct_at(static_cast<FlexArray*>(ptr), count)};
}
FlexArray(index_type size) : mStore{size} { }