std::basic_...f::pbackfail(3)

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

πŸ’… NAME πŸ’…

std::basic_filebuf::pbackfail β€” yes bestie, that's literally the whole name, it's giving "I am the function and I know it" ✨

So before we even get into it: this page lives in the C++ Standard Libary manual (that spelling? not mine, I'm just the messenger 🫢), and it's page std::basic_...f::pbackfail(3). Periodt.


✨ SYNOPSIS ✨

protected:
virtual int_type pbackfail( int_type c = Traits::eof() )

🌸 DESCRIPTION 🌸

Okay so, this is a protected virtual function, and the way it gets summoned is lowkey indirect: the public functions basic_streambuf::sungetc and basic_streambuf::sputbackc call it β€” and those, in turn, get called by basic_istream::unget and basic_istream::putback. It's giving backstage crew energy: never on stage, runs everything. πŸ‘‘

Here's the vibe check on the two situations:

  1. The caller wants the get area backed up by one character, and pbackfail() gets called with no arguments. In that case, this function re-reads the file starting one byte earlier and decrements basic_streambuf::gptr(), e.g. by calling gbump(-1).
  2. The caller is trying to put back a different character from the one retrieved earlier β€” so pbackfail() is called with the character that needs to be put back. Then:
    • First, it checks if there's a putback position, and if there isn't, it backs up the get area by re-reading the file starting one byte earlier.
    • Then it checks what character is actually sitting in the putback position. If the character held there is already equal to c β€” as determined by Traits::eq(to_char_type(c), gptr()[-1]) β€” then it simply decrements basic_streambuf::gptr(). Easy. Slay. πŸ’…
    • Otherwise, if the buffer is allowed to modify its own get area, it decrements basic_streambuf::gptr() and writes c to the location pointed to by gptr() after the adjustment.
🫢 Big important note: this function never modifies the file β€” only the get area of the in-memory buffer. The file itself stays untouched, unbothered, flourishing.
😭 Also: if the file is not open (is_open()==false), this function returns Traits::eof() immediately. No file, no service, no discussion.

πŸŽ€ PARAMETERS πŸŽ€

  • c β€” the character to put back, or Traits::eof() to indicate that backing up of the get area is what's being requested.

⭐ RETURN VALUE ⭐

  • c on success β€” except when c was Traits::eof(), in which case Traits::not_eof(c) is what comes back at you.
  • Traits::eof() on failure. πŸ™ˆ

πŸ¦‹ EXAMPLE πŸ¦‹

This section is incomplete.

Reason: no example.

(yeah. that's it. that's the example section. we move. πŸ’€)

🌈 SEE ALSO 🌈

  • pbackfail β€” puts a character back into the input sequence, possibly modifying the input sequence. [virtual] β€” virtual protected member function of std::basic_streambuf<CharT,Traits>
  • sungetc β€” moves the next pointer in the input sequence back by one. Public member function of std::basic_streambuf<CharT,Traits>
  • sputbackc β€” puts one character back in the input sequence. Public member function of std::basic_streambuf<CharT,Traits>
  • unget β€” unextracts a character. Public member function of std::basic_istream<CharT,Traits>
  • putback β€” puts a character into input stream. Public member function of std::basic_istream<CharT,Traits>

πŸ“ CATEGORY πŸ“

  • Todo: no example

okay that's the whole page bestie, go put those characters back πŸ’œ

🧚 Sign-off time: this was std::basic_...f::pbackfail(3) from http://cppreference.com, dated 2024.06.10. Iconic. No cap. βœ¨πŸ‘‘
πŸ“¦ where this page comes from