From 08615ee80e5ce21599fa67263e34e55f875cee2a Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Tue, 30 Jul 2024 07:24:17 +0300 Subject: [PATCH] Added overload to getAndDetach that accepts a constant reference to allow usage of temporaries to point to members. (such as immediately using the result of begin()). (#1512) --- Common++/header/PointerVector.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Common++/header/PointerVector.h b/Common++/header/PointerVector.h index 299c190033..bd04b38261 100644 --- a/Common++/header/PointerVector.h +++ b/Common++/header/PointerVector.h @@ -302,6 +302,18 @@ namespace pcpp return result; } + /** + * Removes an element from the vector and transfers ownership to the returned unique pointer. + * @param[in] position An iterator pointing to the element to detach. + * @return An unique pointer that holds ownership of the detached element. + */ + std::unique_ptr getAndDetach(VectorIterator const& position) + { + std::unique_ptr result(*position); + m_Vector.erase(position); + return result; + } + /** * Return a pointer to the element in a certain index * @param[in] index The index to retrieve the element from