std::basic_ios::init(3)

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

✨ NAME ✨

std::basic_ios::init β€” std::basic_ios::init

okay so this is the manual page for std::basic_ios::init(3) from the C++ Standard Libary manual, and it's giving two-stage initialization realness. πŸŽ€

πŸŒ€ Synopsis πŸŒ€

protected:
void init( std::basic_streambuf<CharT,Traits>* sb );

This one sets the associated stream buffer to sb and initializes the internal state. Slay. πŸ’…

The postconditions are as follows πŸ’–

  • rdbuf() β€” sb
  • tie() β€” null pointer
  • rdstate() β€” goodbit if sb is not a null pointer, otherwise badbit
  • exceptions() β€” goodbit
  • flags() β€” skipws | dec
  • width() β€” 0
  • precision() β€” 6
  • fill() β€” widen(' ')
  • getloc() β€” a copy of the value returned by std::locale()

This member function is protected: it is called by the constructors of the derived stream classes std::basic_istream and std::basic_ostream once the associated stream buffer is known. 🫢

Until this function is called, every member function (including the destructor) of the default-constructed std::basic_ios invokes undefined behavior. No cap, that's the scary part. 😭

Also note that basic_ios is a virtual base class, and therefore its constructor is not called by the constructors of those directly derived classes β€” which is why two-stage initialization is necessary. Iykyk. πŸ¦‹

🌸 Parameters 🌸

  • sb β€” stream buffer to associate to.

πŸ‘€ See also πŸ‘€

  • constructor β€” constructs the object (public member function) ✨

πŸ’– source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::basic_ios::init(3) β€” love u bestie, go init something safely πŸ’…πŸŽ€

πŸ“¦ where this page comes from