Skip to content
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

Change ArenaVector<T>::Iterator to satisfy standard (Legacy)RandomAccessIterator concept #1962

Merged
merged 2 commits into from
Mar 26, 2019

Conversation

Ryooooooga
Copy link
Contributor

@Ryooooooga Ryooooooga commented Mar 22, 2019

to pass iterators to the functions defined in <algorithm>.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ryooooooga! Some comments below.

}

bool operator<(const Iterator& other) const {
return (parent->data + index) < (other.parent->data + other.index);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's enough to compare the indexes here - as the parent must be identical? (perhaps we should assert on that?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a < b must be equal to b - a > 0 [*1], I agree that it is better to order only among iterators with the same parent.
509dd76
*1: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator

}

T* operator->() const {
return &(*parent)[index];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it common to define () to be identical to * like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not operator () but operator -> to allow it->member_of_T.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, right, I misread that.

@kripken
Copy link
Member

kripken commented Mar 26, 2019

Great, thanks again @Ryooooooga!

@kripken kripken merged commit c5a22ba into WebAssembly:master Mar 26, 2019
@Ryooooooga Ryooooooga deleted the random-access-iterator branch July 19, 2019 14:00
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