std::strstr...::pbackfail(3)
π std::strstr...::pbackfail(3) π
okay bestie so this is a page straight out of the C++ Standard Libary (yes that's how the header spells it, we're not fixing it, it's iconic) β and it's all about std::strstreambuf::pbackfail, which is a whole mood. π
β¨ NAME β¨
std::strstreambuf::pbackfail β literally the same thing twice because that's how C++ rolls π
πΈ Synopsis πΈ
protected: (deprecated in
C++98)
virtual int_type pbackfail( int_type c = EOF ); (removed in C++26)
so before we even get into it β yes, this function is deprecated in C++98 and removed in C++26. it's giving vintage. it's giving "your mom's C++" π«Ά
This protected virtual function is called by the public functions basic_streambuf::sungetc and basic_streambuf::sputbackc (which, in turn, are called by basic_istream::unget and basic_istream::putback). so it's like a whole chain of besties asking each other for a favor π
1) The caller is requesting that the get area is backed up by one character β that's when pbackfail() gets called with no arguments or with EOF as the argument. and then:
- a) First thing it does: checks if there is a putback position, and if there really isn't, it fails (because
strstreambufhas no external character source to re-read β no take-backs, no re-dos, nothing to go back to π). - b) But if the caller was wrong and the putback position is in fact available? Simply decrements
basic_streambuf::gptr(), e.g. by callinggbump(-1). slay, that was easy β¨
2) The caller attempts to putback a different character from the one retrieved earlier β that's when pbackfail() is called with the character that needs to be put back. in which case:
- a) First, checks if there is a putback position, and if there isn't, fails. same energy as before, no position no party π
- b) Then checks what character is in the putback position. If the character held there is already equal to
(char)c, then simply decrementsbasic_streambuf::gptr(). easy win π - c) Otherwise, if the buffer is unmodifiable (this
strstreambufwas constructed with a string literal or some other const array), it fails. periodt. nothing you can do, it's frozen π§ - d) Otherwise, decrements
basic_streambuf::gptr()and writescto the location pointed togptr()after adjustment. now that's main character energy π
π¦ Parameters π¦
cβ the character to put back, orTraits::eof()to indicate that backing up of the get area is requested. (basically "put this back" vs "just rewind the tape bestie" π)
π₯ Return value π₯
c on success β except if c was EOF, in which case an unspecified value other than EOF is returned. like, it comes back but it's mysterious about it π
EOF on failure. that's the sad path and we don't talk about it π
β Example β
This section is incomplete. Reason: no example.
ngl the cppreference girlies left this one blank, so no example for us π«Ά (see Category below, it's literally in the todo list π )
π 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
(yup. that's the whole category. it's giving "assigned but not started" π)
so yeah bestie, that's the whole page β no cap, every last flag and failure mode is right there π and before you go, the receipts: this came from cppreference.com, dated 2024.06.10. go forth and put those characters back, icon π§β¨
π¦ 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