[stringstream] (original) (raw)

31.8.5.1 General [stringstream.general]

namespace std { template<class charT, class traits = char_traits<charT>,class Allocator = allocator<charT>> class basic_stringstream : public basic_iostream<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;using allocator_type = Allocator; basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} explicit basic_stringstream(ios_base::openmode which);explicit basic_stringstream( const basic_string<charT, traits, Allocator>& s, ios_base::openmode which = ios_base::out | ios_base::in); basic_stringstream(ios_base::openmode which, const Allocator& a);explicit basic_stringstream( basic_string<charT, traits, Allocator>&& s, ios_base::openmode which = ios_base::out | ios_base::in);template<class SAlloc> basic_stringstream( const basic_string<charT, traits, SAlloc>& s, const Allocator& a) : basic_stringstream(s, ios_base::out | ios_base::in, a) {} template<class SAlloc> basic_stringstream( const basic_string<charT, traits, SAlloc>& s, ios_base::openmode which, const Allocator& a);template<class SAlloc> explicit basic_stringstream( const basic_string<charT, traits, SAlloc>& s, ios_base::openmode which = ios_base::out | ios_base::in);template<class T> explicit basic_stringstream(const T& t, ios_base::openmode which = ios_base::out | ios_base::in);template<class T> basic_stringstream(const T& t, const Allocator& a);template<class T> basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); basic_stringstream(const basic_stringstream&) = delete; basic_stringstream(basic_stringstream&& rhs); basic_stringstream& operator=(const basic_stringstream&) = delete; basic_stringstream& operator=(basic_stringstream&& rhs);void swap(basic_stringstream& rhs); basic_stringbuf<charT, traits, Allocator>* rdbuf() const; basic_string<charT, traits, Allocator> str() const &;template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const; basic_string<charT, traits, Allocator> str() &&; basic_string_view<charT, traits> view() const noexcept;void str(const basic_string<charT, traits, Allocator>& s);template<class SAlloc> void str(const basic_string<charT, traits, SAlloc>& s);void str(basic_string<charT, traits, Allocator>&& s);template<class T> void str(const T& t);private: basic_stringbuf<charT, traits, Allocator> sb; };}

The class templatebasic_stringstream<charT, traits>supports reading and writing from objects of classbasic_string<charT, traits, Allocator>.

It uses abasic_stringbuf<charT, traits, Allocator>object to control the associated sequence.

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

31.8.5.2 Constructors [stringstream.cons]

explicit basic_stringstream(ios_base::openmode which);

Effects: Initializes the base class withbasic_iostream<charT, traits>(addressof(sb)) ([iostream.cons]) and_sb_withbasic_stringbuf<charT, traits, Allocator>(which).

explicit basic_stringstream( const basic_string<charT, traits, Allocator>& s, ios_base::openmode which = ios_base::out | ios_base::in);

Effects: Initializes the base class withbasic_iostream<charT, traits>(addressof(sb)) ([iostream.cons]) and_sb_withbasic_stringbuf<charT, traits, Allocator>(s, which).

basic_stringstream(ios_base::openmode which, const Allocator& a);

Effects: Initializes the base class withbasic_iostream<charT, traits>(addressof(sb)) ([iostream.cons]) and sb withbasic_stringbuf<charT, traits, Allocator>(which, a) ([stringbuf.cons]).

explicit basic_stringstream( basic_string<charT, traits, Allocator>&& s, ios_base::openmode which = ios_base::out | ios_base::in);

Effects: Initializes the base class withbasic_iostream<charT, traits>(addressof(sb)) ([iostream.cons]) and sb withbasic_stringbuf<charT, traits, Allocator>(std​::​move(s), which) ([stringbuf.cons]).

template<class SAlloc> basic_stringstream( const basic_string<charT, traits, SAlloc>& s, ios_base::openmode which, const Allocator& a);

Effects: Initializes the base class withbasic_iostream<charT, traits>(addressof(sb)) ([iostream.cons]) and sb withbasic_stringbuf<charT, traits, Allocator>(s, which, a) ([stringbuf.cons]).

template<class SAlloc> explicit basic_stringstream( const basic_string<charT, traits, SAlloc>& s, ios_base::openmode which = ios_base::out | ios_base::in);

Constraints: is_same_v<SAlloc,Allocator> is false.

Effects: Initializes the base class withbasic_iostream<charT, traits>(addressof(sb)) ([iostream.cons]) and sb withbasic_stringbuf<charT, traits, Allocator>(s, which) ([stringbuf.cons]).

template<class T> explicit basic_stringstream(const T& t, ios_base::openmode which = ios_base::out | ios_base::in);template<class T> basic_stringstream(const T& t, const Allocator& a);template<class T> basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a);

Let which be ios_base​::​out | ios_base​::​infor the overload with no parameter which, anda be Allocator() for the overload with no parameter a.

Constraints: is_convertible_v<const T&, basic_string_view<charT, traits>>is true.

Effects: Initializes the base class with addressof(sb), and direct-non-list-initializes sb with t, which, a.

basic_stringstream(basic_stringstream&& rhs);

Effects: Move constructs from the rvalue rhs.

This is accomplished by move constructing the base class, and the containedbasic_stringbuf.

Then calls basic_istream<charT, traits>​::​set_rdbuf(addressof(sb))to install the contained basic_stringbuf.

31.8.5.3 Swap [stringstream.swap]

void swap(basic_stringstream& rhs);

Effects: Equivalent to:basic_iostream<charT,traits>::swap(rhs);sb.swap(rhs.sb);

template<class charT, class traits, class Allocator> void swap(basic_stringstream<charT, traits, Allocator>& x, basic_stringstream<charT, traits, Allocator>& y);

Effects: Equivalent to x.swap(y).

31.8.5.4 Member functions [stringstream.members]

basic_stringbuf<charT, traits, Allocator>* rdbuf() const;

Returns: const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(sb)).

basic_string<charT, traits, Allocator> str() const &;

Effects: Equivalent to: return rdbuf()->str();

template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;

Effects: Equivalent to: return rdbuf()->str(sa);

basic_string<charT,traits,Allocator> str() &&;

Effects: Equivalent to: return std​::​move(*rdbuf()).str();

basic_string_view<charT, traits> view() const noexcept;

Effects: Equivalent to: return rdbuf()->view();

void str(const basic_string<charT, traits, Allocator>& s);

Effects: Equivalent to: rdbuf()->str(s);

template<class SAlloc> void str(const basic_string<charT, traits, SAlloc>& s);

Effects: Equivalent to: rdbuf()->str(s);

void str(basic_string<charT, traits, Allocator>&& s);

Effects: Equivalent to: rdbuf()->str(std​::​move(s));

template<class T> void str(const T&);

Constraints: is_convertible_v<const T&, basic_string_view<charT, traits>>is true.

Effects: Equivalent to: rdbuf()->str(t);