Background
I implement a JSON parser and offer a function operator>>to parse from std::ifstream. To speed up the reading, I copy 16 KB to the buffer and let my parser read from the buffer. A small benchmark showed that it is faster than working directly with std::ifstream::getor std::ifstream::read.
Realization of the current (buggy?)
When I successfully read the JSON value, I want to "return" all unnecessary bytes from the buffer to the stream so that the subsequent call operator>>with the same std::istreamcontinues parsing right where the first call ended. I am currently implementing this “return” as follows:
is.clear();
is.seekg(start_position + static_cast<std::streamoff>(processed_chars));
is.clear();
Thus, is- this is the stream of input files, start_position- this is the initial value is.tellg()and the processed_charsnumber of characters read by the parser.
This works with GCC and Clang with OSX and Linux, but MSVC 2015 and MSVC 2017 cannot bring the input stream to the desired state.
My questions
Apparently I'm doing something wrong. Different compilers should not behave differently. The call is clear()already the result of a trial error and an error so that the code is executed using GCC / Clang.
What would be the correct way to (a) read from a std::ifstreamcache that has already been opened and (b) be able to resume parsing after the last processed character (instead, after the last cached character)?
std::ifstream? , .
( ! , std::ifstream "" .)