Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documentation for std::basic_filebuf::seekpos

I have studied documentation page for std::basic_filebuf::seekpos provided by cppreference.com and got confused by the following sentence:

If the file is open for reading, updates the get area if necessary.

As far as I can see on my computer, seekpos ends up with eback()==gptr()==egptr(), i.e. function empties get area. Does this mean that get area has been updated? It would be very nice, if someone could clarify it. Thank you!

like image 754
Baykov Nikita Avatar asked Jan 01 '26 13:01

Baykov Nikita


1 Answers

From further down the page:

Many implementations do not update the get area in seekpos(), delegating to underflow() that is called by the next sgetc()

and:

on some implementations, the get area is emptied by seekpos() and the second underflow() is necessary to observe the effects

Looks like that's what happened to you.

It is open to interpretation as to what "update" means. The standard is very flexible here (note the lack of explicit postconditions), basically saying "the implementation gets to do whatever it needs to do in order to carry out its business".

In this particular case, your filebuf implementation probably emptied the get area when you seeked, then will "fill" it on the next underflow() — arguably both operations in concert are the "update", but to be honest you can spin it whichever way you like.

like image 115
Lightness Races in Orbit Avatar answered Jan 03 '26 03:01

Lightness Races in Orbit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!