Skip to content

Commit fc95fa0

Browse files
fix: wrong value for buffered file size (#95)
1 parent 1e702cf commit fc95fa0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

include/rusty_iterators/file_iterator.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,25 @@ class FileIterator<FIterType::Buffered>
4444
fileLines.push_back(std::move(nextLine));
4545
}
4646
is.close();
47+
ptr = fileLines.begin();
4748
};
4849

4950
auto next() -> std::optional<std::string>
5051
{
51-
[[unlikely]] if (ptr == fileLines.size())
52+
[[unlikely]] if (ptr == fileLines.end())
5253
{
5354
return std::nullopt;
5455
}
55-
auto line = fileLines.at(ptr);
56+
auto line = *ptr;
5657
ptr += 1;
5758
return std::move(line);
5859
}
5960

60-
[[nodiscard]] auto sizeHint() const -> std::optional<size_t> { return fileLines.size(); }
61+
[[nodiscard]] auto sizeHint() const -> std::optional<size_t> { return fileLines.end() - ptr; }
6162

6263
private:
63-
size_t ptr = 0;
6464
std::vector<std::string> fileLines{};
65+
std::vector<std::string>::iterator ptr;
6566
};
6667

6768
template <>

0 commit comments

Comments
 (0)