Skip to content

Commit

Permalink
Use pointer to the container for int_vector_buffer iterator
Browse files Browse the repository at this point in the history
Using reference member prevents defining assignment operator for the
iterator class of int_vector_buffer. This commit fixes simongog#436.
  • Loading branch information
cartoonist committed Dec 8, 2020
1 parent c32874c commit b14bb04
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/sdsl/int_vector_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class int_vector_buffer
class iterator;
typedef typename int_vector<t_width>::difference_type difference_type;
typedef typename int_vector<t_width>::value_type value_type;
typedef typename int_vector<t_width>::size_type size_type;

private:
static_assert(t_width <= 64 , "int_vector_buffer: width must be at most 64 bits.");
Expand Down Expand Up @@ -489,12 +490,12 @@ 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++()
{
Expand Down Expand Up @@ -524,7 +525,7 @@ class int_vector_buffer

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

iterator& operator+=(difference_type i)
Expand Down Expand Up @@ -557,7 +558,7 @@ class int_vector_buffer

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

0 comments on commit b14bb04

Please sign in to comment.