10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_SSTREAM 110b57cec5SDimitry Andric#define _LIBCPP_SSTREAM 120b57cec5SDimitry Andric 13*5f757f3fSDimitry Andric// clang-format off 14*5f757f3fSDimitry Andric 150b57cec5SDimitry Andric/* 16bdd1243dSDimitry Andric sstream synopsis [sstream.syn] 170b57cec5SDimitry Andric 18bdd1243dSDimitry Andric// Class template basic_stringbuf [stringbuf] 190b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 200b57cec5SDimitry Andricclass basic_stringbuf 210b57cec5SDimitry Andric : public basic_streambuf<charT, traits> 220b57cec5SDimitry Andric{ 230b57cec5SDimitry Andricpublic: 240b57cec5SDimitry Andric typedef charT char_type; 250b57cec5SDimitry Andric typedef traits traits_type; 260b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 270b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 280b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 290b57cec5SDimitry Andric typedef Allocator allocator_type; 300b57cec5SDimitry Andric 31bdd1243dSDimitry Andric // [stringbuf.cons] constructors: 32e8d8bef9SDimitry Andric explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 33e8d8bef9SDimitry Andric basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 34e8d8bef9SDimitry Andric explicit basic_stringbuf(ios_base::openmode which); // C++20 3506c3fb27SDimitry Andric explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& s, 360b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 3706c3fb27SDimitry Andric explicit basic_stringbuf(const allocator_type& a) 3806c3fb27SDimitry Andric : basic_stringbuf(ios_base::in | ios_base::out, a) {} // C++20 3906c3fb27SDimitry Andric basic_stringbuf(ios_base::openmode which, const allocator_type& a); // C++20 4006c3fb27SDimitry Andric explicit basic_stringbuf(basic_string<char_type, traits_type, allocator_type>&& s, 4106c3fb27SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); // C++20 4206c3fb27SDimitry Andric template <class SAlloc> 4306c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 4406c3fb27SDimitry Andric : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} // C++20 4506c3fb27SDimitry Andric template <class SAlloc> 4606c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, 4706c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 4806c3fb27SDimitry Andric template <class SAlloc> 4906c3fb27SDimitry Andric explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, 5006c3fb27SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); // C++20 510b57cec5SDimitry Andric basic_stringbuf(basic_stringbuf&& rhs); 5206c3fb27SDimitry Andric basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20 530b57cec5SDimitry Andric 54bdd1243dSDimitry Andric // [stringbuf.assign] Assign and swap: 550b57cec5SDimitry Andric basic_stringbuf& operator=(basic_stringbuf&& rhs); 5606c3fb27SDimitry Andric void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20 570b57cec5SDimitry Andric 58bdd1243dSDimitry Andric // [stringbuf.members] Member functions: 5906c3fb27SDimitry Andric allocator_type get_allocator() const noexcept; // C++20 6006c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 6106c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 6206c3fb27SDimitry Andric template <class SAlloc> 6306c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 6406c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 6506c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 660b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 6706c3fb27SDimitry Andric template <class SAlloc> 6806c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 6906c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 700b57cec5SDimitry Andric 710b57cec5SDimitry Andricprotected: 72bdd1243dSDimitry Andric // [stringbuf.virtuals] Overridden virtual functions: 730b57cec5SDimitry Andric virtual int_type underflow(); 740b57cec5SDimitry Andric virtual int_type pbackfail(int_type c = traits_type::eof()); 750b57cec5SDimitry Andric virtual int_type overflow (int_type c = traits_type::eof()); 760b57cec5SDimitry Andric virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); 770b57cec5SDimitry Andric virtual pos_type seekoff(off_type off, ios_base::seekdir way, 780b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 790b57cec5SDimitry Andric virtual pos_type seekpos(pos_type sp, 800b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 810b57cec5SDimitry Andric}; 820b57cec5SDimitry Andric 83bdd1243dSDimitry Andric// [stringbuf.assign] non member swap 840b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 850b57cec5SDimitry Andricvoid swap(basic_stringbuf<charT, traits, Allocator>& x, 8606c3fb27SDimitry Andric basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20 870b57cec5SDimitry Andric 880b57cec5SDimitry Andrictypedef basic_stringbuf<char> stringbuf; 890b57cec5SDimitry Andrictypedef basic_stringbuf<wchar_t> wstringbuf; 900b57cec5SDimitry Andric 91bdd1243dSDimitry Andric// Class template basic_istringstream [istringstream] 920b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 930b57cec5SDimitry Andricclass basic_istringstream 940b57cec5SDimitry Andric : public basic_istream<charT, traits> 950b57cec5SDimitry Andric{ 960b57cec5SDimitry Andricpublic: 970b57cec5SDimitry Andric typedef charT char_type; 980b57cec5SDimitry Andric typedef traits traits_type; 990b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 1000b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 1010b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1020b57cec5SDimitry Andric typedef Allocator allocator_type; 1030b57cec5SDimitry Andric 104bdd1243dSDimitry Andric // [istringstream.cons] Constructors: 105e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 106e8d8bef9SDimitry Andric basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 107e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode which); // C++20 10806c3fb27SDimitry Andric explicit basic_istringstream(const basic_string<char_type, traits_type, allocator_type>& s, 1090b57cec5SDimitry Andric ios_base::openmode which = ios_base::in); 11006c3fb27SDimitry Andric basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20 11106c3fb27SDimitry Andric explicit basic_istringstream(basic_string<char_type, traits_type, allocator_type>&& s, 11206c3fb27SDimitry Andric ios_base::openmode which = ios_base::in); // C++20 11306c3fb27SDimitry Andric template <class SAlloc> 11406c3fb27SDimitry Andric basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 11506c3fb27SDimitry Andric : basic_istringstream(s, ios_base::in, a) {} // C++20 11606c3fb27SDimitry Andric template <class SAlloc> 11706c3fb27SDimitry Andric basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, 11806c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 11906c3fb27SDimitry Andric template <class SAlloc> 12006c3fb27SDimitry Andric explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, 12106c3fb27SDimitry Andric ios_base::openmode which = ios_base::in); // C++20 1220b57cec5SDimitry Andric basic_istringstream(basic_istringstream&& rhs); 1230b57cec5SDimitry Andric 124bdd1243dSDimitry Andric // [istringstream.assign] Assign and swap: 1250b57cec5SDimitry Andric basic_istringstream& operator=(basic_istringstream&& rhs); 1260b57cec5SDimitry Andric void swap(basic_istringstream& rhs); 1270b57cec5SDimitry Andric 128bdd1243dSDimitry Andric // [istringstream.members] Member functions: 1290b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 13006c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 13106c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 13206c3fb27SDimitry Andric template <class SAlloc> 13306c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 13406c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 13506c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 1360b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 13706c3fb27SDimitry Andric template <class SAlloc> 13806c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 13906c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 1400b57cec5SDimitry Andric}; 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 1430b57cec5SDimitry Andricvoid swap(basic_istringstream<charT, traits, Allocator>& x, 1440b57cec5SDimitry Andric basic_istringstream<charT, traits, Allocator>& y); 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andrictypedef basic_istringstream<char> istringstream; 1470b57cec5SDimitry Andrictypedef basic_istringstream<wchar_t> wistringstream; 1480b57cec5SDimitry Andric 149bdd1243dSDimitry Andric// Class template basic_ostringstream [ostringstream] 1500b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 1510b57cec5SDimitry Andricclass basic_ostringstream 1520b57cec5SDimitry Andric : public basic_ostream<charT, traits> 1530b57cec5SDimitry Andric{ 1540b57cec5SDimitry Andricpublic: 1550b57cec5SDimitry Andric // types: 1560b57cec5SDimitry Andric typedef charT char_type; 1570b57cec5SDimitry Andric typedef traits traits_type; 1580b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 1590b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 1600b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1610b57cec5SDimitry Andric typedef Allocator allocator_type; 1620b57cec5SDimitry Andric 163bdd1243dSDimitry Andric // [ostringstream.cons] Constructors: 164e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 165e8d8bef9SDimitry Andric basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 166e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode which); // C++20 16706c3fb27SDimitry Andric explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& s, 1680b57cec5SDimitry Andric ios_base::openmode which = ios_base::out); 16906c3fb27SDimitry Andric basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20 17006c3fb27SDimitry Andric explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s, 17106c3fb27SDimitry Andric ios_base::openmode which = ios_base::out); // C++20 17206c3fb27SDimitry Andric template <class SAlloc> 17306c3fb27SDimitry Andric basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 17406c3fb27SDimitry Andric : basic_ostringstream(s, ios_base::out, a) {} // C++20 17506c3fb27SDimitry Andric template <class SAlloc> 17606c3fb27SDimitry Andric basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, 17706c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 17806c3fb27SDimitry Andric template <class SAlloc> 17906c3fb27SDimitry Andric explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, 18006c3fb27SDimitry Andric ios_base::openmode which = ios_base::out); // C++20 1810b57cec5SDimitry Andric basic_ostringstream(basic_ostringstream&& rhs); 1820b57cec5SDimitry Andric 183bdd1243dSDimitry Andric // [ostringstream.assign] Assign and swap: 1840b57cec5SDimitry Andric basic_ostringstream& operator=(basic_ostringstream&& rhs); 1850b57cec5SDimitry Andric void swap(basic_ostringstream& rhs); 1860b57cec5SDimitry Andric 187bdd1243dSDimitry Andric // [ostringstream.members] Member functions: 1880b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 18906c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 19006c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 19106c3fb27SDimitry Andric template <class SAlloc> 19206c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 19306c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 19406c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 1950b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 19606c3fb27SDimitry Andric template <class SAlloc> 19706c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 19806c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 1990b57cec5SDimitry Andric}; 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 2020b57cec5SDimitry Andricvoid swap(basic_ostringstream<charT, traits, Allocator>& x, 2030b57cec5SDimitry Andric basic_ostringstream<charT, traits, Allocator>& y); 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andrictypedef basic_ostringstream<char> ostringstream; 2060b57cec5SDimitry Andrictypedef basic_ostringstream<wchar_t> wostringstream; 2070b57cec5SDimitry Andric 208bdd1243dSDimitry Andric// Class template basic_stringstream [stringstream] 2090b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 2100b57cec5SDimitry Andricclass basic_stringstream 2110b57cec5SDimitry Andric : public basic_iostream<charT, traits> 2120b57cec5SDimitry Andric{ 2130b57cec5SDimitry Andricpublic: 2140b57cec5SDimitry Andric // types: 2150b57cec5SDimitry Andric typedef charT char_type; 2160b57cec5SDimitry Andric typedef traits traits_type; 2170b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 2180b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 2190b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 2200b57cec5SDimitry Andric typedef Allocator allocator_type; 2210b57cec5SDimitry Andric 222bdd1243dSDimitry Andric // [stringstream.cons] constructors 223e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 224e8d8bef9SDimitry Andric basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 225e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode which); // C++20 22606c3fb27SDimitry Andric explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s, 2270b57cec5SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); 22806c3fb27SDimitry Andric basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20 22906c3fb27SDimitry Andric explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s, 23006c3fb27SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // C++20 23106c3fb27SDimitry Andric template <class SAlloc> 23206c3fb27SDimitry Andric basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 23306c3fb27SDimitry Andric : basic_stringstream(s, ios_base::out | ios_base::in, a) {} // C++20 23406c3fb27SDimitry Andric template <class SAlloc> 23506c3fb27SDimitry Andric basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, 23606c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 23706c3fb27SDimitry Andric template <class SAlloc> 23806c3fb27SDimitry Andric explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, 23906c3fb27SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // C++20 2400b57cec5SDimitry Andric basic_stringstream(basic_stringstream&& rhs); 2410b57cec5SDimitry Andric 242bdd1243dSDimitry Andric // [stringstream.assign] Assign and swap: 2430b57cec5SDimitry Andric basic_stringstream& operator=(basic_stringstream&& rhs); 2440b57cec5SDimitry Andric void swap(basic_stringstream& rhs); 2450b57cec5SDimitry Andric 246bdd1243dSDimitry Andric // [stringstream.members] Member functions: 2470b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 24806c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 24906c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 25006c3fb27SDimitry Andric template <class SAlloc> 25106c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 25206c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 25306c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 25406c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 25506c3fb27SDimitry Andric template <class SAlloc> 25606c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 25706c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 2580b57cec5SDimitry Andric}; 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 2610b57cec5SDimitry Andricvoid swap(basic_stringstream<charT, traits, Allocator>& x, 2620b57cec5SDimitry Andric basic_stringstream<charT, traits, Allocator>& y); 2630b57cec5SDimitry Andric 2640b57cec5SDimitry Andrictypedef basic_stringstream<char> stringstream; 2650b57cec5SDimitry Andrictypedef basic_stringstream<wchar_t> wstringstream; 2660b57cec5SDimitry Andric 2670b57cec5SDimitry Andric} // std 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andric*/ 2700b57cec5SDimitry Andric 271*5f757f3fSDimitry Andric// clang-format on 272*5f757f3fSDimitry Andric 27381ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 274*5f757f3fSDimitry Andric#include <__availability> 2750b57cec5SDimitry Andric#include <__config> 27606c3fb27SDimitry Andric#include <__fwd/sstream.h> 27781ad6265SDimitry Andric#include <__utility/swap.h> 2780b57cec5SDimitry Andric#include <istream> 279fe6060f1SDimitry Andric#include <ostream> 2800b57cec5SDimitry Andric#include <string> 28104eeddc0SDimitry Andric#include <version> 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2840b57cec5SDimitry Andric# pragma GCC system_header 2850b57cec5SDimitry Andric#endif 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 2880b57cec5SDimitry Andric#include <__undef_macros> 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric 29106c3fb27SDimitry Andric// TODO(LLVM-19): Remove this once we drop support for Clang 16, 29206c3fb27SDimitry Andric// which had this bug: https://github.com/llvm/llvm-project/issues/40363 29306c3fb27SDimitry Andric#ifdef _WIN32 29406c3fb27SDimitry Andric#define _LIBCPP_HIDE_FROM_ABI_SSTREAM _LIBCPP_ALWAYS_INLINE 29506c3fb27SDimitry Andric#else 29606c3fb27SDimitry Andric#define _LIBCPP_HIDE_FROM_ABI_SSTREAM _LIBCPP_HIDE_FROM_ABI 29706c3fb27SDimitry Andric#endif 29806c3fb27SDimitry Andric 2990b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3000b57cec5SDimitry Andric 301bdd1243dSDimitry Andric// Class template basic_stringbuf [stringbuf] 3020b57cec5SDimitry Andric 3030b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3040b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_stringbuf 3050b57cec5SDimitry Andric : public basic_streambuf<_CharT, _Traits> 3060b57cec5SDimitry Andric{ 3070b57cec5SDimitry Andricpublic: 3080b57cec5SDimitry Andric typedef _CharT char_type; 3090b57cec5SDimitry Andric typedef _Traits traits_type; 3100b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 3110b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 3120b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 3130b57cec5SDimitry Andric typedef _Allocator allocator_type; 3140b57cec5SDimitry Andric 3150b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andricprivate: 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric string_type __str_; 3200b57cec5SDimitry Andric mutable char_type* __hm_; 3210b57cec5SDimitry Andric ios_base::openmode __mode_; 32206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); 32306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andricpublic: 326bdd1243dSDimitry Andric // [stringbuf.cons] constructors: 327*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 328fe6060f1SDimitry Andric basic_stringbuf() 329fe6060f1SDimitry Andric : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {} 330e8d8bef9SDimitry Andric 331*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 332e8d8bef9SDimitry Andric explicit basic_stringbuf(ios_base::openmode __wch) 333e8d8bef9SDimitry Andric : __hm_(nullptr), __mode_(__wch) {} 334e8d8bef9SDimitry Andric 335*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 336e8d8bef9SDimitry Andric explicit basic_stringbuf(const string_type& __s, 337e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 338e8d8bef9SDimitry Andric : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) 339e8d8bef9SDimitry Andric { 340e8d8bef9SDimitry Andric str(__s); 341e8d8bef9SDimitry Andric } 342e8d8bef9SDimitry Andric 34306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 34406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) 34506c3fb27SDimitry Andric : basic_stringbuf(ios_base::in | ios_base::out, __a) {} 34606c3fb27SDimitry Andric 34706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) 34806c3fb27SDimitry Andric : __str_(__a), __hm_(nullptr), __mode_(__wch) {} 34906c3fb27SDimitry Andric 35006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, 35106c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 35206c3fb27SDimitry Andric : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { 35306c3fb27SDimitry Andric __init_buf_ptrs(); 35406c3fb27SDimitry Andric } 35506c3fb27SDimitry Andric 35606c3fb27SDimitry Andric template <class _SAlloc> 35706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 35806c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a) 35906c3fb27SDimitry Andric : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} 36006c3fb27SDimitry Andric 36106c3fb27SDimitry Andric template <class _SAlloc> 36206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf( 36306c3fb27SDimitry Andric const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a) 36406c3fb27SDimitry Andric : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { 36506c3fb27SDimitry Andric __init_buf_ptrs(); 36606c3fb27SDimitry Andric } 36706c3fb27SDimitry Andric 36806c3fb27SDimitry Andric template <class _SAlloc> 36906c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 37006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, 37106c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 37206c3fb27SDimitry Andric : __str_(__s), __hm_(nullptr), __mode_(__wch) { 37306c3fb27SDimitry Andric __init_buf_ptrs(); 37406c3fb27SDimitry Andric } 37506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 37606c3fb27SDimitry Andric 37706c3fb27SDimitry Andric basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); } 37806c3fb27SDimitry Andric 37906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 38006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) 38106c3fb27SDimitry Andric : basic_stringbuf(__rhs.__mode_, __a) { 38206c3fb27SDimitry Andric __move_init(std::move(__rhs)); 38306c3fb27SDimitry Andric } 38406c3fb27SDimitry Andric#endif 3850b57cec5SDimitry Andric 386bdd1243dSDimitry Andric // [stringbuf.assign] Assign and swap: 3870b57cec5SDimitry Andric basic_stringbuf& operator=(basic_stringbuf&& __rhs); 38806c3fb27SDimitry Andric void swap(basic_stringbuf& __rhs) 38906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 39006c3fb27SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 39106c3fb27SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value) 39206c3fb27SDimitry Andric#endif 39306c3fb27SDimitry Andric ; 3940b57cec5SDimitry Andric 395bdd1243dSDimitry Andric // [stringbuf.members] Member functions: 39606c3fb27SDimitry Andric 39706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 39806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } 39906c3fb27SDimitry Andric#endif 40006c3fb27SDimitry Andric 40106c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 4020b57cec5SDimitry Andric string_type str() const; 40306c3fb27SDimitry Andric#else 40406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return str(__str_.get_allocator()); } 40506c3fb27SDimitry Andric 40606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { 40706c3fb27SDimitry Andric const basic_string_view<_CharT, _Traits> __view = view(); 408*5f757f3fSDimitry Andric typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data(); 409*5f757f3fSDimitry Andric // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator()); 410*5f757f3fSDimitry Andric // But we need something that works in C++20 also. 411*5f757f3fSDimitry Andric string_type __result(__str_.get_allocator()); 412*5f757f3fSDimitry Andric __result.__move_assign(std::move(__str_), __pos, __view.size()); 41306c3fb27SDimitry Andric __str_.clear(); 41406c3fb27SDimitry Andric __init_buf_ptrs(); 41506c3fb27SDimitry Andric return __result; 41606c3fb27SDimitry Andric } 41706c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 41806c3fb27SDimitry Andric 41906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 42006c3fb27SDimitry Andric template <class _SAlloc> 42106c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 42206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 42306c3fb27SDimitry Andric return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); 42406c3fb27SDimitry Andric } 42506c3fb27SDimitry Andric 42606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept; 4278a4dda33SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 42806c3fb27SDimitry Andric 42906c3fb27SDimitry Andric void str(const string_type& __s) { 43006c3fb27SDimitry Andric __str_ = __s; 43106c3fb27SDimitry Andric __init_buf_ptrs(); 43206c3fb27SDimitry Andric } 43306c3fb27SDimitry Andric 43406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 43506c3fb27SDimitry Andric template <class _SAlloc> 43606c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 43706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 43806c3fb27SDimitry Andric __str_ = __s; 43906c3fb27SDimitry Andric __init_buf_ptrs(); 44006c3fb27SDimitry Andric } 44106c3fb27SDimitry Andric 44206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { 44306c3fb27SDimitry Andric __str_ = std::move(__s); 44406c3fb27SDimitry Andric __init_buf_ptrs(); 44506c3fb27SDimitry Andric } 44606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andricprotected: 449bdd1243dSDimitry Andric // [stringbuf.virtuals] Overridden virtual functions: 450bdd1243dSDimitry Andric int_type underflow() override; 451bdd1243dSDimitry Andric int_type pbackfail(int_type __c = traits_type::eof()) override; 452bdd1243dSDimitry Andric int_type overflow (int_type __c = traits_type::eof()) override; 453bdd1243dSDimitry Andric pos_type seekoff(off_type __off, ios_base::seekdir __way, 454bdd1243dSDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) override; 455bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI_VIRTUAL 456bdd1243dSDimitry Andric pos_type seekpos(pos_type __sp, 457bdd1243dSDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) override { 458e8d8bef9SDimitry Andric return seekoff(__sp, ios_base::beg, __wch); 459e8d8bef9SDimitry Andric } 4600b57cec5SDimitry Andric}; 4610b57cec5SDimitry Andric 4620b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 46306c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { 4640b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 4650b57cec5SDimitry Andric ptrdiff_t __binp = -1; 4660b57cec5SDimitry Andric ptrdiff_t __ninp = -1; 4670b57cec5SDimitry Andric ptrdiff_t __einp = -1; 4680b57cec5SDimitry Andric if (__rhs.eback() != nullptr) 4690b57cec5SDimitry Andric { 4700b57cec5SDimitry Andric __binp = __rhs.eback() - __p; 4710b57cec5SDimitry Andric __ninp = __rhs.gptr() - __p; 4720b57cec5SDimitry Andric __einp = __rhs.egptr() - __p; 4730b57cec5SDimitry Andric } 4740b57cec5SDimitry Andric ptrdiff_t __bout = -1; 4750b57cec5SDimitry Andric ptrdiff_t __nout = -1; 4760b57cec5SDimitry Andric ptrdiff_t __eout = -1; 4770b57cec5SDimitry Andric if (__rhs.pbase() != nullptr) 4780b57cec5SDimitry Andric { 4790b57cec5SDimitry Andric __bout = __rhs.pbase() - __p; 4800b57cec5SDimitry Andric __nout = __rhs.pptr() - __p; 4810b57cec5SDimitry Andric __eout = __rhs.epptr() - __p; 4820b57cec5SDimitry Andric } 4830b57cec5SDimitry Andric ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 484*5f757f3fSDimitry Andric __str_ = std::move(__rhs.__str_); 4850b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 4860b57cec5SDimitry Andric if (__binp != -1) 4870b57cec5SDimitry Andric this->setg(__p + __binp, __p + __ninp, __p + __einp); 4880b57cec5SDimitry Andric if (__bout != -1) 4890b57cec5SDimitry Andric { 4900b57cec5SDimitry Andric this->setp(__p + __bout, __p + __eout); 4910b57cec5SDimitry Andric this->__pbump(__nout); 4920b57cec5SDimitry Andric } 4930b57cec5SDimitry Andric __hm_ = __hm == -1 ? nullptr : __p + __hm; 4940b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 4950b57cec5SDimitry Andric __rhs.setg(__p, __p, __p); 4960b57cec5SDimitry Andric __rhs.setp(__p, __p); 4970b57cec5SDimitry Andric __rhs.__hm_ = __p; 4980b57cec5SDimitry Andric this->pubimbue(__rhs.getloc()); 4990b57cec5SDimitry Andric} 5000b57cec5SDimitry Andric 5010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 5020b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>& 5030b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) 5040b57cec5SDimitry Andric{ 5050b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 5060b57cec5SDimitry Andric ptrdiff_t __binp = -1; 5070b57cec5SDimitry Andric ptrdiff_t __ninp = -1; 5080b57cec5SDimitry Andric ptrdiff_t __einp = -1; 5090b57cec5SDimitry Andric if (__rhs.eback() != nullptr) 5100b57cec5SDimitry Andric { 5110b57cec5SDimitry Andric __binp = __rhs.eback() - __p; 5120b57cec5SDimitry Andric __ninp = __rhs.gptr() - __p; 5130b57cec5SDimitry Andric __einp = __rhs.egptr() - __p; 5140b57cec5SDimitry Andric } 5150b57cec5SDimitry Andric ptrdiff_t __bout = -1; 5160b57cec5SDimitry Andric ptrdiff_t __nout = -1; 5170b57cec5SDimitry Andric ptrdiff_t __eout = -1; 5180b57cec5SDimitry Andric if (__rhs.pbase() != nullptr) 5190b57cec5SDimitry Andric { 5200b57cec5SDimitry Andric __bout = __rhs.pbase() - __p; 5210b57cec5SDimitry Andric __nout = __rhs.pptr() - __p; 5220b57cec5SDimitry Andric __eout = __rhs.epptr() - __p; 5230b57cec5SDimitry Andric } 5240b57cec5SDimitry Andric ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 525*5f757f3fSDimitry Andric __str_ = std::move(__rhs.__str_); 5260b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5270b57cec5SDimitry Andric if (__binp != -1) 5280b57cec5SDimitry Andric this->setg(__p + __binp, __p + __ninp, __p + __einp); 5290b57cec5SDimitry Andric else 5300b57cec5SDimitry Andric this->setg(nullptr, nullptr, nullptr); 5310b57cec5SDimitry Andric if (__bout != -1) 5320b57cec5SDimitry Andric { 5330b57cec5SDimitry Andric this->setp(__p + __bout, __p + __eout); 5340b57cec5SDimitry Andric this->__pbump(__nout); 5350b57cec5SDimitry Andric } 5360b57cec5SDimitry Andric else 5370b57cec5SDimitry Andric this->setp(nullptr, nullptr); 5380b57cec5SDimitry Andric 5390b57cec5SDimitry Andric __hm_ = __hm == -1 ? nullptr : __p + __hm; 5400b57cec5SDimitry Andric __mode_ = __rhs.__mode_; 5410b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 5420b57cec5SDimitry Andric __rhs.setg(__p, __p, __p); 5430b57cec5SDimitry Andric __rhs.setp(__p, __p); 5440b57cec5SDimitry Andric __rhs.__hm_ = __p; 5450b57cec5SDimitry Andric this->pubimbue(__rhs.getloc()); 5460b57cec5SDimitry Andric return *this; 5470b57cec5SDimitry Andric} 5480b57cec5SDimitry Andric 5490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 5500b57cec5SDimitry Andricvoid 5510b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) 55206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 55306c3fb27SDimitry Andric noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value || 55406c3fb27SDimitry Andric allocator_traits<_Allocator>::is_always_equal::value) 55506c3fb27SDimitry Andric#endif 5560b57cec5SDimitry Andric{ 5570b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 5580b57cec5SDimitry Andric ptrdiff_t __rbinp = -1; 5590b57cec5SDimitry Andric ptrdiff_t __rninp = -1; 5600b57cec5SDimitry Andric ptrdiff_t __reinp = -1; 5610b57cec5SDimitry Andric if (__rhs.eback() != nullptr) 5620b57cec5SDimitry Andric { 5630b57cec5SDimitry Andric __rbinp = __rhs.eback() - __p; 5640b57cec5SDimitry Andric __rninp = __rhs.gptr() - __p; 5650b57cec5SDimitry Andric __reinp = __rhs.egptr() - __p; 5660b57cec5SDimitry Andric } 5670b57cec5SDimitry Andric ptrdiff_t __rbout = -1; 5680b57cec5SDimitry Andric ptrdiff_t __rnout = -1; 5690b57cec5SDimitry Andric ptrdiff_t __reout = -1; 5700b57cec5SDimitry Andric if (__rhs.pbase() != nullptr) 5710b57cec5SDimitry Andric { 5720b57cec5SDimitry Andric __rbout = __rhs.pbase() - __p; 5730b57cec5SDimitry Andric __rnout = __rhs.pptr() - __p; 5740b57cec5SDimitry Andric __reout = __rhs.epptr() - __p; 5750b57cec5SDimitry Andric } 5760b57cec5SDimitry Andric ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 5770b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5780b57cec5SDimitry Andric ptrdiff_t __lbinp = -1; 5790b57cec5SDimitry Andric ptrdiff_t __lninp = -1; 5800b57cec5SDimitry Andric ptrdiff_t __leinp = -1; 5810b57cec5SDimitry Andric if (this->eback() != nullptr) 5820b57cec5SDimitry Andric { 5830b57cec5SDimitry Andric __lbinp = this->eback() - __p; 5840b57cec5SDimitry Andric __lninp = this->gptr() - __p; 5850b57cec5SDimitry Andric __leinp = this->egptr() - __p; 5860b57cec5SDimitry Andric } 5870b57cec5SDimitry Andric ptrdiff_t __lbout = -1; 5880b57cec5SDimitry Andric ptrdiff_t __lnout = -1; 5890b57cec5SDimitry Andric ptrdiff_t __leout = -1; 5900b57cec5SDimitry Andric if (this->pbase() != nullptr) 5910b57cec5SDimitry Andric { 5920b57cec5SDimitry Andric __lbout = this->pbase() - __p; 5930b57cec5SDimitry Andric __lnout = this->pptr() - __p; 5940b57cec5SDimitry Andric __leout = this->epptr() - __p; 5950b57cec5SDimitry Andric } 5960b57cec5SDimitry Andric ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; 597*5f757f3fSDimitry Andric std::swap(__mode_, __rhs.__mode_); 5980b57cec5SDimitry Andric __str_.swap(__rhs.__str_); 5990b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 6000b57cec5SDimitry Andric if (__rbinp != -1) 6010b57cec5SDimitry Andric this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); 6020b57cec5SDimitry Andric else 6030b57cec5SDimitry Andric this->setg(nullptr, nullptr, nullptr); 6040b57cec5SDimitry Andric if (__rbout != -1) 6050b57cec5SDimitry Andric { 6060b57cec5SDimitry Andric this->setp(__p + __rbout, __p + __reout); 6070b57cec5SDimitry Andric this->__pbump(__rnout); 6080b57cec5SDimitry Andric } 6090b57cec5SDimitry Andric else 6100b57cec5SDimitry Andric this->setp(nullptr, nullptr); 6110b57cec5SDimitry Andric __hm_ = __rhm == -1 ? nullptr : __p + __rhm; 6120b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 6130b57cec5SDimitry Andric if (__lbinp != -1) 6140b57cec5SDimitry Andric __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); 6150b57cec5SDimitry Andric else 6160b57cec5SDimitry Andric __rhs.setg(nullptr, nullptr, nullptr); 6170b57cec5SDimitry Andric if (__lbout != -1) 6180b57cec5SDimitry Andric { 6190b57cec5SDimitry Andric __rhs.setp(__p + __lbout, __p + __leout); 6200b57cec5SDimitry Andric __rhs.__pbump(__lnout); 6210b57cec5SDimitry Andric } 6220b57cec5SDimitry Andric else 6230b57cec5SDimitry Andric __rhs.setp(nullptr, nullptr); 6240b57cec5SDimitry Andric __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; 6250b57cec5SDimitry Andric locale __tl = __rhs.getloc(); 6260b57cec5SDimitry Andric __rhs.pubimbue(this->getloc()); 6270b57cec5SDimitry Andric this->pubimbue(__tl); 6280b57cec5SDimitry Andric} 6290b57cec5SDimitry Andric 6300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 631*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 6320b57cec5SDimitry Andricvoid 6330b57cec5SDimitry Andricswap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, 6340b57cec5SDimitry Andric basic_stringbuf<_CharT, _Traits, _Allocator>& __y) 63506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 63606c3fb27SDimitry Andric noexcept(noexcept(__x.swap(__y))) 63706c3fb27SDimitry Andric#endif 6380b57cec5SDimitry Andric{ 6390b57cec5SDimitry Andric __x.swap(__y); 6400b57cec5SDimitry Andric} 6410b57cec5SDimitry Andric 64206c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 6430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 6440b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 64506c3fb27SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::str() const { 64606c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 6470b57cec5SDimitry Andric if (__hm_ < this->pptr()) 6480b57cec5SDimitry Andric __hm_ = this->pptr(); 6490b57cec5SDimitry Andric return string_type(this->pbase(), __hm_, __str_.get_allocator()); 65006c3fb27SDimitry Andric } else if (__mode_ & ios_base::in) 6510b57cec5SDimitry Andric return string_type(this->eback(), this->egptr(), __str_.get_allocator()); 6520b57cec5SDimitry Andric return string_type(__str_.get_allocator()); 6530b57cec5SDimitry Andric} 65406c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 6550b57cec5SDimitry Andric 6560b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 65706c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { 658e8d8bef9SDimitry Andric __hm_ = nullptr; 65906c3fb27SDimitry Andric char_type* __data = const_cast<char_type*>(__str_.data()); 6600b57cec5SDimitry Andric typename string_type::size_type __sz = __str_.size(); 66106c3fb27SDimitry Andric if (__mode_ & ios_base::in) { 66206c3fb27SDimitry Andric __hm_ = __data + __sz; 66306c3fb27SDimitry Andric this->setg(__data, __data, __hm_); 66406c3fb27SDimitry Andric } 66506c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 66606c3fb27SDimitry Andric __hm_ = __data + __sz; 6670b57cec5SDimitry Andric __str_.resize(__str_.capacity()); 66806c3fb27SDimitry Andric this->setp(__data, __data + __str_.size()); 66906c3fb27SDimitry Andric if (__mode_ & (ios_base::app | ios_base::ate)) { 67006c3fb27SDimitry Andric while (__sz > INT_MAX) { 6710b57cec5SDimitry Andric this->pbump(INT_MAX); 6720b57cec5SDimitry Andric __sz -= INT_MAX; 6730b57cec5SDimitry Andric } 6740b57cec5SDimitry Andric if (__sz > 0) 6750b57cec5SDimitry Andric this->pbump(__sz); 6760b57cec5SDimitry Andric } 6770b57cec5SDimitry Andric } 6780b57cec5SDimitry Andric} 6790b57cec5SDimitry Andric 68006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 68106c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 68206c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits> 68306c3fb27SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept { 68406c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 68506c3fb27SDimitry Andric if (__hm_ < this->pptr()) 68606c3fb27SDimitry Andric __hm_ = this->pptr(); 68706c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_); 68806c3fb27SDimitry Andric } else if (__mode_ & ios_base::in) 68906c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr()); 69006c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(); 69106c3fb27SDimitry Andric} 69206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 69306c3fb27SDimitry Andric 6940b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 6950b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 6960b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::underflow() 6970b57cec5SDimitry Andric{ 6980b57cec5SDimitry Andric if (__hm_ < this->pptr()) 6990b57cec5SDimitry Andric __hm_ = this->pptr(); 7000b57cec5SDimitry Andric if (__mode_ & ios_base::in) 7010b57cec5SDimitry Andric { 7020b57cec5SDimitry Andric if (this->egptr() < __hm_) 7030b57cec5SDimitry Andric this->setg(this->eback(), this->gptr(), __hm_); 7040b57cec5SDimitry Andric if (this->gptr() < this->egptr()) 7050b57cec5SDimitry Andric return traits_type::to_int_type(*this->gptr()); 7060b57cec5SDimitry Andric } 7070b57cec5SDimitry Andric return traits_type::eof(); 7080b57cec5SDimitry Andric} 7090b57cec5SDimitry Andric 7100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7110b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 7120b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) 7130b57cec5SDimitry Andric{ 7140b57cec5SDimitry Andric if (__hm_ < this->pptr()) 7150b57cec5SDimitry Andric __hm_ = this->pptr(); 7160b57cec5SDimitry Andric if (this->eback() < this->gptr()) 7170b57cec5SDimitry Andric { 7180b57cec5SDimitry Andric if (traits_type::eq_int_type(__c, traits_type::eof())) 7190b57cec5SDimitry Andric { 7200b57cec5SDimitry Andric this->setg(this->eback(), this->gptr()-1, __hm_); 7210b57cec5SDimitry Andric return traits_type::not_eof(__c); 7220b57cec5SDimitry Andric } 7230b57cec5SDimitry Andric if ((__mode_ & ios_base::out) || 7240b57cec5SDimitry Andric traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) 7250b57cec5SDimitry Andric { 7260b57cec5SDimitry Andric this->setg(this->eback(), this->gptr()-1, __hm_); 7270b57cec5SDimitry Andric *this->gptr() = traits_type::to_char_type(__c); 7280b57cec5SDimitry Andric return __c; 7290b57cec5SDimitry Andric } 7300b57cec5SDimitry Andric } 7310b57cec5SDimitry Andric return traits_type::eof(); 7320b57cec5SDimitry Andric} 7330b57cec5SDimitry Andric 7340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7350b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 7360b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) 7370b57cec5SDimitry Andric{ 7380b57cec5SDimitry Andric if (!traits_type::eq_int_type(__c, traits_type::eof())) 7390b57cec5SDimitry Andric { 7400b57cec5SDimitry Andric ptrdiff_t __ninp = this->gptr() - this->eback(); 7410b57cec5SDimitry Andric if (this->pptr() == this->epptr()) 7420b57cec5SDimitry Andric { 7430b57cec5SDimitry Andric if (!(__mode_ & ios_base::out)) 7440b57cec5SDimitry Andric return traits_type::eof(); 74506c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 7460b57cec5SDimitry Andric try 7470b57cec5SDimitry Andric { 74806c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 7490b57cec5SDimitry Andric ptrdiff_t __nout = this->pptr() - this->pbase(); 7500b57cec5SDimitry Andric ptrdiff_t __hm = __hm_ - this->pbase(); 7510b57cec5SDimitry Andric __str_.push_back(char_type()); 7520b57cec5SDimitry Andric __str_.resize(__str_.capacity()); 7530b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__str_.data()); 7540b57cec5SDimitry Andric this->setp(__p, __p + __str_.size()); 7550b57cec5SDimitry Andric this->__pbump(__nout); 7560b57cec5SDimitry Andric __hm_ = this->pbase() + __hm; 75706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 7580b57cec5SDimitry Andric } 7590b57cec5SDimitry Andric catch (...) 7600b57cec5SDimitry Andric { 7610b57cec5SDimitry Andric return traits_type::eof(); 7620b57cec5SDimitry Andric } 76306c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 7640b57cec5SDimitry Andric } 765*5f757f3fSDimitry Andric __hm_ = std::max(this->pptr() + 1, __hm_); 7660b57cec5SDimitry Andric if (__mode_ & ios_base::in) 7670b57cec5SDimitry Andric { 7680b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__str_.data()); 7690b57cec5SDimitry Andric this->setg(__p, __p + __ninp, __hm_); 7700b57cec5SDimitry Andric } 7710b57cec5SDimitry Andric return this->sputc(traits_type::to_char_type(__c)); 7720b57cec5SDimitry Andric } 7730b57cec5SDimitry Andric return traits_type::not_eof(__c); 7740b57cec5SDimitry Andric} 7750b57cec5SDimitry Andric 7760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7770b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type 7780b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, 7790b57cec5SDimitry Andric ios_base::seekdir __way, 7800b57cec5SDimitry Andric ios_base::openmode __wch) 7810b57cec5SDimitry Andric{ 7820b57cec5SDimitry Andric if (__hm_ < this->pptr()) 7830b57cec5SDimitry Andric __hm_ = this->pptr(); 7840b57cec5SDimitry Andric if ((__wch & (ios_base::in | ios_base::out)) == 0) 7850b57cec5SDimitry Andric return pos_type(-1); 7860b57cec5SDimitry Andric if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) 7870b57cec5SDimitry Andric && __way == ios_base::cur) 7880b57cec5SDimitry Andric return pos_type(-1); 7890b57cec5SDimitry Andric const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); 7900b57cec5SDimitry Andric off_type __noff; 7910b57cec5SDimitry Andric switch (__way) 7920b57cec5SDimitry Andric { 7930b57cec5SDimitry Andric case ios_base::beg: 7940b57cec5SDimitry Andric __noff = 0; 7950b57cec5SDimitry Andric break; 7960b57cec5SDimitry Andric case ios_base::cur: 7970b57cec5SDimitry Andric if (__wch & ios_base::in) 7980b57cec5SDimitry Andric __noff = this->gptr() - this->eback(); 7990b57cec5SDimitry Andric else 8000b57cec5SDimitry Andric __noff = this->pptr() - this->pbase(); 8010b57cec5SDimitry Andric break; 8020b57cec5SDimitry Andric case ios_base::end: 8030b57cec5SDimitry Andric __noff = __hm; 8040b57cec5SDimitry Andric break; 8050b57cec5SDimitry Andric default: 8060b57cec5SDimitry Andric return pos_type(-1); 8070b57cec5SDimitry Andric } 8080b57cec5SDimitry Andric __noff += __off; 8090b57cec5SDimitry Andric if (__noff < 0 || __hm < __noff) 8100b57cec5SDimitry Andric return pos_type(-1); 8110b57cec5SDimitry Andric if (__noff != 0) 8120b57cec5SDimitry Andric { 813e8d8bef9SDimitry Andric if ((__wch & ios_base::in) && this->gptr() == nullptr) 8140b57cec5SDimitry Andric return pos_type(-1); 815e8d8bef9SDimitry Andric if ((__wch & ios_base::out) && this->pptr() == nullptr) 8160b57cec5SDimitry Andric return pos_type(-1); 8170b57cec5SDimitry Andric } 8180b57cec5SDimitry Andric if (__wch & ios_base::in) 8190b57cec5SDimitry Andric this->setg(this->eback(), this->eback() + __noff, __hm_); 8200b57cec5SDimitry Andric if (__wch & ios_base::out) 8210b57cec5SDimitry Andric { 8220b57cec5SDimitry Andric this->setp(this->pbase(), this->epptr()); 82306c3fb27SDimitry Andric this->__pbump(__noff); 8240b57cec5SDimitry Andric } 8250b57cec5SDimitry Andric return pos_type(__noff); 8260b57cec5SDimitry Andric} 8270b57cec5SDimitry Andric 828bdd1243dSDimitry Andric// Class template basic_istringstream [istringstream] 8290b57cec5SDimitry Andric 8300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 8310b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_istringstream 8320b57cec5SDimitry Andric : public basic_istream<_CharT, _Traits> 8330b57cec5SDimitry Andric{ 8340b57cec5SDimitry Andricpublic: 8350b57cec5SDimitry Andric typedef _CharT char_type; 8360b57cec5SDimitry Andric typedef _Traits traits_type; 8370b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 8380b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 8390b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 8400b57cec5SDimitry Andric typedef _Allocator allocator_type; 8410b57cec5SDimitry Andric 8420b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 8430b57cec5SDimitry Andric 8440b57cec5SDimitry Andricprivate: 8450b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 8460b57cec5SDimitry Andric 8470b57cec5SDimitry Andricpublic: 848bdd1243dSDimitry Andric // [istringstream.cons] Constructors: 849*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 850fe6060f1SDimitry Andric basic_istringstream() 851fe6060f1SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in) {} 852e8d8bef9SDimitry Andric 853*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 854e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode __wch) 855e8d8bef9SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {} 856e8d8bef9SDimitry Andric 857*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 8580b57cec5SDimitry Andric explicit basic_istringstream(const string_type& __s, 859e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in) 860e8d8bef9SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_) 861e8d8bef9SDimitry Andric , __sb_(__s, __wch | ios_base::in) 862e8d8bef9SDimitry Andric { } 8630b57cec5SDimitry Andric 86406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 86506c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) 86606c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {} 86706c3fb27SDimitry Andric 86806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in) 86906c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {} 87006c3fb27SDimitry Andric 87106c3fb27SDimitry Andric template <class _SAlloc> 87206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 87306c3fb27SDimitry Andric : basic_istringstream(__s, ios_base::in, __a) {} 87406c3fb27SDimitry Andric 87506c3fb27SDimitry Andric template <class _SAlloc> 87606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream( 87706c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 87806c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {} 87906c3fb27SDimitry Andric 88006c3fb27SDimitry Andric template <class _SAlloc> 88106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 88206c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in) 88306c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} 88406c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 88506c3fb27SDimitry Andric 886*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 887e8d8bef9SDimitry Andric basic_istringstream(basic_istringstream&& __rhs) 888*5f757f3fSDimitry Andric : basic_istream<_CharT, _Traits>(std::move(__rhs)) 889*5f757f3fSDimitry Andric , __sb_(std::move(__rhs.__sb_)) 8900b57cec5SDimitry Andric { 8910b57cec5SDimitry Andric basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 8920b57cec5SDimitry Andric } 8930b57cec5SDimitry Andric 894bdd1243dSDimitry Andric // [istringstream.assign] Assign and swap: 895e8d8bef9SDimitry Andric basic_istringstream& operator=(basic_istringstream&& __rhs) { 896*5f757f3fSDimitry Andric basic_istream<char_type, traits_type>::operator=(std::move(__rhs)); 897*5f757f3fSDimitry Andric __sb_ = std::move(__rhs.__sb_); 8980b57cec5SDimitry Andric return *this; 8990b57cec5SDimitry Andric } 900*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 901e8d8bef9SDimitry Andric void swap(basic_istringstream& __rhs) { 9020b57cec5SDimitry Andric basic_istream<char_type, traits_type>::swap(__rhs); 9030b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 9040b57cec5SDimitry Andric } 9050b57cec5SDimitry Andric 906bdd1243dSDimitry Andric // [istringstream.members] Member functions: 907*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 908e8d8bef9SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 909e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 910e8d8bef9SDimitry Andric } 91106c3fb27SDimitry Andric 9128a4dda33SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 9138a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 9148a4dda33SDimitry Andric#else 9158a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); } 91606c3fb27SDimitry Andric 9178a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); } 9188a4dda33SDimitry Andric#endif 9198a4dda33SDimitry Andric 9208a4dda33SDimitry Andric#if _LIBCPP_STD_VER >= 20 92106c3fb27SDimitry Andric template <class _SAlloc> 92206c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 92306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 92406c3fb27SDimitry Andric return __sb_.str(__sa); 925e8d8bef9SDimitry Andric } 92606c3fb27SDimitry Andric 92706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 92806c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 92906c3fb27SDimitry Andric 93006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 93106c3fb27SDimitry Andric 93206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 93306c3fb27SDimitry Andric template <class _SAlloc> 93406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 935e8d8bef9SDimitry Andric __sb_.str(__s); 936e8d8bef9SDimitry Andric } 93706c3fb27SDimitry Andric 93806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 93906c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 940e8d8bef9SDimitry Andric}; 941e8d8bef9SDimitry Andric 9420b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 943*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 9440b57cec5SDimitry Andricvoid 9450b57cec5SDimitry Andricswap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, 9460b57cec5SDimitry Andric basic_istringstream<_CharT, _Traits, _Allocator>& __y) 9470b57cec5SDimitry Andric{ 9480b57cec5SDimitry Andric __x.swap(__y); 9490b57cec5SDimitry Andric} 9500b57cec5SDimitry Andric 951bdd1243dSDimitry Andric// Class template basic_ostringstream [ostringstream] 9520b57cec5SDimitry Andric 9530b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 9540b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_ostringstream 9550b57cec5SDimitry Andric : public basic_ostream<_CharT, _Traits> 9560b57cec5SDimitry Andric{ 9570b57cec5SDimitry Andricpublic: 9580b57cec5SDimitry Andric typedef _CharT char_type; 9590b57cec5SDimitry Andric typedef _Traits traits_type; 9600b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 9610b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 9620b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 9630b57cec5SDimitry Andric typedef _Allocator allocator_type; 9640b57cec5SDimitry Andric 9650b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 9660b57cec5SDimitry Andric 9670b57cec5SDimitry Andricprivate: 9680b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 9690b57cec5SDimitry Andric 9700b57cec5SDimitry Andricpublic: 971bdd1243dSDimitry Andric // [ostringstream.cons] Constructors: 972*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 973fe6060f1SDimitry Andric basic_ostringstream() 974fe6060f1SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::out) {} 975e8d8bef9SDimitry Andric 976*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 977e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode __wch) 978fe6060f1SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out) {} 979e8d8bef9SDimitry Andric 980*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 9810b57cec5SDimitry Andric explicit basic_ostringstream(const string_type& __s, 982e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::out) 983e8d8bef9SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_) 984e8d8bef9SDimitry Andric , __sb_(__s, __wch | ios_base::out) 985e8d8bef9SDimitry Andric { } 9860b57cec5SDimitry Andric 98706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 98806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) 98906c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {} 99006c3fb27SDimitry Andric 99106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out) 99206c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {} 99306c3fb27SDimitry Andric 99406c3fb27SDimitry Andric template <class _SAlloc> 99506c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 99606c3fb27SDimitry Andric : basic_ostringstream(__s, ios_base::out, __a) {} 99706c3fb27SDimitry Andric 99806c3fb27SDimitry Andric template <class _SAlloc> 99906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream( 100006c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 100106c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {} 100206c3fb27SDimitry Andric 100306c3fb27SDimitry Andric template <class _SAlloc> 100406c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 100506c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 100606c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::out) 100706c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} 100806c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 100906c3fb27SDimitry Andric 1010*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1011e8d8bef9SDimitry Andric basic_ostringstream(basic_ostringstream&& __rhs) 1012*5f757f3fSDimitry Andric : basic_ostream<_CharT, _Traits>(std::move(__rhs)) 1013*5f757f3fSDimitry Andric , __sb_(std::move(__rhs.__sb_)) 10140b57cec5SDimitry Andric { 10150b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); 10160b57cec5SDimitry Andric } 10170b57cec5SDimitry Andric 1018bdd1243dSDimitry Andric // [ostringstream.assign] Assign and swap: 1019e8d8bef9SDimitry Andric basic_ostringstream& operator=(basic_ostringstream&& __rhs) { 1020*5f757f3fSDimitry Andric basic_ostream<char_type, traits_type>::operator=(std::move(__rhs)); 1021*5f757f3fSDimitry Andric __sb_ = std::move(__rhs.__sb_); 10220b57cec5SDimitry Andric return *this; 10230b57cec5SDimitry Andric } 10240b57cec5SDimitry Andric 1025*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1026e8d8bef9SDimitry Andric void swap(basic_ostringstream& __rhs) { 10270b57cec5SDimitry Andric basic_ostream<char_type, traits_type>::swap(__rhs); 10280b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 10290b57cec5SDimitry Andric } 10300b57cec5SDimitry Andric 1031bdd1243dSDimitry Andric // [ostringstream.members] Member functions: 1032*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1033e8d8bef9SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 1034e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 1035e8d8bef9SDimitry Andric } 103606c3fb27SDimitry Andric 10378a4dda33SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 10388a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 10398a4dda33SDimitry Andric#else 10408a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); } 104106c3fb27SDimitry Andric 10428a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); } 10438a4dda33SDimitry Andric#endif 10448a4dda33SDimitry Andric 10458a4dda33SDimitry Andric#if _LIBCPP_STD_VER >= 20 104606c3fb27SDimitry Andric template <class _SAlloc> 104706c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 104806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 104906c3fb27SDimitry Andric return __sb_.str(__sa); 1050e8d8bef9SDimitry Andric } 105106c3fb27SDimitry Andric 105206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 105306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 105406c3fb27SDimitry Andric 105506c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 105606c3fb27SDimitry Andric 105706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 105806c3fb27SDimitry Andric template <class _SAlloc> 105906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 1060e8d8bef9SDimitry Andric __sb_.str(__s); 1061e8d8bef9SDimitry Andric } 106206c3fb27SDimitry Andric 106306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 106406c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1065e8d8bef9SDimitry Andric}; 1066e8d8bef9SDimitry Andric 10670b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 1068*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 10690b57cec5SDimitry Andricvoid 10700b57cec5SDimitry Andricswap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, 10710b57cec5SDimitry Andric basic_ostringstream<_CharT, _Traits, _Allocator>& __y) 10720b57cec5SDimitry Andric{ 10730b57cec5SDimitry Andric __x.swap(__y); 10740b57cec5SDimitry Andric} 10750b57cec5SDimitry Andric 1076bdd1243dSDimitry Andric// Class template basic_stringstream [stringstream] 10770b57cec5SDimitry Andric 10780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 10790b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_stringstream 10800b57cec5SDimitry Andric : public basic_iostream<_CharT, _Traits> 10810b57cec5SDimitry Andric{ 10820b57cec5SDimitry Andricpublic: 10830b57cec5SDimitry Andric typedef _CharT char_type; 10840b57cec5SDimitry Andric typedef _Traits traits_type; 10850b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 10860b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 10870b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 10880b57cec5SDimitry Andric typedef _Allocator allocator_type; 10890b57cec5SDimitry Andric 10900b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 10910b57cec5SDimitry Andric 10920b57cec5SDimitry Andricprivate: 10930b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 10940b57cec5SDimitry Andric 10950b57cec5SDimitry Andricpublic: 1096bdd1243dSDimitry Andric // [stringstream.cons] constructors 1097*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1098fe6060f1SDimitry Andric basic_stringstream() 1099fe6060f1SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in | ios_base::out) {} 1100e8d8bef9SDimitry Andric 1101*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1102e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode __wch) 1103e8d8bef9SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {} 1104e8d8bef9SDimitry Andric 1105*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 11060b57cec5SDimitry Andric explicit basic_stringstream(const string_type& __s, 1107e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 1108e8d8bef9SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_) 1109e8d8bef9SDimitry Andric , __sb_(__s, __wch) 1110e8d8bef9SDimitry Andric { } 11110b57cec5SDimitry Andric 111206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 111306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a) 111406c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {} 111506c3fb27SDimitry Andric 111606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out | ios_base::in) 111706c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {} 111806c3fb27SDimitry Andric 111906c3fb27SDimitry Andric template <class _SAlloc> 112006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 112106c3fb27SDimitry Andric : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {} 112206c3fb27SDimitry Andric 112306c3fb27SDimitry Andric template <class _SAlloc> 112406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream( 112506c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 112606c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {} 112706c3fb27SDimitry Andric 112806c3fb27SDimitry Andric template <class _SAlloc> 112906c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 113006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 113106c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::out | ios_base::in) 113206c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} 113306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 113406c3fb27SDimitry Andric 1135*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1136e8d8bef9SDimitry Andric basic_stringstream(basic_stringstream&& __rhs) 1137*5f757f3fSDimitry Andric : basic_iostream<_CharT, _Traits>(std::move(__rhs)) 1138*5f757f3fSDimitry Andric , __sb_(std::move(__rhs.__sb_)) 11390b57cec5SDimitry Andric { 11400b57cec5SDimitry Andric basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 11410b57cec5SDimitry Andric } 11420b57cec5SDimitry Andric 1143bdd1243dSDimitry Andric // [stringstream.assign] Assign and swap: 1144e8d8bef9SDimitry Andric basic_stringstream& operator=(basic_stringstream&& __rhs) { 1145*5f757f3fSDimitry Andric basic_iostream<char_type, traits_type>::operator=(std::move(__rhs)); 1146*5f757f3fSDimitry Andric __sb_ = std::move(__rhs.__sb_); 11470b57cec5SDimitry Andric return *this; 11480b57cec5SDimitry Andric } 1149*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1150e8d8bef9SDimitry Andric void swap(basic_stringstream& __rhs) { 11510b57cec5SDimitry Andric basic_iostream<char_type, traits_type>::swap(__rhs); 11520b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 11530b57cec5SDimitry Andric } 11540b57cec5SDimitry Andric 1155bdd1243dSDimitry Andric // [stringstream.members] Member functions: 1156*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1157e8d8bef9SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 1158e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 1159e8d8bef9SDimitry Andric } 116006c3fb27SDimitry Andric 11618a4dda33SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 11628a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 11638a4dda33SDimitry Andric#else 11648a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return __sb_.str(); } 116506c3fb27SDimitry Andric 11668a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { return std::move(__sb_).str(); } 11678a4dda33SDimitry Andric#endif 11688a4dda33SDimitry Andric 11698a4dda33SDimitry Andric#if _LIBCPP_STD_VER >= 20 117006c3fb27SDimitry Andric template <class _SAlloc> 117106c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 117206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 117306c3fb27SDimitry Andric return __sb_.str(__sa); 1174e8d8bef9SDimitry Andric } 117506c3fb27SDimitry Andric 117606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 117706c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 117806c3fb27SDimitry Andric 117906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 118006c3fb27SDimitry Andric 118106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 118206c3fb27SDimitry Andric template <class _SAlloc> 118306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 1184e8d8bef9SDimitry Andric __sb_.str(__s); 1185e8d8bef9SDimitry Andric } 118606c3fb27SDimitry Andric 118706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 118806c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1189e8d8bef9SDimitry Andric}; 1190e8d8bef9SDimitry Andric 11910b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 1192*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 11930b57cec5SDimitry Andricvoid 11940b57cec5SDimitry Andricswap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, 11950b57cec5SDimitry Andric basic_stringstream<_CharT, _Traits, _Allocator>& __y) 11960b57cec5SDimitry Andric{ 11970b57cec5SDimitry Andric __x.swap(__y); 11980b57cec5SDimitry Andric} 11990b57cec5SDimitry Andric 1200*5f757f3fSDimitry Andric#if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 120181ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>; 120281ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>; 120381ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>; 120481ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>; 1205e8d8bef9SDimitry Andric#endif 12060b57cec5SDimitry Andric 12070b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 12080b57cec5SDimitry Andric 12090b57cec5SDimitry Andric_LIBCPP_POP_MACROS 12100b57cec5SDimitry Andric 1211bdd1243dSDimitry Andric#if _LIBCPP_STD_VER <= 20 && !defined(_LIPCPP_REMOVE_TRANSITIVE_INCLUDES) 1212bdd1243dSDimitry Andric# include <type_traits> 1213bdd1243dSDimitry Andric#endif 1214bdd1243dSDimitry Andric 12150b57cec5SDimitry Andric#endif // _LIBCPP_SSTREAM 1216