std::strstr...::pbackfail(3)

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

πŸ’… 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 strstreambuf has 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 calling gbump(-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 decrements basic_streambuf::gptr(). easy win πŸ’–
  • c) Otherwise, if the buffer is unmodifiable (this strstreambuf was 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 writes c to the location pointed to gptr() after adjustment. now that's main character energy πŸ‘‘

πŸ¦‹ Parameters πŸ¦‹

  • c β€” the character to put back, or Traits::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 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

(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