std::basic_stringbuf<CharT,Traits,Allocator>::init_buf_ptrs
来自 cppreference.cn
< cpp | io | basic stringbuf
void init_buf_ptrs(); |
(仅作说明*) | |
根据 mode,从 buf 初始化输入和输出序列。buf 和 mode 是 *this 的仅用于阐释的数据成员。
此函数返回后,立即
- 若 std::ios_base::out 在 mode 中设置,则 pbase() 指向 buf.front(),且 epptr() >= pbase() + buf.size() 为 true;
- 此外,若 std::ios_base::ate 在 mode 中设置,则 pptr() == pbase() + buf.size() 为 true,
- 否则 pptr() == pbase() 为 true。
- 若 std::ios_base::in 在 mode 中设置,则 eback() 指向 buf.front(),且 gptr() == eback() && egptr() == eback() + buf.size() 为 true。
[编辑] 注解
出于效率原因,当 buf 被封装在 std::basic_stringbuf
中时,流缓冲区的操作可能会违反 buf 的不变式,例如,通过写入到 [
buf.data() + buf.size(),
buf.data() + buf.capacity())
范围内的字符。
所有从 buf 检索 std::basic_string 的操作都会确保返回的 std::basic_string 值满足其不变式。
[编辑] 缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 发布时的行为 | 正确的行为 |
---|---|---|---|
LWG 1448 | C++98 | 调用 init_buf_ptrs() 会使pptr() == pbase() + buf.data() 对于同时用于输入和输出的流 |
使 pptr() == pbase() + buf.size() 对于附加流 |