-
Notifications
You must be signed in to change notification settings - Fork 4
Added support for range based loop #2
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
base: master
Are you sure you want to change the base?
Conversation
joancarreras
commented
Oct 13, 2021
- TBD
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 understand this iterator inheritance is the whole point of the implementation. Since ArrayIterator_ class does not have members there should not be any memory leak because of parent's non-virtual destructor, so I'm ok with it.
However, I would suggest to address the two other comments
JSONAdapterInterface/IJSONValue.h
Outdated
|
|
||
| // Array iterator for range-loop | ||
| template <typename BaseIterator_, typename Ref_> | ||
| class ArrayIterator_ : public BaseIterator_ |
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.
it is normally considered bad practice to inherit from STL (in this case vector's iterator) as they do not declare dtor virtual on purpose
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.
The implementation of the whole class has changed in order to be unrelated to the vector<unique_ptr> (because it reveals the current way to store values contained in the JSONValue implementation, something inherent in the implementation but not in the interface)
JSONAdapterInterface/IJSONValue.h
Outdated
|
|
||
| Ref_ operator*() const | ||
| { | ||
| const BaseIterator_ it = *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.
original implementation does this function in one line
reference operator*() const
{ // return designated object
return ((reference)**(_Mybase *)this);
}
I recommend condensing it also in one line to reduce code
JSONAdapterInterface/IJSONValue.h
Outdated
| { | ||
| public: | ||
|
|
||
| virtual ~ArrayIterator_() = default; |
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.
not needed as this is a final class, adding this virtual method implies allocating vtable unnecessarily
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.
Yes, I agree, thanks! (as a previous approach I had considered making this class as an 'IArrayIterator' interface; because of this the 'virtual' in the destructor has remained here without being necessary now)
Redesign of ArrayIterator class for range base loops, in order to lean on the existing virtual method IJSONValue::getArrayValue(), avoiding to mention vector<unique_ptr<IJSONValue>>.