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

add assignment operator to int_vector_buffer iterator #364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions include/sdsl/int_vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,19 @@ class int_vector_buffer
class iterator: public std::iterator<std::random_access_iterator_tag, value_type, difference_type, value_type*, reference>
{
private:
int_vector_buffer<t_width>& m_ivb;
int_vector_buffer<t_width>* m_ivb;
uint64_t m_idx = 0;
public:

iterator() = delete;
iterator(int_vector_buffer<t_width>& ivb, uint64_t idx=0) : m_ivb(ivb), m_idx(idx) {}
iterator(int_vector_buffer<t_width>& ivb, uint64_t idx=0) : m_ivb(&ivb), m_idx(idx) {}

iterator& operator=(const iterator& other)
{
m_ivb = other.m_ivb;
m_idx = other.m_idx;
return *this;
}

iterator& operator++()
{
Expand Down Expand Up @@ -524,7 +531,7 @@ class int_vector_buffer

reference operator*()const
{
return m_ivb[m_idx];
return (*m_ivb)[m_idx];
}

iterator& operator+=(difference_type i)
Expand All @@ -549,15 +556,15 @@ class int_vector_buffer
return it += i;
}

iterator& operator-(difference_type i) const
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't it enough to just remove the reference here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's enough to fix the bug, yes. This pull request is primarily about about adding an assignment operator though.

iterator operator-(difference_type i) const
{
iterator it = *this;
return it -= i;
}

bool operator==(const iterator& it) const
{
return &m_ivb == &(it.m_ivb) and m_idx == it.m_idx;
return m_ivb == it.m_ivb and m_idx == it.m_idx;
}

bool operator!=(const iterator& it) const
Expand Down