From 6441a67783fda5e49a38cd369b65487752f6707d Mon Sep 17 00:00:00 2001 From: Ali Ghaffaari Date: Wed, 4 Jan 2023 18:49:20 +0100 Subject: [PATCH 1/2] Use pointer to the container for int_vector_buffer iterator Using reference member prevents defining assignment operator for the iterator class of int_vector_buffer. This commit fixes issue vgteam/sdsl-lite#436. --- include/sdsl/int_vector_buffer.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/sdsl/int_vector_buffer.hpp b/include/sdsl/int_vector_buffer.hpp index 1c3ccb98..7c28cca5 100644 --- a/include/sdsl/int_vector_buffer.hpp +++ b/include/sdsl/int_vector_buffer.hpp @@ -30,6 +30,7 @@ class int_vector_buffer typedef typename int_vector::difference_type difference_type; typedef typename int_vector::value_type value_type; + typedef typename int_vector::size_type size_type; private: static_assert(t_width <= 64, "int_vector_buffer: width must be at most 64 bits."); @@ -493,7 +494,7 @@ class int_vector_buffer class iterator { private: - int_vector_buffer & m_ivb; + int_vector_buffer * m_ivb; uint64_t m_idx = 0; public: @@ -504,7 +505,7 @@ class int_vector_buffer using reference = sdsl::int_vector_buffer::reference; iterator() = delete; - iterator(int_vector_buffer & ivb, uint64_t idx = 0) : m_ivb(ivb), m_idx(idx) + iterator(int_vector_buffer & ivb, uint64_t idx = 0) : m_ivb(&ivb), m_idx(idx) {} iterator & operator++() @@ -535,7 +536,7 @@ class int_vector_buffer reference operator*() const { - return m_ivb[m_idx]; + return (*m_ivb)[m_idx]; } iterator & operator+=(difference_type i) @@ -568,7 +569,7 @@ class int_vector_buffer bool operator==(iterator const & 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!=(iterator const & it) const From c181c7b125c0917dc2b1a6be7174b97453fa92df Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 11 Sep 2023 12:26:13 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- include/sdsl/int_vector_buffer.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/sdsl/int_vector_buffer.hpp b/include/sdsl/int_vector_buffer.hpp index 7c28cca5..9dcb8567 100644 --- a/include/sdsl/int_vector_buffer.hpp +++ b/include/sdsl/int_vector_buffer.hpp @@ -494,7 +494,7 @@ class int_vector_buffer class iterator { private: - int_vector_buffer * m_ivb; + int_vector_buffer * m_ivb{nullptr}; uint64_t m_idx = 0; public: @@ -536,6 +536,7 @@ class int_vector_buffer reference operator*() const { + assert(m_ivb != nullptr); return (*m_ivb)[m_idx]; }