-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PointerVector
smart pointer intergration.
#1468
PointerVector
smart pointer intergration.
#1468
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just adding some reminders of things I noticed, that I should probably fix.
@@ -56,7 +56,9 @@ namespace pcpp | |||
* @param[in] other The vector to move from. | |||
*/ | |||
PointerVector(PointerVector&& other) noexcept : m_Vector(std::move(other.m_Vector)) | |||
{} | |||
{ | |||
other.m_Vector.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems redundant, because when people call moving constructor, they suppose to not to use the object anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector
's move ctor technically does not have a well defined state after move. The standard just says it should be in a valid state, but it does not guarantee it will always be empty state. It usually is, but that is implementation defined.
If for some reason, an implementation left the vector non-empty, the destructor will attempt to iterate through the values and call delete on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. thanks for the explanation.
PointerVector
smart pointer intergration.
Core changes to
PointerVector
:pushBack
that acceptsunique_ptr<T>
.getAndDetach
that work analogous togetAndRemoveFromVector
but returnunique_ptr<T>
.const
overloads tofront()
/back()
accessors.nullptr
is being pushed into the vector.