Skip to content

Conversation

@joancarreras
Copy link

  • TBD

Copy link
Collaborator

@lurume84 lurume84 left a 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


// Array iterator for range-loop
template <typename BaseIterator_, typename Ref_>
class ArrayIterator_ : public BaseIterator_
Copy link
Collaborator

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

Copy link
Author

@joancarreras joancarreras Oct 14, 2021

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)


Ref_ operator*() const
{
const BaseIterator_ it = *this;
Copy link
Collaborator

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

{
public:

virtual ~ArrayIterator_() = default;
Copy link
Collaborator

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

Copy link
Author

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>>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants