20 char* begin =
const_cast<char*
>(view.data());
21 char* end = begin + view.size();
22 this->setg(begin, begin, end);
26 std::streamsize xsgetn(
char* s, std::streamsize count)
override {
27 const std::streamsize avail = this->egptr() - this->gptr();
28 const std::streamsize n = std::min(avail, count);
30 std::memcpy(s, this->gptr(),
static_cast<size_t>(n));
31 this->gbump(
static_cast<int>(n));
36 pos_type seekoff(off_type off, std::ios_base::seekdir dir,
37 std::ios_base::openmode which = std::ios_base::in)
override {
38 if (!(which & std::ios_base::in)) {
39 return pos_type(off_type(-1));
42 const auto begin = this->eback();
43 const auto curr = this->gptr();
44 const auto end = this->egptr();
47 if (dir == std::ios_base::beg) {
50 else if (dir == std::ios_base::cur) {
51 base =
static_cast<off_type
>(curr - begin);
53 else if (dir == std::ios_base::end) {
54 base =
static_cast<off_type
>(end - begin);
57 return pos_type(off_type(-1));
60 const off_type next = base + off;
61 const off_type size =
static_cast<off_type
>(end - begin);
62 if (next < 0 || next > size) {
63 return pos_type(off_type(-1));
66 this->setg(begin, begin + next, end);
67 return pos_type(next);
70 pos_type seekpos(pos_type pos,
71 std::ios_base::openmode which = std::ios_base::in)
override {
72 return this->seekoff(off_type(pos), std::ios_base::beg, which);