array/parray: add resize function

This commit is contained in:
Danny Robson 2019-06-02 11:09:58 +10:00
parent 3e08d64927
commit 04fd13fe42

View File

@ -8,6 +8,9 @@
#pragma once
#include "../debug/assert.hpp"
#include "../cast.hpp"
#include <algorithm>
#include <iterator>
#include <cstddef>
@ -45,6 +48,16 @@ namespace cruft {
parray (parray &&) noexcept = default;
parray& operator= (parray &&) noexcept = default;
// Only allows shrinking currently.
void resize (SizeT count)
{
CHECK_LE (count, m_size);
for (auto cursor = count; cursor < m_size; ++cursor)
m_data[cursor].~DataT ();
m_size = count;
}
DataT& operator[] (SizeT idx);
const DataT& operator[] (SizeT idx) const;