std::basic_...nit_buf_ptrs(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

Okay bestie, welcome to the std::basic_...nit_buf_ptrs(3) page β€” that's the C++ Standard Library manual, and the main character is std::basic_stringbuf::init_buf_ptrs. 🫢


πŸŽ€ SYNOPSIS πŸŽ€

void init_buf_ptrs();  (exposition only*)

This little function initializes the input and output sequences from buf, following whatever mode says. Both buf and mode are exposition-only data members of *this β€” so they're part of the explanation, not regular public members you can just poke at. πŸ™ˆ

Immediately after this function returns:

  • If std::ios_base::out is set in mode, pbase() points to buf.front() and epptr() >= pbase() + buf.size() is true.
    • In addition, if std::ios_base::ate is set in mode, pptr() == pbase() + buf.size() is true.
    • Otherwise, pptr() == pbase() is true.
  • If std::ios_base::in is set in mode, eback() points to buf.front(), and gptr() == eback() && egptr() == eback() + buf.size() is true.

πŸ’… NOTES πŸ’…

Okay so efficiency, bestie: stream buffer operations can violate invariants of buf while it's held encapsulated in the std::basic_stringbuf. Example? Writing to characters in the range [buf.data() + buf.size(), buf.data() + buf.capacity()). It's giving "we bend the rules for speed." 😭

But all operations retrieving a std::basic_string from buf ensure that the std::basic_string invariants hold on the returned value. So the returned string stays valid and iconic. ✨

🩹 Defect reports 🩹

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. History said what it said, but the fix is the fix. 🩹

  • DR: LWG 1448
  • Applied to: C++98
  • Behavior as published: calling init_buf_ptrs() made pptr() == pbase() + buf.data() for streams that are both input and output streams
  • Correct behavior: makes pptr() == pbase() + buf.size() for append streams

Alright bestie, that's the whole vibe. πŸ¦‹ This gem came from cppreference.com, dated 2024.06.10, and the page is std::basic_...nit_buf_ptrs(3) β€” slay, bye! πŸ’–πŸ‘‘

πŸ“¦ where this page comes from