From 04fd13fe427c39c71ef980ae13fdc58be53137bb Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 2 Jun 2019 11:09:58 +1000 Subject: [PATCH] array/parray: add resize function --- array/parray.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/array/parray.hpp b/array/parray.hpp index a058fe2c..c468c4d4 100644 --- a/array/parray.hpp +++ b/array/parray.hpp @@ -8,6 +8,9 @@ #pragma once +#include "../debug/assert.hpp" +#include "../cast.hpp" + #include #include #include @@ -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;