From 5196bed8aadf1f8cacda3f37db942e153e77a2fa Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 2 Jun 2020 13:57:40 +0200 Subject: [PATCH] Implement Remove function for UniquePtrList. --- src/Memory/UniquePtrList.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Memory/UniquePtrList.hpp b/src/Memory/UniquePtrList.hpp index 1ed9f43..bcbd44e 100644 --- a/src/Memory/UniquePtrList.hpp +++ b/src/Memory/UniquePtrList.hpp @@ -33,7 +33,7 @@ namespace ArbUt { inline BorrowedPtr At(size_t index) const { #ifndef NO_ASSERT - if (index >= _vector.size() || index < 0) { + if (index >= _vector.size()) { std::stringstream ss; ss << "Index " << index << " is out of bounds."; throw std::logic_error(ss.str()); @@ -42,6 +42,19 @@ namespace ArbUt { return _vector[index]; } + inline void Remove(size_t index){ +#ifndef NO_ASSERT + if (index >= _vector.size()) { + std::stringstream ss; + ss << "Index " << index << " is out of bounds."; + throw std::logic_error(ss.str()); + } +#endif + auto item = _vector.at(index); + delete item; + _vector.erase(index); + } + inline bool Contains(const BorrowedPtr& value) const { return std::find(_vector.begin(), _vector.end(), value) != _vector.end(); }