31 Input/output library [input.output]

31.8 String-based streams [string.streams]

31.8.2 Class template basic_stringbuf [stringbuf]

31.8.2.2 Constructors [stringbuf.cons]

explicit basic_stringbuf(ios_base::openmode which);
Effects: Initializes the base class with basic_streambuf() ([streambuf.cons]), and mode with which.
It is implementation-defined whether the sequence pointers (eback(), gptr(), egptr(), pbase(), pptr(), epptr()) are initialized to null pointers.
Postconditions: str().empty() is true.
explicit basic_stringbuf( const basic_string<charT, traits, Allocator>& s, ios_base::openmode which = ios_base::in | ios_base::out);
Effects: Initializes the base class with basic_streambuf() ([streambuf.cons]), mode with which, and buf with s, then calls init_buf_ptrs().
basic_stringbuf(ios_base::openmode which, const Allocator& a);
Effects: Initializes the base class with basic_streambuf() ([streambuf.cons]), mode with which, and buf with a, then calls init_buf_ptrs().
Postconditions: str().empty() is true.
explicit basic_stringbuf( basic_string<charT, traits, Allocator>&& s, ios_base::openmode which = ios_base::in | ios_base::out);
Effects: Initializes the base class with basic_streambuf() ([streambuf.cons]), mode with which, and buf with std​::​move(s), then calls init_buf_ptrs().
template<class SAlloc> basic_stringbuf( const basic_string<charT, traits, SAlloc>& s, ios_base::openmode which, const Allocator& a);
Effects: Initializes the base class with basic_streambuf() ([streambuf.cons]), mode with which, and buf with {s,a}, then calls init_buf_ptrs().
template<class SAlloc> explicit basic_stringbuf( const basic_string<charT, traits, SAlloc>& s, ios_base::openmode which = ios_base::in | ios_base::out);
Constraints: is_same_v<SAlloc, Allocator> is false.
Effects: Initializes the base class with basic_streambuf() ([streambuf.cons]), mode with which, and buf with s, then calls init_buf_ptrs().
template<class T> explicit basic_stringbuf(const T& t, ios_base::openmode which = ios_base::in | ios_base::out); template<class T> basic_stringbuf(const T& t, const Allocator& a); template<class T> basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a);
Let which be ios_base​::​in | ios_base​::​out for the overload with no parameter which, and a be Allocator() for the overload with no parameter a.
Constraints: is_convertible_v<const T&, basic_string_view<charT, traits>> is true.
Effects: Creates a variable sv as if by basic_string_view<charT, traits> sv = t, then value-initializes the base class, initializes mode with which, and direct-non-list-initializes buf with sv, a, then calls init_buf_ptrs().
basic_stringbuf(basic_stringbuf&& rhs); basic_stringbuf(basic_stringbuf&& rhs, const Allocator& a);
Effects: Copy constructs the base class from rhs and initializes mode with rhs.mode.
In the first form buf is initialized from std​::​move(rhs).str().
In the second form buf is initialized from {std​::​move(rhs).str(), a}.
It is implementation-defined whether the sequence pointers in *this (eback(), gptr(), egptr(), pbase(), pptr(), epptr()) obtain the values which rhs had.
Postconditions: Let rhs_p refer to the state of rhs just prior to this construction and let rhs_a refer to the state of rhs just after this construction.
  • str() == rhs_p.str()
  • gptr() - eback() == rhs_p.gptr() - rhs_p.eback()
  • egptr() - eback() == rhs_p.egptr() - rhs_p.eback()
  • pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()
  • epptr() - pbase() == rhs_p.epptr() - rhs_p.pbase()
  • if (eback()) eback() != rhs_a.eback()
  • if (gptr()) gptr() != rhs_a.gptr()
  • if (egptr()) egptr() != rhs_a.egptr()
  • if (pbase()) pbase() != rhs_a.pbase()
  • if (pptr()) pptr() != rhs_a.pptr()
  • if (epptr()) epptr() != rhs_a.epptr()
  • getloc() == rhs_p.getloc()
  • rhs is empty but usable, as if std​::​move(rhs).str() was called.