std::basic_...f::pbackfail(3)
π 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:
- 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 decrementsbasic_streambuf::gptr(), e.g. by callinggbump(-1). - 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 byTraits::eq(to_char_type(c), gptr()[-1])β then it simply decrementsbasic_streambuf::gptr(). Easy. Slay. π - Otherwise, if the buffer is allowed to modify its own get area, it decrements
basic_streambuf::gptr()and writescto the location pointed to bygptr()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 returnsTraits::eof()immediately. No file, no service, no discussion.
π PARAMETERS π
cβ the character to put back, orTraits::eof()to indicate that backing up of the get area is what's being requested.
β RETURN VALUE β
con success β except whencwasTraits::eof(), in which caseTraits::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 ofstd::basic_streambuf<CharT,Traits>sungetcβ moves the next pointer in the input sequence back by one. Public member function ofstd::basic_streambuf<CharT,Traits>sputbackcβ puts one character back in the input sequence. Public member function ofstd::basic_streambuf<CharT,Traits>ungetβ unextracts a character. Public member function ofstd::basic_istream<CharT,Traits>putbackβ puts a character into input stream. Public member function ofstd::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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms