std::basic_stringbuf<CharT,Traits,Allocator>::init_buf_ptrs

從 cppreference.com
< cpp‎ | io‎ | basic stringbuf
 
 
 
 
void init_buf_ptrs();
(僅用於闡述*)

根據 mode,以 buf 初始化輸入和輸出序列。bufmode*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()