std::basic_ios::basic_ios(3)

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

πŸŽ€ std::basic_ios::basic_ios πŸŽ€

Ok so welcome to the C++ Standard Libary manpage for std::basic_ios::basic_ios(3) β€” constructor edition, and yes, we are getting into it. πŸ’…

πŸ’– NAME πŸ’–

std::basic_ios::basic_ios β€” this is the constructor page for std::basic_ios, bestie. That's the name, that's the vibe. 🫢

✨ Synopsis ✨

It literally constructs a new std::basic_ios object. Here's the signature situation, exactly as the manual lays it out:

          protected:                                                     (1)
          basic_ios();
          public:                                                        (2)
          explicit basic_ios( std::basic_streambuf<CharT, Traits>* sb );
          private:
       (until C++11)
          basic_ios( const basic_ios& );                                 (3)
          public:
       (since C++11)
          basic_ios( const basic_ios& ) = delete;

The numbered tea β˜•:

  1. Default constructor β€” the internal state is not initialized. init() must be called before the first use of the object or before the destructor, otherwise the behavior is undefined. No cap, that's a real "handle your initialization" warning. 😭
  2. basic_ios( std::basic_streambuf<CharT, Traits>* sb ) β€” initializes the internal state by calling init(sb). The associated stream buffer is set to sb.
  3. Copy constructor β€” it's declared private and not defined (until C++11), and since C++11 it's explicitly defined as deleted. The reason is iconic: I/O streams are not CopyConstructible. Periodt. πŸ’€

🌸 Parameters 🌸

  • sb β€” stream buffer to associate to. That's the whole parameter list, and she's doing her job. πŸ¦‹

πŸŽ€ Defect reports πŸŽ€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • DR LWG 1249 β€” applied to C++98. Behavior as published: internal state did not need to be initialized before first use. Correct behavior: also needs to be initialized. πŸ’–

πŸ’– that's the whole page, bestie β€” source: http://cppreference.com, version/date: 2024.06.10. Now go initialize your internal state before first use, fr fr. πŸ’…βœ¨

πŸ“¦ where this page comes from