0

I'm trying to implement a input_seekable source with boost iostreams. The source uses fixed data from a char array. The reading works so far but I'm having a problem with the seek function.

The documentation https://www.boost.org/doc/libs/1_75_0/libs/iostreams/doc/index.html shows an example for a container device where the seek function is implemented. Lets say I need to construct an istream from a streambuffer with the implemented source and I use seekg(0, std::ios_base::end) to get to the end of the stream to use tellg() for the stream size.

What is the intended behavior of tellg()? As is understand it seekg(0, std::ios_base::end) will put the read pointer one past the last element in the buffer so tellg will return the number of bytes in the stream. The implementation the documentation points to the last element which would lead to tellg reporting the wrong number of bytes.

Gustavo
  • 919
  • 11
  • 34

1 Answers1

0

You don't need to implement tellg, seek returns the current offset so iostreams implements tellg as seek(0, std::ios_base::cur).

https://www.boost.org/doc/libs/1_75_0/libs/iostreams/doc/concepts/seekable_device.html

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • I didn't implement tellg but seek like in the link I provided. The problem is my understanding of the read pointer and how seek is implemented. – Gustavo Jun 06 '23 at 19:00