Files
cppdraft_translate/cppdraft/spanbuf/general.md
2025-10-25 03:02:53 +03:00

2.8 KiB
Raw Blame History

[spanbuf.general]

31 Input/output library [input.output]

31.9 Span-based streams [span.streams]

31.9.3 Class template basic_spanbuf [spanbuf]

31.9.3.1 General [spanbuf.general]

🔗

namespace std {template<class charT, class traits = char_traits>class basic_spanbuf : public basic_streambuf<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; // [spanbuf.cons], constructors basic_spanbuf() : basic_spanbuf(ios_base::in | ios_base::out) {}explicit basic_spanbuf(ios_base::openmode which): basic_spanbuf(std::span(), which) {}explicit basic_spanbuf(std::span s, ios_base::openmode which = ios_base::in | ios_base::out); basic_spanbuf(const basic_spanbuf&) = delete; basic_spanbuf(basic_spanbuf&& rhs); // [spanbuf.assign], assignment and swap basic_spanbuf& operator=(const basic_spanbuf&) = delete; basic_spanbuf& operator=(basic_spanbuf&& rhs); void swap(basic_spanbuf& rhs); // [spanbuf.members], member functions std::span span() const noexcept; void span(std::span s) noexcept; protected:// [spanbuf.virtuals], overridden virtual functions basic_streambuf<charT, traits>* setbuf(charT*, streamsize) override; pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out) override; pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out) override; private: ios_base::openmode mode; // exposition only std::span buf; // exposition only};}

1

#

The class template basic_spanbuf is derived from basic_streambuf to associate possibly the input sequence and possibly the output sequence with a sequence of arbitrary characters.

The sequence is provided by an object of class span.

2

#

For the sake of exposition, the maintained data is presented here as:

  • (2.1)

    ios_base::openmode mode, hasin set if the input sequence can be read, andout set if the output sequence can be written.

  • (2.2)

    std::span buf is the view to the underlying character sequence.