std::basic_stringbuf<CharT,Traits,Allocator>::init_buf_ptrs
從 cppreference.com
< cpp | io | basic stringbuf
void init_buf_ptrs(); |
(僅用於闡述*) | |
根據 mode,以 buf 初始化輸入和輸出序列。buf 和 mode 是 *this 的 僅用於闡述的數據成員。
在此函數返回後立即滿足以下條件:
- 如果 mode 中設置了 std::ios_base::out,那麼 pbase() 指向 buf.front() 且 epptr() >= pbase() + buf.size() 是 true;
- 另外,如果 mode 中設置了 std::ios_base::ate,那麼 pptr() == pbase() + buf.size() 是 true,
- 否則 pptr() == pbase() 是 true。
- 如果 mode 中設置了 std::ios_base::in,那麼 eback() 指向 buf.front() 且 gptr() == eback() && egptr() == eback() + buf.size() 是 true。
[編輯] 註解
考慮到效率原因,流緩衝區操作可能會違背封裝在 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() |