• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SSTREAM
11#define _LIBCPP_SSTREAM
12
13// clang-format off
14
15/*
16    sstream synopsis [sstream.syn]
17
18// Class template basic_stringbuf [stringbuf]
19template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
20class basic_stringbuf
21    : public basic_streambuf<charT, traits>
22{
23public:
24    typedef charT                          char_type;
25    typedef traits                         traits_type;
26    typedef typename traits_type::int_type int_type;
27    typedef typename traits_type::pos_type pos_type;
28    typedef typename traits_type::off_type off_type;
29    typedef Allocator                      allocator_type;
30
31    // [stringbuf.cons] constructors:
32    explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20
33    basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {}               // C++20
34    explicit basic_stringbuf(ios_base::openmode which);                                // C++20
35    explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& s,
36                             ios_base::openmode which = ios_base::in | ios_base::out);
37    explicit basic_stringbuf(const allocator_type& a)
38        : basic_stringbuf(ios_base::in | ios_base::out, a) {}                          // C++20
39    basic_stringbuf(ios_base::openmode which, const allocator_type& a);                // C++20
40    explicit basic_stringbuf(basic_string<char_type, traits_type, allocator_type>&& s,
41                             ios_base::openmode which = ios_base::in | ios_base::out); // C++20
42    template <class SAlloc>
43    basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
44        : basic_stringbuf(s, ios_base::in | ios_base::out, a) {}                       // C++20
45    template <class SAlloc>
46    basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
47                    ios_base::openmode which, const allocator_type& a);                // C++20
48    template <class SAlloc>
49    explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s,
50                             ios_base::openmode which = ios_base::in | ios_base::out); // C++20
51    template<class T>
52      explicit basic_stringbuf(const T& t,
53                               ios_base::openmode which = ios_base::in | ios_base::out); // Since C++26
54    template<class T>
55      basic_stringbuf(const T& t, const Allocator& a);                                   // Since C++26
56    template<class T>
57      basic_stringbuf(const T& t, ios_base::openmode which, const Allocator& a);         // Since C++26
58    basic_stringbuf(const basic_stringbuf&) = delete;
59    basic_stringbuf(basic_stringbuf&& rhs);
60    basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a);                   // C++20
61
62    // [stringbuf.assign] Assign and swap:
63    basic_stringbuf& operator=(const basic_stringbuf&) = delete;
64    basic_stringbuf& operator=(basic_stringbuf&& rhs);
65    void swap(basic_stringbuf& rhs) noexcept(see below);                               // conditionally noexcept since C++20
66
67    // [stringbuf.members] Member functions:
68    allocator_type get_allocator() const noexcept;                                     // C++20
69    basic_string<char_type, traits_type, allocator_type> str() const;                  // before C++20
70    basic_string<char_type, traits_type, allocator_type> str() const &;                // C++20
71    template <class SAlloc>
72    basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const;          // C++20
73    basic_string<char_type, traits_type, allocator_type> str() &&;                     // C++20
74    basic_string_view<char_type, traits_type> view() const noexcept;                   // C++20
75    void str(const basic_string<char_type, traits_type, allocator_type>& s);
76    template <class SAlloc>
77    void str(const basic_string<char_type, traits_type, SAlloc>& s);                   // C++20
78    void str(basic_string<char_type, traits_type, allocator_type>&& s);                // C++20
79    template<class T>
80      void str(const T& t);                                                            // Since C++26
81
82protected:
83    // [stringbuf.virtuals] Overridden virtual functions:
84    virtual int_type underflow();
85    virtual int_type pbackfail(int_type c = traits_type::eof());
86    virtual int_type overflow (int_type c = traits_type::eof());
87    virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize);
88    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
89                             ios_base::openmode which = ios_base::in | ios_base::out);
90    virtual pos_type seekpos(pos_type sp,
91                             ios_base::openmode which = ios_base::in | ios_base::out);
92};
93
94// [stringbuf.assign] non member swap
95template <class charT, class traits, class Allocator>
96void swap(basic_stringbuf<charT, traits, Allocator>& x,
97          basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20
98
99typedef basic_stringbuf<char>    stringbuf;
100typedef basic_stringbuf<wchar_t> wstringbuf;
101
102// Class template basic_istringstream [istringstream]
103template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
104class basic_istringstream
105    : public basic_istream<charT, traits>
106{
107public:
108    typedef charT                          char_type;
109    typedef traits                         traits_type;
110    typedef typename traits_type::int_type int_type;
111    typedef typename traits_type::pos_type pos_type;
112    typedef typename traits_type::off_type off_type;
113    typedef Allocator                      allocator_type;
114
115    // [istringstream.cons] Constructors:
116    explicit basic_istringstream(ios_base::openmode which = ios_base::in);             // before C++20
117    basic_istringstream() : basic_istringstream(ios_base::in) {}                       // C++20
118    explicit basic_istringstream(ios_base::openmode which);                            // C++20
119    explicit basic_istringstream(const basic_string<char_type, traits_type, allocator_type>& s,
120                                 ios_base::openmode which = ios_base::in);
121    basic_istringstream(ios_base::openmode which, const allocator_type& a);            // C++20
122    explicit basic_istringstream(basic_string<char_type, traits_type, allocator_type>&& s,
123                                 ios_base::openmode which = ios_base::in);             // C++20
124    template <class SAlloc>
125    basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
126        : basic_istringstream(s, ios_base::in, a) {}                                   // C++20
127    template <class SAlloc>
128    basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
129                        ios_base::openmode which, const allocator_type& a);            // C++20
130    template <class SAlloc>
131    explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s,
132                                 ios_base::openmode which = ios_base::in);             // C++20
133    template<class T>
134      explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); // Since C++26
135    template<class T>
136      basic_istringstream(const T& t, const Allocator& a);                               // Since C++26
137    template<class T>
138      basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);     // Since C++26
139    basic_istringstream(const basic_istringstream&) = delete;
140    basic_istringstream(basic_istringstream&& rhs);
141
142    // [istringstream.assign] Assign and swap:
143    basic_istringstream& operator=(const basic_istringstream&) = delete;
144    basic_istringstream& operator=(basic_istringstream&& rhs);
145    void swap(basic_istringstream& rhs);
146
147    // [istringstream.members] Member functions:
148    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
149    basic_string<char_type, traits_type, allocator_type> str() const;                  // before C++20
150    basic_string<char_type, traits_type, allocator_type> str() const &;                // C++20
151    template <class SAlloc>
152    basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const;          // C++20
153    basic_string<char_type, traits_type, allocator_type> str() &&;                     // C++20
154    basic_string_view<char_type, traits_type> view() const noexcept;                   // C++20
155    void str(const basic_string<char_type, traits_type, allocator_type>& s);
156    template <class SAlloc>
157    void str(const basic_string<char_type, traits_type, SAlloc>& s);                   // C++20
158    void str(basic_string<char_type, traits_type, allocator_type>&& s);                // C++20
159    template<class T>
160      void str(const T& t);                                                            // Since C++26
161};
162
163template <class charT, class traits, class Allocator>
164void swap(basic_istringstream<charT, traits, Allocator>& x,
165          basic_istringstream<charT, traits, Allocator>& y);
166
167typedef basic_istringstream<char>    istringstream;
168typedef basic_istringstream<wchar_t> wistringstream;
169
170// Class template basic_ostringstream [ostringstream]
171template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
172class basic_ostringstream
173    : public basic_ostream<charT, traits>
174{
175public:
176    // types:
177    typedef charT                          char_type;
178    typedef traits                         traits_type;
179    typedef typename traits_type::int_type int_type;
180    typedef typename traits_type::pos_type pos_type;
181    typedef typename traits_type::off_type off_type;
182    typedef Allocator                      allocator_type;
183
184    // [ostringstream.cons] Constructors:
185    explicit basic_ostringstream(ios_base::openmode which = ios_base::out);            // before C++20
186    basic_ostringstream() : basic_ostringstream(ios_base::out) {}                      // C++20
187    explicit basic_ostringstream(ios_base::openmode which);                            // C++20
188    explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& s,
189                                 ios_base::openmode which = ios_base::out);
190    basic_ostringstream(ios_base::openmode which, const allocator_type& a);            // C++20
191    explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s,
192                                 ios_base::openmode which = ios_base::out);            // C++20
193    template <class SAlloc>
194    basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
195        : basic_ostringstream(s, ios_base::out, a) {}                                  // C++20
196    template <class SAlloc>
197    basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
198                        ios_base::openmode which, const allocator_type& a);            // C++20
199    template <class SAlloc>
200    explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s,
201                                 ios_base::openmode which = ios_base::out);            // C++20
202    template<class T>
203      explicit basic_ostringstream(const T& t, ios_base::openmode which = ios_base::out); // Since C++26
204    template<class T>
205      basic_ostringstream(const T& t, const Allocator& a);                                // Since C++26
206    template<class T>
207      basic_ostringstream(const T& t, ios_base::openmode which, const Allocator& a);      // Since C++26
208    basic_ostringstream(const basic_ostringstream&) = delete;
209    basic_ostringstream(basic_ostringstream&& rhs);
210
211    // [ostringstream.assign] Assign and swap:
212    basic_ostringstream& operator=(const basic_ostringstream&) = delete;
213    basic_ostringstream& operator=(basic_ostringstream&& rhs);
214    void swap(basic_ostringstream& rhs);
215
216    // [ostringstream.members] Member functions:
217    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
218    basic_string<char_type, traits_type, allocator_type> str() const;                  // before C++20
219    basic_string<char_type, traits_type, allocator_type> str() const &;                // C++20
220    template <class SAlloc>
221    basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const;          // C++20
222    basic_string<char_type, traits_type, allocator_type> str() &&;                     // C++20
223    basic_string_view<char_type, traits_type> view() const noexcept;                   // C++20
224    void str(const basic_string<char_type, traits_type, allocator_type>& s);
225    template <class SAlloc>
226    void str(const basic_string<char_type, traits_type, SAlloc>& s);                   // C++20
227    void str(basic_string<char_type, traits_type, allocator_type>&& s);                // C++20
228    template<class T>
229      void str(const T& t);                                                            // Since C++26
230};
231
232template <class charT, class traits, class Allocator>
233void swap(basic_ostringstream<charT, traits, Allocator>& x,
234          basic_ostringstream<charT, traits, Allocator>& y);
235
236typedef basic_ostringstream<char>    ostringstream;
237typedef basic_ostringstream<wchar_t> wostringstream;
238
239// Class template basic_stringstream [stringstream]
240template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
241class basic_stringstream
242    : public basic_iostream<charT, traits>
243{
244public:
245    // types:
246    typedef charT                          char_type;
247    typedef traits                         traits_type;
248    typedef typename traits_type::int_type int_type;
249    typedef typename traits_type::pos_type pos_type;
250    typedef typename traits_type::off_type off_type;
251    typedef Allocator                      allocator_type;
252
253    // [stringstream.cons] constructors
254    explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20
255    basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {}            // C++20
256    explicit basic_stringstream(ios_base::openmode which);                                // C++20
257    explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s,
258                                ios_base::openmode which = ios_base::out | ios_base::in);
259    basic_stringstream(ios_base::openmode which, const allocator_type& a);                // C++20
260    explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s,
261                                ios_base::openmode which = ios_base::out | ios_base::in); // C++20
262    template <class SAlloc>
263    basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a)
264        : basic_stringstream(s, ios_base::out | ios_base::in, a) {}                       // C++20
265    template <class SAlloc>
266    basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
267                       ios_base::openmode which, const allocator_type& a);                // C++20
268    template <class SAlloc>
269    explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s,
270                                ios_base::openmode which = ios_base::out | ios_base::in); // C++20
271    template<class T>
272      explicit basic_stringstream(const T& t,
273                                  ios_base::openmode which = ios_base::out | ios_base::in); // Since C++26
274    template<class T>
275      basic_stringstream(const T& t, const Allocator& a);                                   // Since C++26
276    template<class T>
277      basic_stringstream(const T& t, ios_base::openmode which, const Allocator& a);         // Since C++26
278    basic_stringstream(const basic_stringstream&) = delete;
279    basic_stringstream(basic_stringstream&& rhs);
280
281    // [stringstream.assign] Assign and swap:
282    basic_stringstream& operator=(const basic_stringstream&) = delete;
283    basic_stringstream& operator=(basic_stringstream&& rhs);
284    void swap(basic_stringstream& rhs);
285
286    // [stringstream.members] Member functions:
287    basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
288    basic_string<char_type, traits_type, allocator_type> str() const;                     // before C++20
289    basic_string<char_type, traits_type, allocator_type> str() const &;                   // C++20
290    template <class SAlloc>
291    basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const;             // C++20
292    basic_string<char_type, traits_type, allocator_type> str() &&;                        // C++20
293    basic_string_view<char_type, traits_type> view() const noexcept;                      // C++20
294    void str(const basic_string<char_type, traits_type, allocator_type>& s);
295    template <class SAlloc>
296    void str(const basic_string<char_type, traits_type, SAlloc>& s);                      // C++20
297    void str(basic_string<char_type, traits_type, allocator_type>&& s);                   // C++20
298    template<class T>
299      void str(const T& t);                                                               // Since C++26
300};
301
302template <class charT, class traits, class Allocator>
303void swap(basic_stringstream<charT, traits, Allocator>& x,
304          basic_stringstream<charT, traits, Allocator>& y);
305
306typedef basic_stringstream<char>    stringstream;
307typedef basic_stringstream<wchar_t> wstringstream;
308
309}  // std
310
311*/
312
313// clang-format on
314
315#include <__config>
316#include <__fwd/sstream.h>
317#include <__ostream/basic_ostream.h>
318#include <__type_traits/is_convertible.h>
319#include <__utility/swap.h>
320#include <istream>
321#include <string>
322#include <string_view>
323#include <version>
324
325#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
326#  pragma GCC system_header
327#endif
328
329_LIBCPP_PUSH_MACROS
330#include <__undef_macros>
331
332_LIBCPP_BEGIN_NAMESPACE_STD
333
334// Class template basic_stringbuf [stringbuf]
335
336template <class _CharT, class _Traits, class _Allocator>
337class _LIBCPP_TEMPLATE_VIS basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
338public:
339  typedef _CharT char_type;
340  typedef _Traits traits_type;
341  typedef typename traits_type::int_type int_type;
342  typedef typename traits_type::pos_type pos_type;
343  typedef typename traits_type::off_type off_type;
344  typedef _Allocator allocator_type;
345
346  typedef basic_string<char_type, traits_type, allocator_type> string_type;
347
348private:
349  string_type __str_;
350  mutable char_type* __hm_;
351  ios_base::openmode __mode_;
352  _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs();
353  _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs);
354
355public:
356  // [stringbuf.cons] constructors:
357  _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {
358    // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
359    __init_buf_ptrs();
360  }
361
362  _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) {
363    // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
364    __init_buf_ptrs();
365  }
366
367  _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s,
368                                                 ios_base::openmode __wch = ios_base::in | ios_base::out)
369      : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) {
370    str(__s);
371  }
372
373#if _LIBCPP_STD_VER >= 20
374  _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a)
375      : basic_stringbuf(ios_base::in | ios_base::out, __a) {}
376
377  _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a)
378      : __str_(__a), __hm_(nullptr), __mode_(__wch) {
379    __init_buf_ptrs();
380  }
381
382  _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s,
383                                                 ios_base::openmode __wch = ios_base::in | ios_base::out)
384      : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) {
385    __init_buf_ptrs();
386  }
387
388  template <class _SAlloc>
389  _LIBCPP_HIDE_FROM_ABI
390  basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a)
391      : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {}
392
393  template <class _SAlloc>
394  _LIBCPP_HIDE_FROM_ABI basic_stringbuf(
395      const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a)
396      : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) {
397    __init_buf_ptrs();
398  }
399
400  template <class _SAlloc>
401    requires(!is_same_v<_SAlloc, allocator_type>)
402  _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s,
403                                                 ios_base::openmode __wch = ios_base::in | ios_base::out)
404      : __str_(__s), __hm_(nullptr), __mode_(__wch) {
405    __init_buf_ptrs();
406  }
407#endif // _LIBCPP_STD_VER >= 20
408
409#if _LIBCPP_STD_VER >= 26
410
411  template <class _Tp>
412    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
413  _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t,
414                                                 ios_base::openmode __which = ios_base::in | ios_base::out)
415      : basic_stringbuf(__t, __which, _Allocator()) {}
416
417  template <class _Tp>
418    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
419  _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a)
420      : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {}
421
422  template <class _Tp>
423    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
424  _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
425      : __hm_(nullptr), __mode_(__which) {
426    basic_string_view<_CharT, _Traits> __sv = __t;
427    __str_                                  = string_type(__sv, __a);
428    __init_buf_ptrs();
429  }
430
431#endif //  _LIBCPP_STD_VER >= 26
432
433  basic_stringbuf(const basic_stringbuf&) = delete;
434  basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); }
435
436#if _LIBCPP_STD_VER >= 20
437  _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a)
438      : basic_stringbuf(__rhs.__mode_, __a) {
439    __move_init(std::move(__rhs));
440  }
441#endif
442
443  // [stringbuf.assign] Assign and swap:
444  basic_stringbuf& operator=(const basic_stringbuf&) = delete;
445  basic_stringbuf& operator=(basic_stringbuf&& __rhs);
446  void swap(basic_stringbuf& __rhs)
447#if _LIBCPP_STD_VER >= 20
448      noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
449               allocator_traits<allocator_type>::is_always_equal::value)
450#endif
451          ;
452
453  // [stringbuf.members] Member functions:
454
455#if _LIBCPP_STD_VER >= 20
456  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); }
457#endif
458
459#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
460  string_type str() const;
461#else
462  _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); }
463
464  _LIBCPP_HIDE_FROM_ABI string_type str() && {
465    const basic_string_view<_CharT, _Traits> __view = view();
466    typename string_type::size_type __pos           = __view.empty() ? 0 : __view.data() - __str_.data();
467    // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator());
468    // But we need something that works in C++20 also.
469    string_type __result(std::move(__str_), __str_.get_allocator());
470    __result.resize(__pos + __view.size());
471    __result.erase(0, __pos);
472    __init_buf_ptrs();
473    return __result;
474  }
475#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
476
477#if _LIBCPP_STD_VER >= 20
478  template <class _SAlloc>
479    requires __is_allocator<_SAlloc>::value
480  _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
481    return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa);
482  }
483
484  _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept;
485#endif // _LIBCPP_STD_VER >= 20
486
487  void str(const string_type& __s) {
488    __str_ = __s;
489    __init_buf_ptrs();
490  }
491
492#if _LIBCPP_STD_VER >= 20
493  template <class _SAlloc>
494    requires(!is_same_v<_SAlloc, allocator_type>)
495  _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
496    __str_ = __s;
497    __init_buf_ptrs();
498  }
499
500  _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) {
501    __str_ = std::move(__s);
502    __init_buf_ptrs();
503  }
504#endif // _LIBCPP_STD_VER >= 20
505
506#if _LIBCPP_STD_VER >= 26
507
508  template <class _Tp>
509    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
510  _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
511    basic_string_view<_CharT, _Traits> __sv = __t;
512    __str_                                  = __sv;
513    __init_buf_ptrs();
514  }
515
516#endif //  _LIBCPP_STD_VER >= 26
517
518protected:
519  // [stringbuf.virtuals] Overridden virtual functions:
520  int_type underflow() override;
521  int_type pbackfail(int_type __c = traits_type::eof()) override;
522  int_type overflow(int_type __c = traits_type::eof()) override;
523  pos_type
524  seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override;
525  _LIBCPP_HIDE_FROM_ABI_VIRTUAL
526  pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override {
527    return seekoff(__sp, ios_base::beg, __wch);
528  }
529};
530
531template <class _CharT, class _Traits, class _Allocator>
532_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) {
533  char_type* __p   = const_cast<char_type*>(__rhs.__str_.data());
534  ptrdiff_t __binp = -1;
535  ptrdiff_t __ninp = -1;
536  ptrdiff_t __einp = -1;
537  if (__rhs.eback() != nullptr) {
538    __binp = __rhs.eback() - __p;
539    __ninp = __rhs.gptr() - __p;
540    __einp = __rhs.egptr() - __p;
541  }
542  ptrdiff_t __bout = -1;
543  ptrdiff_t __nout = -1;
544  ptrdiff_t __eout = -1;
545  if (__rhs.pbase() != nullptr) {
546    __bout = __rhs.pbase() - __p;
547    __nout = __rhs.pptr() - __p;
548    __eout = __rhs.epptr() - __p;
549  }
550  ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
551  __str_         = std::move(__rhs.__str_);
552  __p            = const_cast<char_type*>(__str_.data());
553  if (__binp != -1)
554    this->setg(__p + __binp, __p + __ninp, __p + __einp);
555  if (__bout != -1) {
556    this->setp(__p + __bout, __p + __eout);
557    this->__pbump(__nout);
558  }
559  __hm_ = __hm == -1 ? nullptr : __p + __hm;
560  __p   = const_cast<char_type*>(__rhs.__str_.data());
561  __rhs.setg(__p, __p, __p);
562  __rhs.setp(__p, __p);
563  __rhs.__hm_ = __p;
564  this->pubimbue(__rhs.getloc());
565}
566
567template <class _CharT, class _Traits, class _Allocator>
568basic_stringbuf<_CharT, _Traits, _Allocator>&
569basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) {
570  char_type* __p   = const_cast<char_type*>(__rhs.__str_.data());
571  ptrdiff_t __binp = -1;
572  ptrdiff_t __ninp = -1;
573  ptrdiff_t __einp = -1;
574  if (__rhs.eback() != nullptr) {
575    __binp = __rhs.eback() - __p;
576    __ninp = __rhs.gptr() - __p;
577    __einp = __rhs.egptr() - __p;
578  }
579  ptrdiff_t __bout = -1;
580  ptrdiff_t __nout = -1;
581  ptrdiff_t __eout = -1;
582  if (__rhs.pbase() != nullptr) {
583    __bout = __rhs.pbase() - __p;
584    __nout = __rhs.pptr() - __p;
585    __eout = __rhs.epptr() - __p;
586  }
587  ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
588  __str_         = std::move(__rhs.__str_);
589  __p            = const_cast<char_type*>(__str_.data());
590  if (__binp != -1)
591    this->setg(__p + __binp, __p + __ninp, __p + __einp);
592  else
593    this->setg(nullptr, nullptr, nullptr);
594  if (__bout != -1) {
595    this->setp(__p + __bout, __p + __eout);
596    this->__pbump(__nout);
597  } else
598    this->setp(nullptr, nullptr);
599
600  __hm_   = __hm == -1 ? nullptr : __p + __hm;
601  __mode_ = __rhs.__mode_;
602  __p     = const_cast<char_type*>(__rhs.__str_.data());
603  __rhs.setg(__p, __p, __p);
604  __rhs.setp(__p, __p);
605  __rhs.__hm_ = __p;
606  this->pubimbue(__rhs.getloc());
607  return *this;
608}
609
610template <class _CharT, class _Traits, class _Allocator>
611void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
612#if _LIBCPP_STD_VER >= 20
613    noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value ||
614             allocator_traits<_Allocator>::is_always_equal::value)
615#endif
616{
617  char_type* __p    = const_cast<char_type*>(__rhs.__str_.data());
618  ptrdiff_t __rbinp = -1;
619  ptrdiff_t __rninp = -1;
620  ptrdiff_t __reinp = -1;
621  if (__rhs.eback() != nullptr) {
622    __rbinp = __rhs.eback() - __p;
623    __rninp = __rhs.gptr() - __p;
624    __reinp = __rhs.egptr() - __p;
625  }
626  ptrdiff_t __rbout = -1;
627  ptrdiff_t __rnout = -1;
628  ptrdiff_t __reout = -1;
629  if (__rhs.pbase() != nullptr) {
630    __rbout = __rhs.pbase() - __p;
631    __rnout = __rhs.pptr() - __p;
632    __reout = __rhs.epptr() - __p;
633  }
634  ptrdiff_t __rhm   = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
635  __p               = const_cast<char_type*>(__str_.data());
636  ptrdiff_t __lbinp = -1;
637  ptrdiff_t __lninp = -1;
638  ptrdiff_t __leinp = -1;
639  if (this->eback() != nullptr) {
640    __lbinp = this->eback() - __p;
641    __lninp = this->gptr() - __p;
642    __leinp = this->egptr() - __p;
643  }
644  ptrdiff_t __lbout = -1;
645  ptrdiff_t __lnout = -1;
646  ptrdiff_t __leout = -1;
647  if (this->pbase() != nullptr) {
648    __lbout = this->pbase() - __p;
649    __lnout = this->pptr() - __p;
650    __leout = this->epptr() - __p;
651  }
652  ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
653  std::swap(__mode_, __rhs.__mode_);
654  __str_.swap(__rhs.__str_);
655  __p = const_cast<char_type*>(__str_.data());
656  if (__rbinp != -1)
657    this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
658  else
659    this->setg(nullptr, nullptr, nullptr);
660  if (__rbout != -1) {
661    this->setp(__p + __rbout, __p + __reout);
662    this->__pbump(__rnout);
663  } else
664    this->setp(nullptr, nullptr);
665  __hm_ = __rhm == -1 ? nullptr : __p + __rhm;
666  __p   = const_cast<char_type*>(__rhs.__str_.data());
667  if (__lbinp != -1)
668    __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
669  else
670    __rhs.setg(nullptr, nullptr, nullptr);
671  if (__lbout != -1) {
672    __rhs.setp(__p + __lbout, __p + __leout);
673    __rhs.__pbump(__lnout);
674  } else
675    __rhs.setp(nullptr, nullptr);
676  __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
677  locale __tl = __rhs.getloc();
678  __rhs.pubimbue(this->getloc());
679  this->pubimbue(__tl);
680}
681
682template <class _CharT, class _Traits, class _Allocator>
683inline _LIBCPP_HIDE_FROM_ABI void
684swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
685#if _LIBCPP_STD_VER >= 20
686    noexcept(noexcept(__x.swap(__y)))
687#endif
688{
689  __x.swap(__y);
690}
691
692#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
693template <class _CharT, class _Traits, class _Allocator>
694basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const {
695  if (__mode_ & ios_base::out) {
696    if (__hm_ < this->pptr())
697      __hm_ = this->pptr();
698    return string_type(this->pbase(), __hm_, __str_.get_allocator());
699  } else if (__mode_ & ios_base::in)
700    return string_type(this->eback(), this->egptr(), __str_.get_allocator());
701  return string_type(__str_.get_allocator());
702}
703#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
704
705template <class _CharT, class _Traits, class _Allocator>
706_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() {
707  __hm_                                = nullptr;
708  char_type* __data                    = const_cast<char_type*>(__str_.data());
709  typename string_type::size_type __sz = __str_.size();
710  if (__mode_ & ios_base::in) {
711    __hm_ = __data + __sz;
712    this->setg(__data, __data, __hm_);
713  }
714  if (__mode_ & ios_base::out) {
715    __hm_ = __data + __sz;
716    __str_.resize(__str_.capacity());
717    this->setp(__data, __data + __str_.size());
718    if (__mode_ & (ios_base::app | ios_base::ate)) {
719      while (__sz > INT_MAX) {
720        this->pbump(INT_MAX);
721        __sz -= INT_MAX;
722      }
723      if (__sz > 0)
724        this->pbump(__sz);
725    }
726  }
727}
728
729#if _LIBCPP_STD_VER >= 20
730template <class _CharT, class _Traits, class _Allocator>
731_LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits>
732basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept {
733  if (__mode_ & ios_base::out) {
734    if (__hm_ < this->pptr())
735      __hm_ = this->pptr();
736    return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_);
737  } else if (__mode_ & ios_base::in)
738    return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr());
739  return basic_string_view<_CharT, _Traits>();
740}
741#endif // _LIBCPP_STD_VER >= 20
742
743template <class _CharT, class _Traits, class _Allocator>
744typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
745basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() {
746  if (__hm_ < this->pptr())
747    __hm_ = this->pptr();
748  if (__mode_ & ios_base::in) {
749    if (this->egptr() < __hm_)
750      this->setg(this->eback(), this->gptr(), __hm_);
751    if (this->gptr() < this->egptr())
752      return traits_type::to_int_type(*this->gptr());
753  }
754  return traits_type::eof();
755}
756
757template <class _CharT, class _Traits, class _Allocator>
758typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
759basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) {
760  if (__hm_ < this->pptr())
761    __hm_ = this->pptr();
762  if (this->eback() < this->gptr()) {
763    if (traits_type::eq_int_type(__c, traits_type::eof())) {
764      this->setg(this->eback(), this->gptr() - 1, __hm_);
765      return traits_type::not_eof(__c);
766    }
767    if ((__mode_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
768      this->setg(this->eback(), this->gptr() - 1, __hm_);
769      *this->gptr() = traits_type::to_char_type(__c);
770      return __c;
771    }
772  }
773  return traits_type::eof();
774}
775
776template <class _CharT, class _Traits, class _Allocator>
777typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
778basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) {
779  if (!traits_type::eq_int_type(__c, traits_type::eof())) {
780    ptrdiff_t __ninp = this->gptr() - this->eback();
781    if (this->pptr() == this->epptr()) {
782      if (!(__mode_ & ios_base::out))
783        return traits_type::eof();
784#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
785      try {
786#endif // _LIBCPP_HAS_NO_EXCEPTIONS
787        ptrdiff_t __nout = this->pptr() - this->pbase();
788        ptrdiff_t __hm   = __hm_ - this->pbase();
789        __str_.push_back(char_type());
790        __str_.resize(__str_.capacity());
791        char_type* __p = const_cast<char_type*>(__str_.data());
792        this->setp(__p, __p + __str_.size());
793        this->__pbump(__nout);
794        __hm_ = this->pbase() + __hm;
795#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
796      } catch (...) {
797        return traits_type::eof();
798      }
799#endif // _LIBCPP_HAS_NO_EXCEPTIONS
800    }
801    __hm_ = std::max(this->pptr() + 1, __hm_);
802    if (__mode_ & ios_base::in) {
803      char_type* __p = const_cast<char_type*>(__str_.data());
804      this->setg(__p, __p + __ninp, __hm_);
805    }
806    return this->sputc(traits_type::to_char_type(__c));
807  }
808  return traits_type::not_eof(__c);
809}
810
811template <class _CharT, class _Traits, class _Allocator>
812typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(
813    off_type __off, ios_base::seekdir __way, ios_base::openmode __wch) {
814  if (__hm_ < this->pptr())
815    __hm_ = this->pptr();
816  if ((__wch & (ios_base::in | ios_base::out)) == 0)
817    return pos_type(-1);
818  if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur)
819    return pos_type(-1);
820  const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
821  off_type __noff;
822  switch (__way) {
823  case ios_base::beg:
824    __noff = 0;
825    break;
826  case ios_base::cur:
827    if (__wch & ios_base::in)
828      __noff = this->gptr() - this->eback();
829    else
830      __noff = this->pptr() - this->pbase();
831    break;
832  case ios_base::end:
833    __noff = __hm;
834    break;
835  default:
836    return pos_type(-1);
837  }
838  __noff += __off;
839  if (__noff < 0 || __hm < __noff)
840    return pos_type(-1);
841  if (__noff != 0) {
842    if ((__wch & ios_base::in) && this->gptr() == nullptr)
843      return pos_type(-1);
844    if ((__wch & ios_base::out) && this->pptr() == nullptr)
845      return pos_type(-1);
846  }
847  if (__wch & ios_base::in)
848    this->setg(this->eback(), this->eback() + __noff, __hm_);
849  if (__wch & ios_base::out) {
850    this->setp(this->pbase(), this->epptr());
851    this->__pbump(__noff);
852  }
853  return pos_type(__noff);
854}
855
856// Class template basic_istringstream [istringstream]
857
858template <class _CharT, class _Traits, class _Allocator>
859class _LIBCPP_TEMPLATE_VIS basic_istringstream : public basic_istream<_CharT, _Traits> {
860public:
861  typedef _CharT char_type;
862  typedef _Traits traits_type;
863  typedef typename traits_type::int_type int_type;
864  typedef typename traits_type::pos_type pos_type;
865  typedef typename traits_type::off_type off_type;
866  typedef _Allocator allocator_type;
867
868  typedef basic_string<char_type, traits_type, allocator_type> string_type;
869
870private:
871  basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
872
873public:
874  // [istringstream.cons] Constructors:
875  _LIBCPP_HIDE_FROM_ABI basic_istringstream()
876      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in) {}
877
878  _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch)
879      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in) {}
880
881  _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in)
882      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
883
884#if _LIBCPP_STD_VER >= 20
885  _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a)
886      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {}
887
888  _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in)
889      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {}
890
891  template <class _SAlloc>
892  _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
893      : basic_istringstream(__s, ios_base::in, __a) {}
894
895  template <class _SAlloc>
896  _LIBCPP_HIDE_FROM_ABI basic_istringstream(
897      const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
898      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {}
899
900  template <class _SAlloc>
901  _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
902                                                     ios_base::openmode __wch = ios_base::in)
903      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
904#endif // _LIBCPP_STD_VER >= 20
905
906#if _LIBCPP_STD_VER >= 26
907
908  template <class _Tp>
909    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
910  _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in)
911      : basic_istringstream(__t, __which, _Allocator()) {}
912
913  template <class _Tp>
914    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
915  _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a)
916      : basic_istringstream(__t, ios_base::in, __a) {}
917
918  template <class _Tp>
919    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
920  _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
921      : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {}
922
923#endif //  _LIBCPP_STD_VER >= 26
924
925  basic_istringstream(const basic_istringstream&) = delete;
926  _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
927      : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
928    basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
929  }
930
931  // [istringstream.assign] Assign and swap:
932  basic_istringstream& operator=(const basic_istringstream&) = delete;
933  basic_istringstream& operator=(basic_istringstream&& __rhs) {
934    basic_istream<char_type, traits_type>::operator=(std::move(__rhs));
935    __sb_ = std::move(__rhs.__sb_);
936    return *this;
937  }
938  _LIBCPP_HIDE_FROM_ABI void swap(basic_istringstream& __rhs) {
939    basic_istream<char_type, traits_type>::swap(__rhs);
940    __sb_.swap(__rhs.__sb_);
941  }
942
943  // [istringstream.members] Member functions:
944  _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
945    return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
946  }
947
948#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
949  _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
950#else
951  _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
952
953  _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
954#endif
955
956#if _LIBCPP_STD_VER >= 20
957  template <class _SAlloc>
958    requires __is_allocator<_SAlloc>::value
959  _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
960    return __sb_.str(__sa);
961  }
962
963  _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
964#endif // _LIBCPP_STD_VER >= 20
965
966  _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
967
968#if _LIBCPP_STD_VER >= 20
969  template <class _SAlloc>
970  _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
971    __sb_.str(__s);
972  }
973
974  _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
975#endif // _LIBCPP_STD_VER >= 20
976
977#if _LIBCPP_STD_VER >= 26
978  template <class _Tp>
979    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
980  _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
981    rdbuf()->str(__t);
982  }
983#endif //  _LIBCPP_STD_VER >= 26
984};
985
986template <class _CharT, class _Traits, class _Allocator>
987inline _LIBCPP_HIDE_FROM_ABI void
988swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<_CharT, _Traits, _Allocator>& __y) {
989  __x.swap(__y);
990}
991
992// Class template basic_ostringstream [ostringstream]
993
994template <class _CharT, class _Traits, class _Allocator>
995class _LIBCPP_TEMPLATE_VIS basic_ostringstream : public basic_ostream<_CharT, _Traits> {
996public:
997  typedef _CharT char_type;
998  typedef _Traits traits_type;
999  typedef typename traits_type::int_type int_type;
1000  typedef typename traits_type::pos_type pos_type;
1001  typedef typename traits_type::off_type off_type;
1002  typedef _Allocator allocator_type;
1003
1004  typedef basic_string<char_type, traits_type, allocator_type> string_type;
1005
1006private:
1007  basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
1008
1009public:
1010  // [ostringstream.cons] Constructors:
1011  _LIBCPP_HIDE_FROM_ABI basic_ostringstream()
1012      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::out) {}
1013
1014  _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch)
1015      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out) {}
1016
1017  _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out)
1018      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1019
1020#if _LIBCPP_STD_VER >= 20
1021  _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a)
1022      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {}
1023
1024  _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out)
1025      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {}
1026
1027  template <class _SAlloc>
1028  _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
1029      : basic_ostringstream(__s, ios_base::out, __a) {}
1030
1031  template <class _SAlloc>
1032  _LIBCPP_HIDE_FROM_ABI basic_ostringstream(
1033      const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
1034      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {}
1035
1036  template <class _SAlloc>
1037    requires(!is_same_v<_SAlloc, allocator_type>)
1038  _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
1039                                                     ios_base::openmode __wch = ios_base::out)
1040      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1041#endif // _LIBCPP_STD_VER >= 20
1042
1043#if _LIBCPP_STD_VER >= 26
1044
1045  template <class _Tp>
1046    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1047  _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out)
1048      : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {}
1049
1050  template <class _Tp>
1051    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1052  _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a)
1053      : basic_ostringstream(__t, ios_base::out, __a) {}
1054
1055  template <class _Tp>
1056    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1057  _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
1058      : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {}
1059
1060#endif //  _LIBCPP_STD_VER >= 26
1061
1062  basic_ostringstream(const basic_ostringstream&) = delete;
1063  _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
1064      : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1065    basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
1066  }
1067
1068  // [ostringstream.assign] Assign and swap:
1069  basic_ostringstream& operator=(const basic_ostringstream&) = delete;
1070  basic_ostringstream& operator=(basic_ostringstream&& __rhs) {
1071    basic_ostream<char_type, traits_type>::operator=(std::move(__rhs));
1072    __sb_ = std::move(__rhs.__sb_);
1073    return *this;
1074  }
1075
1076  _LIBCPP_HIDE_FROM_ABI void swap(basic_ostringstream& __rhs) {
1077    basic_ostream<char_type, traits_type>::swap(__rhs);
1078    __sb_.swap(__rhs.__sb_);
1079  }
1080
1081  // [ostringstream.members] Member functions:
1082  _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1083    return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
1084  }
1085
1086#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1087  _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1088#else
1089  _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
1090
1091  _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1092#endif
1093
1094#if _LIBCPP_STD_VER >= 20
1095  template <class _SAlloc>
1096    requires __is_allocator<_SAlloc>::value
1097  _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
1098    return __sb_.str(__sa);
1099  }
1100
1101  _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
1102#endif // _LIBCPP_STD_VER >= 20
1103
1104  _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
1105
1106#if _LIBCPP_STD_VER >= 20
1107  template <class _SAlloc>
1108  _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
1109    __sb_.str(__s);
1110  }
1111
1112  _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1113#endif // _LIBCPP_STD_VER >= 20
1114
1115#if _LIBCPP_STD_VER >= 26
1116  template <class _Tp>
1117    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1118  _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
1119    rdbuf()->str(__t);
1120  }
1121#endif //  _LIBCPP_STD_VER >= 26
1122};
1123
1124template <class _CharT, class _Traits, class _Allocator>
1125inline _LIBCPP_HIDE_FROM_ABI void
1126swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<_CharT, _Traits, _Allocator>& __y) {
1127  __x.swap(__y);
1128}
1129
1130// Class template basic_stringstream [stringstream]
1131
1132template <class _CharT, class _Traits, class _Allocator>
1133class _LIBCPP_TEMPLATE_VIS basic_stringstream : public basic_iostream<_CharT, _Traits> {
1134public:
1135  typedef _CharT char_type;
1136  typedef _Traits traits_type;
1137  typedef typename traits_type::int_type int_type;
1138  typedef typename traits_type::pos_type pos_type;
1139  typedef typename traits_type::off_type off_type;
1140  typedef _Allocator allocator_type;
1141
1142  typedef basic_string<char_type, traits_type, allocator_type> string_type;
1143
1144private:
1145  basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
1146
1147public:
1148  // [stringstream.cons] constructors
1149  _LIBCPP_HIDE_FROM_ABI basic_stringstream()
1150      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in | ios_base::out) {}
1151
1152  _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch)
1153      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch) {}
1154
1155  _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s,
1156                                                    ios_base::openmode __wch = ios_base::in | ios_base::out)
1157      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1158
1159#if _LIBCPP_STD_VER >= 20
1160  _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a)
1161      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {}
1162
1163  _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s,
1164                                                    ios_base::openmode __wch = ios_base::out | ios_base::in)
1165      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {}
1166
1167  template <class _SAlloc>
1168  _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
1169      : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {}
1170
1171  template <class _SAlloc>
1172  _LIBCPP_HIDE_FROM_ABI
1173  basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
1174      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {}
1175
1176  template <class _SAlloc>
1177    requires(!is_same_v<_SAlloc, allocator_type>)
1178  _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
1179                                                    ios_base::openmode __wch = ios_base::out | ios_base::in)
1180      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1181#endif // _LIBCPP_STD_VER >= 20
1182
1183#if _LIBCPP_STD_VER >= 26
1184
1185  template <class _Tp>
1186    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1187  _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t,
1188                                                    ios_base::openmode __which = ios_base::out | ios_base::in)
1189      : basic_stringstream(__t, __which, _Allocator()) {}
1190
1191  template <class _Tp>
1192    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1193  _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, const _Allocator& __a)
1194      : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {}
1195
1196  template <class _Tp>
1197    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1198  _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
1199      : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {}
1200
1201#endif //  _LIBCPP_STD_VER >= 26
1202
1203  basic_stringstream(const basic_stringstream&) = delete;
1204  _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
1205      : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1206    basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
1207  }
1208
1209  // [stringstream.assign] Assign and swap:
1210  basic_stringstream& operator=(const basic_stringstream&) = delete;
1211  basic_stringstream& operator=(basic_stringstream&& __rhs) {
1212    basic_iostream<char_type, traits_type>::operator=(std::move(__rhs));
1213    __sb_ = std::move(__rhs.__sb_);
1214    return *this;
1215  }
1216  _LIBCPP_HIDE_FROM_ABI void swap(basic_stringstream& __rhs) {
1217    basic_iostream<char_type, traits_type>::swap(__rhs);
1218    __sb_.swap(__rhs.__sb_);
1219  }
1220
1221  // [stringstream.members] Member functions:
1222  _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1223    return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
1224  }
1225
1226#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1227  _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1228#else
1229  _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
1230
1231  _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1232#endif
1233
1234#if _LIBCPP_STD_VER >= 20
1235  template <class _SAlloc>
1236    requires __is_allocator<_SAlloc>::value
1237  _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
1238    return __sb_.str(__sa);
1239  }
1240
1241  _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); }
1242#endif // _LIBCPP_STD_VER >= 20
1243
1244  _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
1245
1246#if _LIBCPP_STD_VER >= 20
1247  template <class _SAlloc>
1248  _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
1249    __sb_.str(__s);
1250  }
1251
1252  _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1253#endif // _LIBCPP_STD_VER >= 20
1254
1255#if _LIBCPP_STD_VER >= 26
1256  template <class _Tp>
1257    requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1258  _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
1259    rdbuf()->str(__t);
1260  }
1261#endif //  _LIBCPP_STD_VER >= 26
1262};
1263
1264template <class _CharT, class _Traits, class _Allocator>
1265inline _LIBCPP_HIDE_FROM_ABI void
1266swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_CharT, _Traits, _Allocator>& __y) {
1267  __x.swap(__y);
1268}
1269
1270#if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
1271extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>;
1272extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>;
1273extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>;
1274extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>;
1275#endif
1276
1277_LIBCPP_END_NAMESPACE_STD
1278
1279_LIBCPP_POP_MACROS
1280
1281#if _LIBCPP_STD_VER <= 20 && !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
1282#  include <ostream>
1283#  include <type_traits>
1284#endif
1285
1286#endif // _LIBCPP_SSTREAM
1287