std::basic_...asic_syncbuf(3)

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

✨ NAME ✨

okay so bestie, this is the std::basic_syncbuf::basic_syncbuf page from the C++ Standard Libary man pages (yes, that's literally how the header spells it, and honestly? iconic of them πŸ’…). It's all about the constructors for std::basic_syncbuf β€” the default one, the wrapping one, the allocator one, and the move one. Buckle up, we're getting into constructor lore πŸŽ€


🌸 Synopsis 🌸

basic_syncbuf()                                            (1)
    : basic_syncbuf( nullptr )
explicit basic_syncbuf( streambuf_type* obuf )             (2)
    : basic_syncbuf( obuf, Allocator() ) {}
basic_syncbuf( streambuf_type* obuf, const Allocator& a ); (3)
basic_syncbuf( basic_syncbuf&& rhs );                      (4)
  1. Default constructor β€” creates an instance of std::basic_syncbuf with the emit-on-sync policy set to false, the wrapped streambuffer set to nullptr, and using a default-constructed Allocator as the allocator for temporary storage. No cap, it literally starts with nothing wrapped and nothing emitted. Lowkey humble of it πŸ’–
  2. explicit basic_syncbuf( streambuf_type* obuf ) β€” creates an instance of std::basic_syncbuf with the emit-on-sync policy set to false, the wrapped streambuffer set to obuf, and using a as the allocator for temporary storage. Wait, bestie β€” this one delegates to the next constructor with Allocator(), so it's giving "I'm a shortcut, not a whole new vibe" ✨
  3. basic_syncbuf( streambuf_type* obuf, const Allocator& a ) β€” creates an instance of std::basic_syncbuf with the emit-on-sync policy set to false, the wrapped streambuffer set to obuf, and using a as the allocator for temporary storage. This is the one that actually takes the allocator and handles business 🫢
  4. basic_syncbuf( basic_syncbuf&& rhs ) β€” the move constructor. It move-constructs a std::basic_syncbuf object by moving all contents from another std::basic_syncbuf object rhs, including the temporary storage, the wrapped stream pointer, policy, and all other state (such as the mutex pointer). After the move, rhs is not associated with a stream, and rhs.get_wrapped() == nullptr. The put area member pointers of the base class std::basic_streambuf of rhs are guaranteed to be null. Destroying a moved-from rhs will not produce any output. So like… rhs is empty and unbothered, and it will not be creating drama on destruction. We love a clean exit πŸ’€βœ¨

πŸ¦‹ Parameters πŸ¦‹

  • obuf β€” pointer to the std::basic_streambuf to wrap. It's the stream being adopted, basically the main character it's syncing with πŸ‘‘
  • a β€” the allocator to use for temporary storage. Temporary storage said "I need a sponsor" and a said "say less" πŸ’Έ
  • rhs β€” another std::basic_syncbuf to move from. We're taking its whole vibe and leaving it with nullptr energy 🌈

πŸ”₯ Exceptions πŸ”₯

  • 2, 3) May throw std::bad_alloc from the constructor of the internal temporary storage, or std::system_error from the mutex construction. So yeah, it can go wrong in two very specific ways β€” not me manifesting std::bad_alloc πŸ˜­πŸ’…

πŸŽ€ Notes πŸŽ€

Typically called by the appropriate constructors of std::basic_osyncstream. So if you're ever like "who even calls these constructors?", it's usually std::basic_osyncstream doing the calling. It's giving "I don't start the constructor, I just trigger it" ⭐


🧚 Example 🧚

This section is incomplete. Reason: no example.

ngl bestie, there's literally no example here. The manpage said "example? never heard of her" πŸ™ˆ. The category also says:

  • Category: * Todo no example β€” so yeah, it's a known todo. No example has been served, and we're just gonna have to deal πŸ“

πŸ’œ See also πŸ’œ

  • sync β€” synchronizes the buffers with the associated character sequence. This is a [virtual] virtual protected member function of std::basic_streambuf<CharT,Traits>. It's the behind-the-scenes fixer, the one that lines everything up so the output stays iconic ✨
  • emit β€” atomically transmits the entire internal buffer to the wrapped streambuf. This is a public member function. It's giving "all at once, no half-sends, no crumbs" πŸ”₯

🌟 Cute sign-off 🌟

This page came from http://cppreference.com, version 2024.06.10, and the whole std::basic_...asic_syncbuf(3) moment is dated 2024.06.10 too. Periodt. Now go wrap a streambuf and slay πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from