Skip to content

Commit

Permalink
Added overload to getAndDetach that accepts a constant reference to a…
Browse files Browse the repository at this point in the history
…llow usage of temporaries to point to members. (such as immediately using the result of begin()). (#1512)
  • Loading branch information
Dimi1010 authored Jul 30, 2024
1 parent 09f479f commit 08615ee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Common++/header/PointerVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> getAndDetach(VectorIterator const& position)
{
std::unique_ptr<T> 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
Expand Down

0 comments on commit 08615ee

Please sign in to comment.