Skip to content

Commit

Permalink
allocate with alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
rabauke committed Oct 26, 2023
1 parent a5a6bab commit 2b32d37
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mpl/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ namespace mpl::detail {
}

explicit vector(size_type size, uninitialized)
: size_{size}, data_{static_cast<pointer>(operator new(size_ * sizeof(T)))} {
: size_{size},
data_{static_cast<pointer>(operator new(size_ * sizeof(T),
std::align_val_t{alignof(T)}))} {
if (not std::is_trivially_copyable<value_type>::value)
for (size_type i{0}; i < size; ++i)
new (&data_[i]) value_type();
}

template<typename IterT>
explicit vector(size_type size, IterT iter)
: size_{size}, data_{static_cast<pointer>(operator new(size_ * sizeof(T)))} {
: size_{size},
data_{static_cast<pointer>(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;
Expand Down

0 comments on commit 2b32d37

Please sign in to comment.