array/parray: add erase function

This commit is contained in:
Danny Robson 2019-06-02 11:10:31 +10:00
parent bca58bf352
commit 07840dbc54

View File

@ -80,6 +80,30 @@ namespace cruft {
SizeT size (void) const; SizeT size (void) const;
bool empty (void) const { return size () == 0; } bool empty (void) const { return size () == 0; }
template <
typename T = DataT,
typename = std::enable_if_t<std::is_move_assignable_v<T>>
>
DataT*
erase (DataT *first, DataT *last)
{
DataT *newend = std::move (last, m_data + m_size, first);
for (auto cursor = newend; cursor != end (); ++cursor)
cursor->~DataT ();
m_size = cruft::cast::lossless<SizeT> (newend - m_data);
return newend;
}
template <
typename T = DataT,
typename = std::enable_if_t<std::is_move_assignable_v<T>>
>
DataT*
erase (DataT *item)
{
return erase (item, item + 1);
}
private: private:
SizeT m_size; SizeT m_size;
DataT *m_data; DataT *m_data;