Skip to content

Commit 639b1dc

Browse files
committed
Last read was always empty. Inastanciating the iterator would also yield an empty span, which results in svs::take() etc. not working correctly.
1 parent a6f3e14 commit 639b1dc

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

source/centipede/reader/binary.hpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,34 +176,35 @@ namespace centipede::reader
176176
explicit Iterator(Binary* reader_ptr)
177177
: reader_{ reader_ptr }
178178
{
179+
++(*this);
179180
}
180181

181182
using iterator_category = std::input_iterator_tag;
182183
using difference_type = std::ptrdiff_t;
183184
using value_type = EntryResult;
184-
using reference = EntryResult;
185+
using reference = const EntryResult&;
185186

186-
auto operator*() const -> EntryResult
187-
{
188-
if (has_error_)
189-
{
190-
return std::unexpected{ error_ };
191-
}
192-
return reader_->get_current_entry();
193-
}
187+
auto operator*() const -> const EntryResult& { return current_; }
194188

195189
auto operator++() -> Iterator&
196190
{
197191
auto result = reader_->read_one_entry();
192+
198193
if (not result)
199194
{
200-
has_error_ = true;
201-
error_ = result.error();
195+
current_ = std::unexpected{ result.error() };
196+
done_ = false;
197+
return *this;
202198
}
203-
else
199+
200+
if (reader_->is_end_of_file() || result.value() == 0U)
204201
{
205-
has_error_ = false;
202+
done_ = true;
203+
return *this;
206204
}
205+
206+
current_ = reader_->get_current_entry();
207+
done_ = false;
207208
return *this;
208209
}
209210

@@ -214,12 +215,12 @@ namespace centipede::reader
214215
return tmp;
215216
}
216217

217-
auto operator!=(const Sentinel&) const -> bool { return not reader_->is_end_of_file(); }
218+
auto operator!=(const Sentinel&) const -> bool { return not done_; }
218219

219220
private:
220-
Binary* reader_;
221-
ErrorCode error_;
222-
bool has_error_{ false };
221+
Binary* reader_{};
222+
EntryResult current_{ EntrySpan{} };
223+
bool done_{ false };
223224
};
224225
auto begin() -> Iterator { return Iterator{ this }; }
225226
auto end() const -> Sentinel { return Sentinel{}; }

0 commit comments

Comments
 (0)