-
Notifications
You must be signed in to change notification settings - Fork 145
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
Refactor[MWC]: explicit operator= in mwcc containers #372
Conversation
Signed-off-by: Evgeny Malygin <[email protected]>
91a2d9b
to
a740c28
Compare
inline OrderedHashMap_SequentialIterator<VALUE>& | ||
OrderedHashMap_SequentialIterator<VALUE>::operator=(const NcIter& rhs) | ||
{ | ||
d_link_p = rhs.d_link_p; |
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.
Note that I decided to not to add checks for self-assignment, since we don't assign many fields, and just assign will be much faster than if
-branch.
We don't check for self-assignment for some small classes, for example
template <class VALUE>
inline WeakMemFnResult<VALUE>&
WeakMemFnResult<VALUE>::operator=(const WeakMemFnResult& original)
{
d_value.object() = original.d_value.object();
return *this;
}
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.
This makes sense, this is such a cheap object that we shouldn't worry about self-assignment.
Signed-off-by: Evgeny Malygin <[email protected]>
33c9bc0
to
4376a60
Compare
From what I gathered the
|
If I remove the original
These errors will remain even if I define from-const-iterator constructor
|
I just realized that the assignment operator is also double-purpose. It allows to assign a non-const iterator to a const one, and services as the copy-assignment operator. So it should be explicitly declared and implemented. -- this code is fine |
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.
Small nit, if you want to fix, go ahead and I'll reapprove; otherwise looks good.
@@ -296,6 +296,9 @@ class OrderedHashMap_SequentialIterator { | |||
|
|||
// MANIPULATORS | |||
|
|||
/// Assign to this object the value of the specified `rhs` object. | |||
OrderedHashMap_SequentialIterator& operator=(const NcIter&); |
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.
Nit: Because of the documentation comment, I think we want an rhs
name here (like in the other commit in this PR):
OrderedHashMap_SequentialIterator& operator=(const NcIter& rhs);
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.
Oh, I already force-pushed a fix for this. Might be GH lagging
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.
Huh, you're right! Looks good, go ahead and merge.
inline OrderedHashMap_SequentialIterator<VALUE>& | ||
OrderedHashMap_SequentialIterator<VALUE>::operator=(const NcIter& rhs) | ||
{ | ||
d_link_p = rhs.d_link_p; |
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.
This makes sense, this is such a cheap object that we shouldn't worry about self-assignment.
* Refactor[MWC]: explicit operator= in OrderedHashMap_SequentialIterator * Refactor[MWC]: explicit operator= in OrderedHashMapWithHistory_Iterator Signed-off-by: Evgeny Malygin <[email protected]>
* Refactor[MWC]: explicit operator= in OrderedHashMap_SequentialIterator * Refactor[MWC]: explicit operator= in OrderedHashMapWithHistory_Iterator Signed-off-by: Evgeny Malygin <[email protected]>
* Refactor[MWC]: explicit operator= in OrderedHashMap_SequentialIterator * Refactor[MWC]: explicit operator= in OrderedHashMapWithHistory_Iterator Signed-off-by: Evgeny Malygin <[email protected]>
Removing the custom copy constructor
OrderedHashMap_SequentialIterator(const NcIter& other);
doesn't work since it produces compilation errorsImplemented explicit
operator=
forOrderedHashMap_SequentialIterator
andOrderedHashMapWithHistory_Iterator