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