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 135f757f3fSDimitry Andric// clang-format off 145f757f3fSDimitry 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 51*0fca6ea1SDimitry Andric template<class T> 52*0fca6ea1SDimitry Andric explicit basic_stringbuf(const T& t, 53*0fca6ea1SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); // Since C++26 54*0fca6ea1SDimitry Andric template<class T> 55*0fca6ea1SDimitry Andric basic_stringbuf(const T& t, const Allocator& a); // Since C++26 56*0fca6ea1SDimitry Andric template<class T> 57*0fca6ea1SDimitry Andric basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 58*0fca6ea1SDimitry Andric basic_stringbuf(const basic_stringbuf&) = delete; 590b57cec5SDimitry Andric basic_stringbuf(basic_stringbuf&& rhs); 6006c3fb27SDimitry Andric basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20 610b57cec5SDimitry Andric 62bdd1243dSDimitry Andric // [stringbuf.assign] Assign and swap: 63*0fca6ea1SDimitry Andric basic_stringbuf& operator=(const basic_stringbuf&) = delete; 640b57cec5SDimitry Andric basic_stringbuf& operator=(basic_stringbuf&& rhs); 6506c3fb27SDimitry Andric void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20 660b57cec5SDimitry Andric 67bdd1243dSDimitry Andric // [stringbuf.members] Member functions: 6806c3fb27SDimitry Andric allocator_type get_allocator() const noexcept; // C++20 6906c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 7006c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 7106c3fb27SDimitry Andric template <class SAlloc> 7206c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 7306c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 7406c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 750b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 7606c3fb27SDimitry Andric template <class SAlloc> 7706c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 7806c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 79*0fca6ea1SDimitry Andric template<class T> 80*0fca6ea1SDimitry Andric void str(const T& t); // Since C++26 810b57cec5SDimitry Andric 820b57cec5SDimitry Andricprotected: 83bdd1243dSDimitry Andric // [stringbuf.virtuals] Overridden virtual functions: 840b57cec5SDimitry Andric virtual int_type underflow(); 850b57cec5SDimitry Andric virtual int_type pbackfail(int_type c = traits_type::eof()); 860b57cec5SDimitry Andric virtual int_type overflow (int_type c = traits_type::eof()); 870b57cec5SDimitry Andric virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); 880b57cec5SDimitry Andric virtual pos_type seekoff(off_type off, ios_base::seekdir way, 890b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 900b57cec5SDimitry Andric virtual pos_type seekpos(pos_type sp, 910b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 920b57cec5SDimitry Andric}; 930b57cec5SDimitry Andric 94bdd1243dSDimitry Andric// [stringbuf.assign] non member swap 950b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 960b57cec5SDimitry Andricvoid swap(basic_stringbuf<charT, traits, Allocator>& x, 9706c3fb27SDimitry Andric basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20 980b57cec5SDimitry Andric 990b57cec5SDimitry Andrictypedef basic_stringbuf<char> stringbuf; 1000b57cec5SDimitry Andrictypedef basic_stringbuf<wchar_t> wstringbuf; 1010b57cec5SDimitry Andric 102bdd1243dSDimitry Andric// Class template basic_istringstream [istringstream] 1030b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 1040b57cec5SDimitry Andricclass basic_istringstream 1050b57cec5SDimitry Andric : public basic_istream<charT, traits> 1060b57cec5SDimitry Andric{ 1070b57cec5SDimitry Andricpublic: 1080b57cec5SDimitry Andric typedef charT char_type; 1090b57cec5SDimitry Andric typedef traits traits_type; 1100b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 1110b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 1120b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1130b57cec5SDimitry Andric typedef Allocator allocator_type; 1140b57cec5SDimitry Andric 115bdd1243dSDimitry Andric // [istringstream.cons] Constructors: 116e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 117e8d8bef9SDimitry Andric basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 118e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode which); // C++20 11906c3fb27SDimitry Andric explicit basic_istringstream(const basic_string<char_type, traits_type, allocator_type>& s, 1200b57cec5SDimitry Andric ios_base::openmode which = ios_base::in); 12106c3fb27SDimitry Andric basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20 12206c3fb27SDimitry Andric explicit basic_istringstream(basic_string<char_type, traits_type, allocator_type>&& s, 12306c3fb27SDimitry Andric ios_base::openmode which = ios_base::in); // C++20 12406c3fb27SDimitry Andric template <class SAlloc> 12506c3fb27SDimitry Andric basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 12606c3fb27SDimitry Andric : basic_istringstream(s, ios_base::in, a) {} // C++20 12706c3fb27SDimitry Andric template <class SAlloc> 12806c3fb27SDimitry Andric basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, 12906c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 13006c3fb27SDimitry Andric template <class SAlloc> 13106c3fb27SDimitry Andric explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, 13206c3fb27SDimitry Andric ios_base::openmode which = ios_base::in); // C++20 133*0fca6ea1SDimitry Andric template<class T> 134*0fca6ea1SDimitry Andric explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); // Since C++26 135*0fca6ea1SDimitry Andric template<class T> 136*0fca6ea1SDimitry Andric basic_istringstream(const T& t, const Allocator& a); // Since C++26 137*0fca6ea1SDimitry Andric template<class T> 138*0fca6ea1SDimitry Andric basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 139*0fca6ea1SDimitry Andric basic_istringstream(const basic_istringstream&) = delete; 1400b57cec5SDimitry Andric basic_istringstream(basic_istringstream&& rhs); 1410b57cec5SDimitry Andric 142bdd1243dSDimitry Andric // [istringstream.assign] Assign and swap: 143*0fca6ea1SDimitry Andric basic_istringstream& operator=(const basic_istringstream&) = delete; 1440b57cec5SDimitry Andric basic_istringstream& operator=(basic_istringstream&& rhs); 1450b57cec5SDimitry Andric void swap(basic_istringstream& rhs); 1460b57cec5SDimitry Andric 147bdd1243dSDimitry Andric // [istringstream.members] Member functions: 1480b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 14906c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 15006c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 15106c3fb27SDimitry Andric template <class SAlloc> 15206c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 15306c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 15406c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 1550b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 15606c3fb27SDimitry Andric template <class SAlloc> 15706c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 15806c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 159*0fca6ea1SDimitry Andric template<class T> 160*0fca6ea1SDimitry Andric void str(const T& t); // Since C++26 1610b57cec5SDimitry Andric}; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 1640b57cec5SDimitry Andricvoid swap(basic_istringstream<charT, traits, Allocator>& x, 1650b57cec5SDimitry Andric basic_istringstream<charT, traits, Allocator>& y); 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andrictypedef basic_istringstream<char> istringstream; 1680b57cec5SDimitry Andrictypedef basic_istringstream<wchar_t> wistringstream; 1690b57cec5SDimitry Andric 170bdd1243dSDimitry Andric// Class template basic_ostringstream [ostringstream] 1710b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 1720b57cec5SDimitry Andricclass basic_ostringstream 1730b57cec5SDimitry Andric : public basic_ostream<charT, traits> 1740b57cec5SDimitry Andric{ 1750b57cec5SDimitry Andricpublic: 1760b57cec5SDimitry Andric // types: 1770b57cec5SDimitry Andric typedef charT char_type; 1780b57cec5SDimitry Andric typedef traits traits_type; 1790b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 1800b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 1810b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1820b57cec5SDimitry Andric typedef Allocator allocator_type; 1830b57cec5SDimitry Andric 184bdd1243dSDimitry Andric // [ostringstream.cons] Constructors: 185e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 186e8d8bef9SDimitry Andric basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 187e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode which); // C++20 18806c3fb27SDimitry Andric explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& s, 1890b57cec5SDimitry Andric ios_base::openmode which = ios_base::out); 19006c3fb27SDimitry Andric basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20 19106c3fb27SDimitry Andric explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s, 19206c3fb27SDimitry Andric ios_base::openmode which = ios_base::out); // C++20 19306c3fb27SDimitry Andric template <class SAlloc> 19406c3fb27SDimitry Andric basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 19506c3fb27SDimitry Andric : basic_ostringstream(s, ios_base::out, a) {} // C++20 19606c3fb27SDimitry Andric template <class SAlloc> 19706c3fb27SDimitry Andric basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, 19806c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 19906c3fb27SDimitry Andric template <class SAlloc> 20006c3fb27SDimitry Andric explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, 20106c3fb27SDimitry Andric ios_base::openmode which = ios_base::out); // C++20 202*0fca6ea1SDimitry Andric template<class T> 203*0fca6ea1SDimitry Andric explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); // Since C++26 204*0fca6ea1SDimitry Andric template<class T> 205*0fca6ea1SDimitry Andric basic_ostringstream(const T& t, const Allocator& a); // Since C++26 206*0fca6ea1SDimitry Andric template<class T> 207*0fca6ea1SDimitry Andric basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 208*0fca6ea1SDimitry Andric basic_ostringstream(const basic_ostringstream&) = delete; 2090b57cec5SDimitry Andric basic_ostringstream(basic_ostringstream&& rhs); 2100b57cec5SDimitry Andric 211bdd1243dSDimitry Andric // [ostringstream.assign] Assign and swap: 212*0fca6ea1SDimitry Andric basic_ostringstream& operator=(const basic_ostringstream&) = delete; 2130b57cec5SDimitry Andric basic_ostringstream& operator=(basic_ostringstream&& rhs); 2140b57cec5SDimitry Andric void swap(basic_ostringstream& rhs); 2150b57cec5SDimitry Andric 216bdd1243dSDimitry Andric // [ostringstream.members] Member functions: 2170b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 21806c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 21906c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 22006c3fb27SDimitry Andric template <class SAlloc> 22106c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 22206c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 22306c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 2240b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 22506c3fb27SDimitry Andric template <class SAlloc> 22606c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 22706c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 228*0fca6ea1SDimitry Andric template<class T> 229*0fca6ea1SDimitry Andric void str(const T& t); // Since C++26 2300b57cec5SDimitry Andric}; 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 2330b57cec5SDimitry Andricvoid swap(basic_ostringstream<charT, traits, Allocator>& x, 2340b57cec5SDimitry Andric basic_ostringstream<charT, traits, Allocator>& y); 2350b57cec5SDimitry Andric 2360b57cec5SDimitry Andrictypedef basic_ostringstream<char> ostringstream; 2370b57cec5SDimitry Andrictypedef basic_ostringstream<wchar_t> wostringstream; 2380b57cec5SDimitry Andric 239bdd1243dSDimitry Andric// Class template basic_stringstream [stringstream] 2400b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 2410b57cec5SDimitry Andricclass basic_stringstream 2420b57cec5SDimitry Andric : public basic_iostream<charT, traits> 2430b57cec5SDimitry Andric{ 2440b57cec5SDimitry Andricpublic: 2450b57cec5SDimitry Andric // types: 2460b57cec5SDimitry Andric typedef charT char_type; 2470b57cec5SDimitry Andric typedef traits traits_type; 2480b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 2490b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 2500b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 2510b57cec5SDimitry Andric typedef Allocator allocator_type; 2520b57cec5SDimitry Andric 253bdd1243dSDimitry Andric // [stringstream.cons] constructors 254e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 255e8d8bef9SDimitry Andric basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 256e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode which); // C++20 25706c3fb27SDimitry Andric explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s, 2580b57cec5SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); 25906c3fb27SDimitry Andric basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20 26006c3fb27SDimitry Andric explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s, 26106c3fb27SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // C++20 26206c3fb27SDimitry Andric template <class SAlloc> 26306c3fb27SDimitry Andric basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 26406c3fb27SDimitry Andric : basic_stringstream(s, ios_base::out | ios_base::in, a) {} // C++20 26506c3fb27SDimitry Andric template <class SAlloc> 26606c3fb27SDimitry Andric basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, 26706c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 26806c3fb27SDimitry Andric template <class SAlloc> 26906c3fb27SDimitry Andric explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, 27006c3fb27SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // C++20 271*0fca6ea1SDimitry Andric template<class T> 272*0fca6ea1SDimitry Andric explicit basic_stringstream(const T& t, 273*0fca6ea1SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // Since C++26 274*0fca6ea1SDimitry Andric template<class T> 275*0fca6ea1SDimitry Andric basic_stringstream(const T& t, const Allocator& a); // Since C++26 276*0fca6ea1SDimitry Andric template<class T> 277*0fca6ea1SDimitry Andric basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a); // Since C++26 278*0fca6ea1SDimitry Andric basic_stringstream(const basic_stringstream&) = delete; 2790b57cec5SDimitry Andric basic_stringstream(basic_stringstream&& rhs); 2800b57cec5SDimitry Andric 281bdd1243dSDimitry Andric // [stringstream.assign] Assign and swap: 282*0fca6ea1SDimitry Andric basic_stringstream& operator=(const basic_stringstream&) = delete; 2830b57cec5SDimitry Andric basic_stringstream& operator=(basic_stringstream&& rhs); 2840b57cec5SDimitry Andric void swap(basic_stringstream& rhs); 2850b57cec5SDimitry Andric 286bdd1243dSDimitry Andric // [stringstream.members] Member functions: 2870b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 28806c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 28906c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 29006c3fb27SDimitry Andric template <class SAlloc> 29106c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 29206c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 29306c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 29406c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 29506c3fb27SDimitry Andric template <class SAlloc> 29606c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 29706c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 298*0fca6ea1SDimitry Andric template<class T> 299*0fca6ea1SDimitry Andric void str(const T& t); // Since C++26 3000b57cec5SDimitry Andric}; 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 3030b57cec5SDimitry Andricvoid swap(basic_stringstream<charT, traits, Allocator>& x, 3040b57cec5SDimitry Andric basic_stringstream<charT, traits, Allocator>& y); 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andrictypedef basic_stringstream<char> stringstream; 3070b57cec5SDimitry Andrictypedef basic_stringstream<wchar_t> wstringstream; 3080b57cec5SDimitry Andric 3090b57cec5SDimitry Andric} // std 3100b57cec5SDimitry Andric 3110b57cec5SDimitry Andric*/ 3120b57cec5SDimitry Andric 3135f757f3fSDimitry Andric// clang-format on 3145f757f3fSDimitry Andric 3150b57cec5SDimitry Andric#include <__config> 31606c3fb27SDimitry Andric#include <__fwd/sstream.h> 317*0fca6ea1SDimitry Andric#include <__ostream/basic_ostream.h> 318*0fca6ea1SDimitry Andric#include <__type_traits/is_convertible.h> 31981ad6265SDimitry Andric#include <__utility/swap.h> 3200b57cec5SDimitry Andric#include <istream> 3210b57cec5SDimitry Andric#include <string> 322*0fca6ea1SDimitry Andric#include <string_view> 32304eeddc0SDimitry Andric#include <version> 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 3260b57cec5SDimitry Andric# pragma GCC system_header 3270b57cec5SDimitry Andric#endif 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 3300b57cec5SDimitry Andric#include <__undef_macros> 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3330b57cec5SDimitry Andric 334bdd1243dSDimitry Andric// Class template basic_stringbuf [stringbuf] 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 337cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_stringbuf : public basic_streambuf<_CharT, _Traits> { 3380b57cec5SDimitry Andricpublic: 3390b57cec5SDimitry Andric typedef _CharT char_type; 3400b57cec5SDimitry Andric typedef _Traits traits_type; 3410b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 3420b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 3430b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 3440b57cec5SDimitry Andric typedef _Allocator allocator_type; 3450b57cec5SDimitry Andric 3460b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 3470b57cec5SDimitry Andric 3480b57cec5SDimitry Andricprivate: 3490b57cec5SDimitry Andric string_type __str_; 3500b57cec5SDimitry Andric mutable char_type* __hm_; 3510b57cec5SDimitry Andric ios_base::openmode __mode_; 35206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); 35306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); 3540b57cec5SDimitry Andric 3550b57cec5SDimitry Andricpublic: 356bdd1243dSDimitry Andric // [stringbuf.cons] constructors: 357cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {} 358e8d8bef9SDimitry Andric 359cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) {} 360e8d8bef9SDimitry Andric 361cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s, 362e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 363cb14a3feSDimitry Andric : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) { 364e8d8bef9SDimitry Andric str(__s); 365e8d8bef9SDimitry Andric } 366e8d8bef9SDimitry Andric 36706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 36806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) 36906c3fb27SDimitry Andric : basic_stringbuf(ios_base::in | ios_base::out, __a) {} 37006c3fb27SDimitry Andric 37106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) 37206c3fb27SDimitry Andric : __str_(__a), __hm_(nullptr), __mode_(__wch) {} 37306c3fb27SDimitry Andric 37406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, 37506c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 37606c3fb27SDimitry Andric : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { 37706c3fb27SDimitry Andric __init_buf_ptrs(); 37806c3fb27SDimitry Andric } 37906c3fb27SDimitry Andric 38006c3fb27SDimitry Andric template <class _SAlloc> 38106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 38206c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a) 38306c3fb27SDimitry Andric : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} 38406c3fb27SDimitry Andric 38506c3fb27SDimitry Andric template <class _SAlloc> 38606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf( 38706c3fb27SDimitry Andric const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a) 38806c3fb27SDimitry Andric : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { 38906c3fb27SDimitry Andric __init_buf_ptrs(); 39006c3fb27SDimitry Andric } 39106c3fb27SDimitry Andric 39206c3fb27SDimitry Andric template <class _SAlloc> 39306c3fb27SDimitry Andric requires(!is_same_v<_SAlloc, allocator_type>) 39406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, 39506c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 39606c3fb27SDimitry Andric : __str_(__s), __hm_(nullptr), __mode_(__wch) { 39706c3fb27SDimitry Andric __init_buf_ptrs(); 39806c3fb27SDimitry Andric } 39906c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 40006c3fb27SDimitry Andric 401*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 402*0fca6ea1SDimitry Andric 403*0fca6ea1SDimitry Andric template <class _Tp> 404*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 405*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t, 406*0fca6ea1SDimitry Andric ios_base::openmode __which = ios_base::in | ios_base::out) 407*0fca6ea1SDimitry Andric : basic_stringbuf(__t, __which, _Allocator()) {} 408*0fca6ea1SDimitry Andric 409*0fca6ea1SDimitry Andric template <class _Tp> 410*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 411*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a) 412*0fca6ea1SDimitry Andric : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {} 413*0fca6ea1SDimitry Andric 414*0fca6ea1SDimitry Andric template <class _Tp> 415*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 416*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) 417*0fca6ea1SDimitry Andric : __hm_(nullptr), __mode_(__which) { 418*0fca6ea1SDimitry Andric basic_string_view<_CharT, _Traits> __sv = __t; 419*0fca6ea1SDimitry Andric __str_ = string_type(__sv, __a); 420*0fca6ea1SDimitry Andric __init_buf_ptrs(); 421*0fca6ea1SDimitry Andric } 422*0fca6ea1SDimitry Andric 423*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 424*0fca6ea1SDimitry Andric 425*0fca6ea1SDimitry Andric basic_stringbuf(const basic_stringbuf&) = delete; 42606c3fb27SDimitry Andric basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); } 42706c3fb27SDimitry Andric 42806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 42906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) 43006c3fb27SDimitry Andric : basic_stringbuf(__rhs.__mode_, __a) { 43106c3fb27SDimitry Andric __move_init(std::move(__rhs)); 43206c3fb27SDimitry Andric } 43306c3fb27SDimitry Andric#endif 4340b57cec5SDimitry Andric 435bdd1243dSDimitry Andric // [stringbuf.assign] Assign and swap: 436*0fca6ea1SDimitry Andric basic_stringbuf& operator=(const basic_stringbuf&) = delete; 4370b57cec5SDimitry Andric basic_stringbuf& operator=(basic_stringbuf&& __rhs); 43806c3fb27SDimitry Andric void swap(basic_stringbuf& __rhs) 43906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 44006c3fb27SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 44106c3fb27SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value) 44206c3fb27SDimitry Andric#endif 44306c3fb27SDimitry Andric ; 4440b57cec5SDimitry Andric 445bdd1243dSDimitry Andric // [stringbuf.members] Member functions: 44606c3fb27SDimitry Andric 44706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 44806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } 44906c3fb27SDimitry Andric#endif 45006c3fb27SDimitry Andric 45106c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 4520b57cec5SDimitry Andric string_type str() const; 45306c3fb27SDimitry Andric#else 454*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); } 45506c3fb27SDimitry Andric 456*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { 45706c3fb27SDimitry Andric const basic_string_view<_CharT, _Traits> __view = view(); 4585f757f3fSDimitry Andric typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data(); 4595f757f3fSDimitry Andric // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator()); 4605f757f3fSDimitry Andric // But we need something that works in C++20 also. 4611db9f3b2SDimitry Andric string_type __result(std::move(__str_), __str_.get_allocator()); 4621db9f3b2SDimitry Andric __result.resize(__pos + __view.size()); 4631db9f3b2SDimitry Andric __result.erase(0, __pos); 46406c3fb27SDimitry Andric __init_buf_ptrs(); 46506c3fb27SDimitry Andric return __result; 46606c3fb27SDimitry Andric } 46706c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 46806c3fb27SDimitry Andric 46906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 47006c3fb27SDimitry Andric template <class _SAlloc> 47106c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 47206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 47306c3fb27SDimitry Andric return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); 47406c3fb27SDimitry Andric } 47506c3fb27SDimitry Andric 47606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept; 4778a4dda33SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 47806c3fb27SDimitry Andric 47906c3fb27SDimitry Andric void str(const string_type& __s) { 48006c3fb27SDimitry Andric __str_ = __s; 48106c3fb27SDimitry Andric __init_buf_ptrs(); 48206c3fb27SDimitry Andric } 48306c3fb27SDimitry Andric 48406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 48506c3fb27SDimitry Andric template <class _SAlloc> 48606c3fb27SDimitry Andric requires(!is_same_v<_SAlloc, allocator_type>) 48706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 48806c3fb27SDimitry Andric __str_ = __s; 48906c3fb27SDimitry Andric __init_buf_ptrs(); 49006c3fb27SDimitry Andric } 49106c3fb27SDimitry Andric 49206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { 49306c3fb27SDimitry Andric __str_ = std::move(__s); 49406c3fb27SDimitry Andric __init_buf_ptrs(); 49506c3fb27SDimitry Andric } 49606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 4970b57cec5SDimitry Andric 498*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 499*0fca6ea1SDimitry Andric 500*0fca6ea1SDimitry Andric template <class _Tp> 501*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 502*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { 503*0fca6ea1SDimitry Andric basic_string_view<_CharT, _Traits> __sv = __t; 504*0fca6ea1SDimitry Andric __str_ = __sv; 505*0fca6ea1SDimitry Andric __init_buf_ptrs(); 506*0fca6ea1SDimitry Andric } 507*0fca6ea1SDimitry Andric 508*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 509*0fca6ea1SDimitry Andric 5100b57cec5SDimitry Andricprotected: 511bdd1243dSDimitry Andric // [stringbuf.virtuals] Overridden virtual functions: 512bdd1243dSDimitry Andric int_type underflow() override; 513bdd1243dSDimitry Andric int_type pbackfail(int_type __c = traits_type::eof()) override; 514bdd1243dSDimitry Andric int_type overflow(int_type __c = traits_type::eof()) override; 515cb14a3feSDimitry Andric pos_type 516cb14a3feSDimitry Andric seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override; 517bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI_VIRTUAL 518cb14a3feSDimitry Andric pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override { 519e8d8bef9SDimitry Andric return seekoff(__sp, ios_base::beg, __wch); 520e8d8bef9SDimitry Andric } 5210b57cec5SDimitry Andric}; 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 52406c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { 5250b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 5260b57cec5SDimitry Andric ptrdiff_t __binp = -1; 5270b57cec5SDimitry Andric ptrdiff_t __ninp = -1; 5280b57cec5SDimitry Andric ptrdiff_t __einp = -1; 529cb14a3feSDimitry Andric if (__rhs.eback() != nullptr) { 5300b57cec5SDimitry Andric __binp = __rhs.eback() - __p; 5310b57cec5SDimitry Andric __ninp = __rhs.gptr() - __p; 5320b57cec5SDimitry Andric __einp = __rhs.egptr() - __p; 5330b57cec5SDimitry Andric } 5340b57cec5SDimitry Andric ptrdiff_t __bout = -1; 5350b57cec5SDimitry Andric ptrdiff_t __nout = -1; 5360b57cec5SDimitry Andric ptrdiff_t __eout = -1; 537cb14a3feSDimitry Andric if (__rhs.pbase() != nullptr) { 5380b57cec5SDimitry Andric __bout = __rhs.pbase() - __p; 5390b57cec5SDimitry Andric __nout = __rhs.pptr() - __p; 5400b57cec5SDimitry Andric __eout = __rhs.epptr() - __p; 5410b57cec5SDimitry Andric } 5420b57cec5SDimitry Andric ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 5435f757f3fSDimitry Andric __str_ = std::move(__rhs.__str_); 5440b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5450b57cec5SDimitry Andric if (__binp != -1) 5460b57cec5SDimitry Andric this->setg(__p + __binp, __p + __ninp, __p + __einp); 547cb14a3feSDimitry Andric if (__bout != -1) { 5480b57cec5SDimitry Andric this->setp(__p + __bout, __p + __eout); 5490b57cec5SDimitry Andric this->__pbump(__nout); 5500b57cec5SDimitry Andric } 5510b57cec5SDimitry Andric __hm_ = __hm == -1 ? nullptr : __p + __hm; 5520b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 5530b57cec5SDimitry Andric __rhs.setg(__p, __p, __p); 5540b57cec5SDimitry Andric __rhs.setp(__p, __p); 5550b57cec5SDimitry Andric __rhs.__hm_ = __p; 5560b57cec5SDimitry Andric this->pubimbue(__rhs.getloc()); 5570b57cec5SDimitry Andric} 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 5600b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>& 561cb14a3feSDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) { 5620b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 5630b57cec5SDimitry Andric ptrdiff_t __binp = -1; 5640b57cec5SDimitry Andric ptrdiff_t __ninp = -1; 5650b57cec5SDimitry Andric ptrdiff_t __einp = -1; 566cb14a3feSDimitry Andric if (__rhs.eback() != nullptr) { 5670b57cec5SDimitry Andric __binp = __rhs.eback() - __p; 5680b57cec5SDimitry Andric __ninp = __rhs.gptr() - __p; 5690b57cec5SDimitry Andric __einp = __rhs.egptr() - __p; 5700b57cec5SDimitry Andric } 5710b57cec5SDimitry Andric ptrdiff_t __bout = -1; 5720b57cec5SDimitry Andric ptrdiff_t __nout = -1; 5730b57cec5SDimitry Andric ptrdiff_t __eout = -1; 574cb14a3feSDimitry Andric if (__rhs.pbase() != nullptr) { 5750b57cec5SDimitry Andric __bout = __rhs.pbase() - __p; 5760b57cec5SDimitry Andric __nout = __rhs.pptr() - __p; 5770b57cec5SDimitry Andric __eout = __rhs.epptr() - __p; 5780b57cec5SDimitry Andric } 5790b57cec5SDimitry Andric ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 5805f757f3fSDimitry Andric __str_ = std::move(__rhs.__str_); 5810b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5820b57cec5SDimitry Andric if (__binp != -1) 5830b57cec5SDimitry Andric this->setg(__p + __binp, __p + __ninp, __p + __einp); 5840b57cec5SDimitry Andric else 5850b57cec5SDimitry Andric this->setg(nullptr, nullptr, nullptr); 586cb14a3feSDimitry Andric if (__bout != -1) { 5870b57cec5SDimitry Andric this->setp(__p + __bout, __p + __eout); 5880b57cec5SDimitry Andric this->__pbump(__nout); 589cb14a3feSDimitry Andric } else 5900b57cec5SDimitry Andric this->setp(nullptr, nullptr); 5910b57cec5SDimitry Andric 5920b57cec5SDimitry Andric __hm_ = __hm == -1 ? nullptr : __p + __hm; 5930b57cec5SDimitry Andric __mode_ = __rhs.__mode_; 5940b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 5950b57cec5SDimitry Andric __rhs.setg(__p, __p, __p); 5960b57cec5SDimitry Andric __rhs.setp(__p, __p); 5970b57cec5SDimitry Andric __rhs.__hm_ = __p; 5980b57cec5SDimitry Andric this->pubimbue(__rhs.getloc()); 5990b57cec5SDimitry Andric return *this; 6000b57cec5SDimitry Andric} 6010b57cec5SDimitry Andric 6020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 603cb14a3feSDimitry Andricvoid basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) 60406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 60506c3fb27SDimitry Andric noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value || 60606c3fb27SDimitry Andric allocator_traits<_Allocator>::is_always_equal::value) 60706c3fb27SDimitry Andric#endif 6080b57cec5SDimitry Andric{ 6090b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 6100b57cec5SDimitry Andric ptrdiff_t __rbinp = -1; 6110b57cec5SDimitry Andric ptrdiff_t __rninp = -1; 6120b57cec5SDimitry Andric ptrdiff_t __reinp = -1; 613cb14a3feSDimitry Andric if (__rhs.eback() != nullptr) { 6140b57cec5SDimitry Andric __rbinp = __rhs.eback() - __p; 6150b57cec5SDimitry Andric __rninp = __rhs.gptr() - __p; 6160b57cec5SDimitry Andric __reinp = __rhs.egptr() - __p; 6170b57cec5SDimitry Andric } 6180b57cec5SDimitry Andric ptrdiff_t __rbout = -1; 6190b57cec5SDimitry Andric ptrdiff_t __rnout = -1; 6200b57cec5SDimitry Andric ptrdiff_t __reout = -1; 621cb14a3feSDimitry Andric if (__rhs.pbase() != nullptr) { 6220b57cec5SDimitry Andric __rbout = __rhs.pbase() - __p; 6230b57cec5SDimitry Andric __rnout = __rhs.pptr() - __p; 6240b57cec5SDimitry Andric __reout = __rhs.epptr() - __p; 6250b57cec5SDimitry Andric } 6260b57cec5SDimitry Andric ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 6270b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 6280b57cec5SDimitry Andric ptrdiff_t __lbinp = -1; 6290b57cec5SDimitry Andric ptrdiff_t __lninp = -1; 6300b57cec5SDimitry Andric ptrdiff_t __leinp = -1; 631cb14a3feSDimitry Andric if (this->eback() != nullptr) { 6320b57cec5SDimitry Andric __lbinp = this->eback() - __p; 6330b57cec5SDimitry Andric __lninp = this->gptr() - __p; 6340b57cec5SDimitry Andric __leinp = this->egptr() - __p; 6350b57cec5SDimitry Andric } 6360b57cec5SDimitry Andric ptrdiff_t __lbout = -1; 6370b57cec5SDimitry Andric ptrdiff_t __lnout = -1; 6380b57cec5SDimitry Andric ptrdiff_t __leout = -1; 639cb14a3feSDimitry Andric if (this->pbase() != nullptr) { 6400b57cec5SDimitry Andric __lbout = this->pbase() - __p; 6410b57cec5SDimitry Andric __lnout = this->pptr() - __p; 6420b57cec5SDimitry Andric __leout = this->epptr() - __p; 6430b57cec5SDimitry Andric } 6440b57cec5SDimitry Andric ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; 6455f757f3fSDimitry Andric std::swap(__mode_, __rhs.__mode_); 6460b57cec5SDimitry Andric __str_.swap(__rhs.__str_); 6470b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 6480b57cec5SDimitry Andric if (__rbinp != -1) 6490b57cec5SDimitry Andric this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); 6500b57cec5SDimitry Andric else 6510b57cec5SDimitry Andric this->setg(nullptr, nullptr, nullptr); 652cb14a3feSDimitry Andric if (__rbout != -1) { 6530b57cec5SDimitry Andric this->setp(__p + __rbout, __p + __reout); 6540b57cec5SDimitry Andric this->__pbump(__rnout); 655cb14a3feSDimitry Andric } else 6560b57cec5SDimitry Andric this->setp(nullptr, nullptr); 6570b57cec5SDimitry Andric __hm_ = __rhm == -1 ? nullptr : __p + __rhm; 6580b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 6590b57cec5SDimitry Andric if (__lbinp != -1) 6600b57cec5SDimitry Andric __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); 6610b57cec5SDimitry Andric else 6620b57cec5SDimitry Andric __rhs.setg(nullptr, nullptr, nullptr); 663cb14a3feSDimitry Andric if (__lbout != -1) { 6640b57cec5SDimitry Andric __rhs.setp(__p + __lbout, __p + __leout); 6650b57cec5SDimitry Andric __rhs.__pbump(__lnout); 666cb14a3feSDimitry Andric } else 6670b57cec5SDimitry Andric __rhs.setp(nullptr, nullptr); 6680b57cec5SDimitry Andric __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; 6690b57cec5SDimitry Andric locale __tl = __rhs.getloc(); 6700b57cec5SDimitry Andric __rhs.pubimbue(this->getloc()); 6710b57cec5SDimitry Andric this->pubimbue(__tl); 6720b57cec5SDimitry Andric} 6730b57cec5SDimitry Andric 6740b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 675cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void 676cb14a3feSDimitry Andricswap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y) 67706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 67806c3fb27SDimitry Andric noexcept(noexcept(__x.swap(__y))) 67906c3fb27SDimitry Andric#endif 6800b57cec5SDimitry Andric{ 6810b57cec5SDimitry Andric __x.swap(__y); 6820b57cec5SDimitry Andric} 6830b57cec5SDimitry Andric 68406c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 6850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 686cb14a3feSDimitry Andricbasic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const { 68706c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 6880b57cec5SDimitry Andric if (__hm_ < this->pptr()) 6890b57cec5SDimitry Andric __hm_ = this->pptr(); 6900b57cec5SDimitry Andric return string_type(this->pbase(), __hm_, __str_.get_allocator()); 69106c3fb27SDimitry Andric } else if (__mode_ & ios_base::in) 6920b57cec5SDimitry Andric return string_type(this->eback(), this->egptr(), __str_.get_allocator()); 6930b57cec5SDimitry Andric return string_type(__str_.get_allocator()); 6940b57cec5SDimitry Andric} 69506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 6960b57cec5SDimitry Andric 6970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 69806c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { 699e8d8bef9SDimitry Andric __hm_ = nullptr; 70006c3fb27SDimitry Andric char_type* __data = const_cast<char_type*>(__str_.data()); 7010b57cec5SDimitry Andric typename string_type::size_type __sz = __str_.size(); 70206c3fb27SDimitry Andric if (__mode_ & ios_base::in) { 70306c3fb27SDimitry Andric __hm_ = __data + __sz; 70406c3fb27SDimitry Andric this->setg(__data, __data, __hm_); 70506c3fb27SDimitry Andric } 70606c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 70706c3fb27SDimitry Andric __hm_ = __data + __sz; 7080b57cec5SDimitry Andric __str_.resize(__str_.capacity()); 70906c3fb27SDimitry Andric this->setp(__data, __data + __str_.size()); 71006c3fb27SDimitry Andric if (__mode_ & (ios_base::app | ios_base::ate)) { 71106c3fb27SDimitry Andric while (__sz > INT_MAX) { 7120b57cec5SDimitry Andric this->pbump(INT_MAX); 7130b57cec5SDimitry Andric __sz -= INT_MAX; 7140b57cec5SDimitry Andric } 7150b57cec5SDimitry Andric if (__sz > 0) 7160b57cec5SDimitry Andric this->pbump(__sz); 7170b57cec5SDimitry Andric } 7180b57cec5SDimitry Andric } 7190b57cec5SDimitry Andric} 7200b57cec5SDimitry Andric 72106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 72206c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 72306c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits> 72406c3fb27SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept { 72506c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 72606c3fb27SDimitry Andric if (__hm_ < this->pptr()) 72706c3fb27SDimitry Andric __hm_ = this->pptr(); 72806c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_); 72906c3fb27SDimitry Andric } else if (__mode_ & ios_base::in) 73006c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr()); 73106c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(); 73206c3fb27SDimitry Andric} 73306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 73406c3fb27SDimitry Andric 7350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7360b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 737cb14a3feSDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::underflow() { 7380b57cec5SDimitry Andric if (__hm_ < this->pptr()) 7390b57cec5SDimitry Andric __hm_ = this->pptr(); 740cb14a3feSDimitry Andric if (__mode_ & ios_base::in) { 7410b57cec5SDimitry Andric if (this->egptr() < __hm_) 7420b57cec5SDimitry Andric this->setg(this->eback(), this->gptr(), __hm_); 7430b57cec5SDimitry Andric if (this->gptr() < this->egptr()) 7440b57cec5SDimitry Andric return traits_type::to_int_type(*this->gptr()); 7450b57cec5SDimitry Andric } 7460b57cec5SDimitry Andric return traits_type::eof(); 7470b57cec5SDimitry Andric} 7480b57cec5SDimitry Andric 7490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7500b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 751cb14a3feSDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) { 7520b57cec5SDimitry Andric if (__hm_ < this->pptr()) 7530b57cec5SDimitry Andric __hm_ = this->pptr(); 754cb14a3feSDimitry Andric if (this->eback() < this->gptr()) { 755cb14a3feSDimitry Andric if (traits_type::eq_int_type(__c, traits_type::eof())) { 7560b57cec5SDimitry Andric this->setg(this->eback(), this->gptr() - 1, __hm_); 7570b57cec5SDimitry Andric return traits_type::not_eof(__c); 7580b57cec5SDimitry Andric } 759cb14a3feSDimitry Andric if ((__mode_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { 7600b57cec5SDimitry Andric this->setg(this->eback(), this->gptr() - 1, __hm_); 7610b57cec5SDimitry Andric *this->gptr() = traits_type::to_char_type(__c); 7620b57cec5SDimitry Andric return __c; 7630b57cec5SDimitry Andric } 7640b57cec5SDimitry Andric } 7650b57cec5SDimitry Andric return traits_type::eof(); 7660b57cec5SDimitry Andric} 7670b57cec5SDimitry Andric 7680b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7690b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 770cb14a3feSDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) { 771cb14a3feSDimitry Andric if (!traits_type::eq_int_type(__c, traits_type::eof())) { 7720b57cec5SDimitry Andric ptrdiff_t __ninp = this->gptr() - this->eback(); 773cb14a3feSDimitry Andric if (this->pptr() == this->epptr()) { 7740b57cec5SDimitry Andric if (!(__mode_ & ios_base::out)) 7750b57cec5SDimitry Andric return traits_type::eof(); 77606c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 777cb14a3feSDimitry Andric try { 77806c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 7790b57cec5SDimitry Andric ptrdiff_t __nout = this->pptr() - this->pbase(); 7800b57cec5SDimitry Andric ptrdiff_t __hm = __hm_ - this->pbase(); 7810b57cec5SDimitry Andric __str_.push_back(char_type()); 7820b57cec5SDimitry Andric __str_.resize(__str_.capacity()); 7830b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__str_.data()); 7840b57cec5SDimitry Andric this->setp(__p, __p + __str_.size()); 7850b57cec5SDimitry Andric this->__pbump(__nout); 7860b57cec5SDimitry Andric __hm_ = this->pbase() + __hm; 78706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 788cb14a3feSDimitry Andric } catch (...) { 7890b57cec5SDimitry Andric return traits_type::eof(); 7900b57cec5SDimitry Andric } 79106c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 7920b57cec5SDimitry Andric } 7935f757f3fSDimitry Andric __hm_ = std::max(this->pptr() + 1, __hm_); 794cb14a3feSDimitry Andric if (__mode_ & ios_base::in) { 7950b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__str_.data()); 7960b57cec5SDimitry Andric this->setg(__p, __p + __ninp, __hm_); 7970b57cec5SDimitry Andric } 7980b57cec5SDimitry Andric return this->sputc(traits_type::to_char_type(__c)); 7990b57cec5SDimitry Andric } 8000b57cec5SDimitry Andric return traits_type::not_eof(__c); 8010b57cec5SDimitry Andric} 8020b57cec5SDimitry Andric 8030b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 804cb14a3feSDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff( 805cb14a3feSDimitry Andric off_type __off, ios_base::seekdir __way, ios_base::openmode __wch) { 8060b57cec5SDimitry Andric if (__hm_ < this->pptr()) 8070b57cec5SDimitry Andric __hm_ = this->pptr(); 8080b57cec5SDimitry Andric if ((__wch & (ios_base::in | ios_base::out)) == 0) 8090b57cec5SDimitry Andric return pos_type(-1); 810cb14a3feSDimitry Andric if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur) 8110b57cec5SDimitry Andric return pos_type(-1); 8120b57cec5SDimitry Andric const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); 8130b57cec5SDimitry Andric off_type __noff; 814cb14a3feSDimitry Andric switch (__way) { 8150b57cec5SDimitry Andric case ios_base::beg: 8160b57cec5SDimitry Andric __noff = 0; 8170b57cec5SDimitry Andric break; 8180b57cec5SDimitry Andric case ios_base::cur: 8190b57cec5SDimitry Andric if (__wch & ios_base::in) 8200b57cec5SDimitry Andric __noff = this->gptr() - this->eback(); 8210b57cec5SDimitry Andric else 8220b57cec5SDimitry Andric __noff = this->pptr() - this->pbase(); 8230b57cec5SDimitry Andric break; 8240b57cec5SDimitry Andric case ios_base::end: 8250b57cec5SDimitry Andric __noff = __hm; 8260b57cec5SDimitry Andric break; 8270b57cec5SDimitry Andric default: 8280b57cec5SDimitry Andric return pos_type(-1); 8290b57cec5SDimitry Andric } 8300b57cec5SDimitry Andric __noff += __off; 8310b57cec5SDimitry Andric if (__noff < 0 || __hm < __noff) 8320b57cec5SDimitry Andric return pos_type(-1); 833cb14a3feSDimitry Andric if (__noff != 0) { 834e8d8bef9SDimitry Andric if ((__wch & ios_base::in) && this->gptr() == nullptr) 8350b57cec5SDimitry Andric return pos_type(-1); 836e8d8bef9SDimitry Andric if ((__wch & ios_base::out) && this->pptr() == nullptr) 8370b57cec5SDimitry Andric return pos_type(-1); 8380b57cec5SDimitry Andric } 8390b57cec5SDimitry Andric if (__wch & ios_base::in) 8400b57cec5SDimitry Andric this->setg(this->eback(), this->eback() + __noff, __hm_); 841cb14a3feSDimitry Andric if (__wch & ios_base::out) { 8420b57cec5SDimitry Andric this->setp(this->pbase(), this->epptr()); 84306c3fb27SDimitry Andric this->__pbump(__noff); 8440b57cec5SDimitry Andric } 8450b57cec5SDimitry Andric return pos_type(__noff); 8460b57cec5SDimitry Andric} 8470b57cec5SDimitry Andric 848bdd1243dSDimitry Andric// Class template basic_istringstream [istringstream] 8490b57cec5SDimitry Andric 8500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 851cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_istringstream : public basic_istream<_CharT, _Traits> { 8520b57cec5SDimitry Andricpublic: 8530b57cec5SDimitry Andric typedef _CharT char_type; 8540b57cec5SDimitry Andric typedef _Traits traits_type; 8550b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 8560b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 8570b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 8580b57cec5SDimitry Andric typedef _Allocator allocator_type; 8590b57cec5SDimitry Andric 8600b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 8610b57cec5SDimitry Andric 8620b57cec5SDimitry Andricprivate: 8630b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 8640b57cec5SDimitry Andric 8650b57cec5SDimitry Andricpublic: 866bdd1243dSDimitry Andric // [istringstream.cons] Constructors: 867cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream() : basic_istream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in) {} 868e8d8bef9SDimitry Andric 869cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch) 870e8d8bef9SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {} 871e8d8bef9SDimitry Andric 872cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in) 873cb14a3feSDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::in) {} 8740b57cec5SDimitry Andric 87506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 87606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) 87706c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {} 87806c3fb27SDimitry Andric 87906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in) 88006c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {} 88106c3fb27SDimitry Andric 88206c3fb27SDimitry Andric template <class _SAlloc> 88306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 88406c3fb27SDimitry Andric : basic_istringstream(__s, ios_base::in, __a) {} 88506c3fb27SDimitry Andric 88606c3fb27SDimitry Andric template <class _SAlloc> 88706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream( 88806c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 88906c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {} 89006c3fb27SDimitry Andric 89106c3fb27SDimitry Andric template <class _SAlloc> 89206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 89306c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in) 89406c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} 89506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 89606c3fb27SDimitry Andric 897*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 898*0fca6ea1SDimitry Andric 899*0fca6ea1SDimitry Andric template <class _Tp> 900*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 901*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in) 902*0fca6ea1SDimitry Andric : basic_istringstream(__t, __which, _Allocator()) {} 903*0fca6ea1SDimitry Andric 904*0fca6ea1SDimitry Andric template <class _Tp> 905*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 906*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a) 907*0fca6ea1SDimitry Andric : basic_istringstream(__t, ios_base::in, __a) {} 908*0fca6ea1SDimitry Andric 909*0fca6ea1SDimitry Andric template <class _Tp> 910*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 911*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) 912*0fca6ea1SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {} 913*0fca6ea1SDimitry Andric 914*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 915*0fca6ea1SDimitry Andric 916*0fca6ea1SDimitry Andric basic_istringstream(const basic_istringstream&) = delete; 917cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs) 918cb14a3feSDimitry Andric : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { 9190b57cec5SDimitry Andric basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 9200b57cec5SDimitry Andric } 9210b57cec5SDimitry Andric 922bdd1243dSDimitry Andric // [istringstream.assign] Assign and swap: 923*0fca6ea1SDimitry Andric basic_istringstream& operator=(const basic_istringstream&) = delete; 924e8d8bef9SDimitry Andric basic_istringstream& operator=(basic_istringstream&& __rhs) { 9255f757f3fSDimitry Andric basic_istream<char_type, traits_type>::operator=(std::move(__rhs)); 9265f757f3fSDimitry Andric __sb_ = std::move(__rhs.__sb_); 9270b57cec5SDimitry Andric return *this; 9280b57cec5SDimitry Andric } 929cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI void swap(basic_istringstream& __rhs) { 9300b57cec5SDimitry Andric basic_istream<char_type, traits_type>::swap(__rhs); 9310b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 9320b57cec5SDimitry Andric } 9330b57cec5SDimitry Andric 934bdd1243dSDimitry Andric // [istringstream.members] Member functions: 935cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 936e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 937e8d8bef9SDimitry Andric } 93806c3fb27SDimitry Andric 9398a4dda33SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 9408a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 9418a4dda33SDimitry Andric#else 942*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } 94306c3fb27SDimitry Andric 944*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } 9458a4dda33SDimitry Andric#endif 9468a4dda33SDimitry Andric 9478a4dda33SDimitry Andric#if _LIBCPP_STD_VER >= 20 94806c3fb27SDimitry Andric template <class _SAlloc> 94906c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 95006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 95106c3fb27SDimitry Andric return __sb_.str(__sa); 952e8d8bef9SDimitry Andric } 95306c3fb27SDimitry Andric 95406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 95506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 95606c3fb27SDimitry Andric 95706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 95806c3fb27SDimitry Andric 95906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 96006c3fb27SDimitry Andric template <class _SAlloc> 96106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 962e8d8bef9SDimitry Andric __sb_.str(__s); 963e8d8bef9SDimitry Andric } 96406c3fb27SDimitry Andric 96506c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 96606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 967*0fca6ea1SDimitry Andric 968*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 969*0fca6ea1SDimitry Andric template <class _Tp> 970*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 971*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { 972*0fca6ea1SDimitry Andric rdbuf()->str(__t); 973*0fca6ea1SDimitry Andric } 974*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 975e8d8bef9SDimitry Andric}; 976e8d8bef9SDimitry Andric 9770b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 978cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void 979cb14a3feSDimitry Andricswap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<_CharT, _Traits, _Allocator>& __y) { 9800b57cec5SDimitry Andric __x.swap(__y); 9810b57cec5SDimitry Andric} 9820b57cec5SDimitry Andric 983bdd1243dSDimitry Andric// Class template basic_ostringstream [ostringstream] 9840b57cec5SDimitry Andric 9850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 986cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_ostringstream : public basic_ostream<_CharT, _Traits> { 9870b57cec5SDimitry Andricpublic: 9880b57cec5SDimitry Andric typedef _CharT char_type; 9890b57cec5SDimitry Andric typedef _Traits traits_type; 9900b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 9910b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 9920b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 9930b57cec5SDimitry Andric typedef _Allocator allocator_type; 9940b57cec5SDimitry Andric 9950b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 9960b57cec5SDimitry Andric 9970b57cec5SDimitry Andricprivate: 9980b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 9990b57cec5SDimitry Andric 10000b57cec5SDimitry Andricpublic: 1001bdd1243dSDimitry Andric // [ostringstream.cons] Constructors: 1002cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream() : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::out) {} 1003e8d8bef9SDimitry Andric 1004cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch) 1005fe6060f1SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out) {} 1006e8d8bef9SDimitry Andric 1007cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out) 1008cb14a3feSDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch | ios_base::out) {} 10090b57cec5SDimitry Andric 101006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 101106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) 101206c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {} 101306c3fb27SDimitry Andric 101406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out) 101506c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {} 101606c3fb27SDimitry Andric 101706c3fb27SDimitry Andric template <class _SAlloc> 101806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 101906c3fb27SDimitry Andric : basic_ostringstream(__s, ios_base::out, __a) {} 102006c3fb27SDimitry Andric 102106c3fb27SDimitry Andric template <class _SAlloc> 102206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream( 102306c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 102406c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {} 102506c3fb27SDimitry Andric 102606c3fb27SDimitry Andric template <class _SAlloc> 102706c3fb27SDimitry Andric requires(!is_same_v<_SAlloc, allocator_type>) 102806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 102906c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::out) 103006c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} 103106c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 103206c3fb27SDimitry Andric 1033*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 1034*0fca6ea1SDimitry Andric 1035*0fca6ea1SDimitry Andric template <class _Tp> 1036*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1037*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out) 1038*0fca6ea1SDimitry Andric : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {} 1039*0fca6ea1SDimitry Andric 1040*0fca6ea1SDimitry Andric template <class _Tp> 1041*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1042*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a) 1043*0fca6ea1SDimitry Andric : basic_ostringstream(__t, ios_base::out, __a) {} 1044*0fca6ea1SDimitry Andric 1045*0fca6ea1SDimitry Andric template <class _Tp> 1046*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1047*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) 1048*0fca6ea1SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {} 1049*0fca6ea1SDimitry Andric 1050*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 1051*0fca6ea1SDimitry Andric 1052*0fca6ea1SDimitry Andric basic_ostringstream(const basic_ostringstream&) = delete; 1053cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs) 1054cb14a3feSDimitry Andric : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { 10550b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); 10560b57cec5SDimitry Andric } 10570b57cec5SDimitry Andric 1058bdd1243dSDimitry Andric // [ostringstream.assign] Assign and swap: 1059*0fca6ea1SDimitry Andric basic_ostringstream& operator=(const basic_ostringstream&) = delete; 1060e8d8bef9SDimitry Andric basic_ostringstream& operator=(basic_ostringstream&& __rhs) { 10615f757f3fSDimitry Andric basic_ostream<char_type, traits_type>::operator=(std::move(__rhs)); 10625f757f3fSDimitry Andric __sb_ = std::move(__rhs.__sb_); 10630b57cec5SDimitry Andric return *this; 10640b57cec5SDimitry Andric } 10650b57cec5SDimitry Andric 1066cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI void swap(basic_ostringstream& __rhs) { 10670b57cec5SDimitry Andric basic_ostream<char_type, traits_type>::swap(__rhs); 10680b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 10690b57cec5SDimitry Andric } 10700b57cec5SDimitry Andric 1071bdd1243dSDimitry Andric // [ostringstream.members] Member functions: 1072cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 1073e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 1074e8d8bef9SDimitry Andric } 107506c3fb27SDimitry Andric 10768a4dda33SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 10778a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 10788a4dda33SDimitry Andric#else 1079*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } 108006c3fb27SDimitry Andric 1081*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } 10828a4dda33SDimitry Andric#endif 10838a4dda33SDimitry Andric 10848a4dda33SDimitry Andric#if _LIBCPP_STD_VER >= 20 108506c3fb27SDimitry Andric template <class _SAlloc> 108606c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 108706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 108806c3fb27SDimitry Andric return __sb_.str(__sa); 1089e8d8bef9SDimitry Andric } 109006c3fb27SDimitry Andric 109106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 109206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 109306c3fb27SDimitry Andric 109406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 109506c3fb27SDimitry Andric 109606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 109706c3fb27SDimitry Andric template <class _SAlloc> 109806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 1099e8d8bef9SDimitry Andric __sb_.str(__s); 1100e8d8bef9SDimitry Andric } 110106c3fb27SDimitry Andric 110206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 110306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1104*0fca6ea1SDimitry Andric 1105*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 1106*0fca6ea1SDimitry Andric template <class _Tp> 1107*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1108*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { 1109*0fca6ea1SDimitry Andric rdbuf()->str(__t); 1110*0fca6ea1SDimitry Andric } 1111*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 1112e8d8bef9SDimitry Andric}; 1113e8d8bef9SDimitry Andric 11140b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 1115cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void 1116cb14a3feSDimitry Andricswap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<_CharT, _Traits, _Allocator>& __y) { 11170b57cec5SDimitry Andric __x.swap(__y); 11180b57cec5SDimitry Andric} 11190b57cec5SDimitry Andric 1120bdd1243dSDimitry Andric// Class template basic_stringstream [stringstream] 11210b57cec5SDimitry Andric 11220b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 1123cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_stringstream : public basic_iostream<_CharT, _Traits> { 11240b57cec5SDimitry Andricpublic: 11250b57cec5SDimitry Andric typedef _CharT char_type; 11260b57cec5SDimitry Andric typedef _Traits traits_type; 11270b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 11280b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 11290b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 11300b57cec5SDimitry Andric typedef _Allocator allocator_type; 11310b57cec5SDimitry Andric 11320b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 11330b57cec5SDimitry Andric 11340b57cec5SDimitry Andricprivate: 11350b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andricpublic: 1138bdd1243dSDimitry Andric // [stringstream.cons] constructors 1139cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream() 1140fe6060f1SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in | ios_base::out) {} 1141e8d8bef9SDimitry Andric 1142cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch) 1143e8d8bef9SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {} 1144e8d8bef9SDimitry Andric 1145cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s, 1146e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 1147cb14a3feSDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__s, __wch) {} 11480b57cec5SDimitry Andric 114906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 115006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a) 115106c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {} 115206c3fb27SDimitry Andric 1153cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, 1154cb14a3feSDimitry Andric ios_base::openmode __wch = ios_base::out | ios_base::in) 115506c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {} 115606c3fb27SDimitry Andric 115706c3fb27SDimitry Andric template <class _SAlloc> 115806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 115906c3fb27SDimitry Andric : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {} 116006c3fb27SDimitry Andric 116106c3fb27SDimitry Andric template <class _SAlloc> 1162cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1163cb14a3feSDimitry Andric basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 116406c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {} 116506c3fb27SDimitry Andric 116606c3fb27SDimitry Andric template <class _SAlloc> 116706c3fb27SDimitry Andric requires(!is_same_v<_SAlloc, allocator_type>) 116806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 116906c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::out | ios_base::in) 117006c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} 117106c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 117206c3fb27SDimitry Andric 1173*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 1174*0fca6ea1SDimitry Andric 1175*0fca6ea1SDimitry Andric template <class _Tp> 1176*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1177*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t, 1178*0fca6ea1SDimitry Andric ios_base::openmode __which = ios_base::out | ios_base::in) 1179*0fca6ea1SDimitry Andric : basic_stringstream(__t, __which, _Allocator()) {} 1180*0fca6ea1SDimitry Andric 1181*0fca6ea1SDimitry Andric template <class _Tp> 1182*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1183*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, const _Allocator& __a) 1184*0fca6ea1SDimitry Andric : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {} 1185*0fca6ea1SDimitry Andric 1186*0fca6ea1SDimitry Andric template <class _Tp> 1187*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1188*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a) 1189*0fca6ea1SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {} 1190*0fca6ea1SDimitry Andric 1191*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 1192*0fca6ea1SDimitry Andric 1193*0fca6ea1SDimitry Andric basic_stringstream(const basic_stringstream&) = delete; 1194cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs) 1195cb14a3feSDimitry Andric : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { 11960b57cec5SDimitry Andric basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 11970b57cec5SDimitry Andric } 11980b57cec5SDimitry Andric 1199bdd1243dSDimitry Andric // [stringstream.assign] Assign and swap: 1200*0fca6ea1SDimitry Andric basic_stringstream& operator=(const basic_stringstream&) = delete; 1201e8d8bef9SDimitry Andric basic_stringstream& operator=(basic_stringstream&& __rhs) { 12025f757f3fSDimitry Andric basic_iostream<char_type, traits_type>::operator=(std::move(__rhs)); 12035f757f3fSDimitry Andric __sb_ = std::move(__rhs.__sb_); 12040b57cec5SDimitry Andric return *this; 12050b57cec5SDimitry Andric } 1206cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI void swap(basic_stringstream& __rhs) { 12070b57cec5SDimitry Andric basic_iostream<char_type, traits_type>::swap(__rhs); 12080b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 12090b57cec5SDimitry Andric } 12100b57cec5SDimitry Andric 1211bdd1243dSDimitry Andric // [stringstream.members] Member functions: 1212cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 1213e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 1214e8d8bef9SDimitry Andric } 121506c3fb27SDimitry Andric 12168a4dda33SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 12178a4dda33SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 12188a4dda33SDimitry Andric#else 1219*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); } 122006c3fb27SDimitry Andric 1221*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } 12228a4dda33SDimitry Andric#endif 12238a4dda33SDimitry Andric 12248a4dda33SDimitry Andric#if _LIBCPP_STD_VER >= 20 122506c3fb27SDimitry Andric template <class _SAlloc> 122606c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 122706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 122806c3fb27SDimitry Andric return __sb_.str(__sa); 1229e8d8bef9SDimitry Andric } 123006c3fb27SDimitry Andric 123106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 123206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 123306c3fb27SDimitry Andric 123406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 123506c3fb27SDimitry Andric 123606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 123706c3fb27SDimitry Andric template <class _SAlloc> 123806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 1239e8d8bef9SDimitry Andric __sb_.str(__s); 1240e8d8bef9SDimitry Andric } 124106c3fb27SDimitry Andric 124206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 124306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1244*0fca6ea1SDimitry Andric 1245*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 26 1246*0fca6ea1SDimitry Andric template <class _Tp> 1247*0fca6ea1SDimitry Andric requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>> 1248*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) { 1249*0fca6ea1SDimitry Andric rdbuf()->str(__t); 1250*0fca6ea1SDimitry Andric } 1251*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 26 1252e8d8bef9SDimitry Andric}; 1253e8d8bef9SDimitry Andric 12540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 1255cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void 1256cb14a3feSDimitry Andricswap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_CharT, _Traits, _Allocator>& __y) { 12570b57cec5SDimitry Andric __x.swap(__y); 12580b57cec5SDimitry Andric} 12590b57cec5SDimitry Andric 12605f757f3fSDimitry Andric#if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 126181ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>; 126281ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>; 126381ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>; 126481ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>; 1265e8d8bef9SDimitry Andric#endif 12660b57cec5SDimitry Andric 12670b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 12680b57cec5SDimitry Andric 12690b57cec5SDimitry Andric_LIBCPP_POP_MACROS 12700b57cec5SDimitry Andric 12717a6dacacSDimitry Andric#if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) 1272*0fca6ea1SDimitry Andric# include <ostream> 1273bdd1243dSDimitry Andric# include <type_traits> 1274bdd1243dSDimitry Andric#endif 1275bdd1243dSDimitry Andric 12760b57cec5SDimitry Andric#endif // _LIBCPP_SSTREAM 1277