From 2b32d37956e69465628fb17dbcd672ae3a9c4c9d Mon Sep 17 00:00:00 2001 From: Heiko Bauke Date: Thu, 26 Oct 2023 21:28:00 +0200 Subject: [PATCH] allocate with alignment --- mpl/vector.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mpl/vector.hpp b/mpl/vector.hpp index bbf06858..9d60be45 100644 --- a/mpl/vector.hpp +++ b/mpl/vector.hpp @@ -33,7 +33,9 @@ namespace mpl::detail { } explicit vector(size_type size, uninitialized) - : size_{size}, data_{static_cast(operator new(size_ * sizeof(T)))} { + : size_{size}, + data_{static_cast(operator new(size_ * sizeof(T), + std::align_val_t{alignof(T)}))} { if (not std::is_trivially_copyable::value) for (size_type i{0}; i < size; ++i) new (&data_[i]) value_type(); @@ -41,7 +43,9 @@ namespace mpl::detail { template explicit vector(size_type size, IterT iter) - : size_{size}, data_{static_cast(operator new(size_ * sizeof(T)))} { + : size_{size}, + data_{static_cast(operator new(size_ * sizeof(T), + std::align_val_t{alignof(T)}))} { for (size_type i{0}; i < size; ++i) { new (&data_[i]) value_type(*iter); ++iter;