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#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
316# include <__cxx03/sstream>
317#else
318# include <__config>
319
320# if _LIBCPP_HAS_LOCALIZATION
321
322# include <__fwd/sstream.h>
323# include <__locale_dir/locale.h>
324# include <__ostream/basic_ostream.h>
325# include <__type_traits/is_convertible.h>
326# include <__utility/swap.h>
327# include <ios>
328# include <istream>
329# include <streambuf>
330# include <string>
331# include <string_view>
332# include <version>
333
334# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
335# pragma GCC system_header
336# endif
337
338_LIBCPP_PUSH_MACROS
339# include <__undef_macros>
340
341_LIBCPP_BEGIN_NAMESPACE_STD
342_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
343
344// Class template basic_stringbuf [stringbuf]
345
346template <class _CharT, class _Traits, class _Allocator>
347class basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
348public:
349 typedef _CharT char_type;
350 typedef _Traits traits_type;
351 typedef typename traits_type::int_type int_type;
352 typedef typename traits_type::pos_type pos_type;
353 typedef typename traits_type::off_type off_type;
354 typedef _Allocator allocator_type;
355
356 typedef basic_string<char_type, traits_type, allocator_type> string_type;
357
358private:
359 string_type __str_;
360 mutable char_type* __hm_;
361 ios_base::openmode __mode_;
362 _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs();
363 _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs);
364
365public:
366 // [stringbuf.cons] constructors:
367 _LIBCPP_HIDE_FROM_ABI basic_stringbuf() : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {
368 // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
369 __init_buf_ptrs();
370 }
371
372 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(ios_base::openmode __wch) : __hm_(nullptr), __mode_(__wch) {
373 // it is implementation-defined whether we initialize eback() & friends to nullptr, and libc++ doesn't
374 __init_buf_ptrs();
375 }
376
377 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const string_type& __s,
378 ios_base::openmode __wch = ios_base::in | ios_base::out)
379 : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) {
380 str(__s);
381 }
382
383# if _LIBCPP_STD_VER >= 20
384 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a)
385 : basic_stringbuf(ios_base::in | ios_base::out, __a) {}
386
387 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a)
388 : __str_(__a), __hm_(nullptr), __mode_(__wch) {
389 __init_buf_ptrs();
390 }
391
392 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s,
393 ios_base::openmode __wch = ios_base::in | ios_base::out)
394 : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) {
395 __init_buf_ptrs();
396 }
397
398 template <class _SAlloc>
399 _LIBCPP_HIDE_FROM_ABI
400 basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a)
401 : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {}
402
403 template <class _SAlloc>
404 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(
405 const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a)
406 : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) {
407 __init_buf_ptrs();
408 }
409
410 template <class _SAlloc>
411 requires(!is_same_v<_SAlloc, allocator_type>)
412 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s,
413 ios_base::openmode __wch = ios_base::in | ios_base::out)
414 : __str_(__s), __hm_(nullptr), __mode_(__wch) {
415 __init_buf_ptrs();
416 }
417# endif // _LIBCPP_STD_VER >= 20
418
419# if _LIBCPP_STD_VER >= 26
420
421 template <class _Tp>
422 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
423 _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const _Tp& __t,
424 ios_base::openmode __which = ios_base::in | ios_base::out)
425 : basic_stringbuf(__t, __which, _Allocator()) {}
426
427 template <class _Tp>
428 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
429 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, const _Allocator& __a)
430 : basic_stringbuf(__t, ios_base::in | ios_base::out, __a) {}
431
432 template <class _Tp>
433 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
434 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
435 : __hm_(nullptr), __mode_(__which) {
436 basic_string_view<_CharT, _Traits> __sv = __t;
437 __str_ = string_type(__sv, __a);
438 __init_buf_ptrs();
439 }
440
441# endif // _LIBCPP_STD_VER >= 26
442
443 basic_stringbuf(const basic_stringbuf&) = delete;
444 basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(rhs: std::move(__rhs)); }
445
446# if _LIBCPP_STD_VER >= 20
447 _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a)
448 : basic_stringbuf(__rhs.__mode_, __a) {
449 __move_init(rhs: std::move(__rhs));
450 }
451# endif
452
453 // [stringbuf.assign] Assign and swap:
454 basic_stringbuf& operator=(const basic_stringbuf&) = delete;
455 basic_stringbuf& operator=(basic_stringbuf&& __rhs);
456 void swap(basic_stringbuf& __rhs)
457# if _LIBCPP_STD_VER >= 20
458 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
459 allocator_traits<allocator_type>::is_always_equal::value)
460# endif
461 ;
462
463 // [stringbuf.members] Member functions:
464
465# if _LIBCPP_STD_VER >= 20
466 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); }
467# endif
468
469# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
470 [[__nodiscard__]] string_type str() const;
471# else
472 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return str(__str_.get_allocator()); }
473
474 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && {
475 const basic_string_view<_CharT, _Traits> __view = view();
476 typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data();
477 // In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator());
478 // But we need something that works in C++20 also.
479 string_type __result(std::move(__str_), __str_.get_allocator());
480 __result.resize(__pos + __view.size());
481 __result.erase(0, __pos);
482 __init_buf_ptrs();
483 return __result;
484 }
485# endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
486
487# if _LIBCPP_STD_VER >= 20
488 template <class _SAlloc>
489 requires __is_allocator_v<_SAlloc>
490 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
491 return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa);
492 }
493
494 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept;
495# endif // _LIBCPP_STD_VER >= 20
496
497 void str(const string_type& __s) {
498 __str_ = __s;
499 __init_buf_ptrs();
500 }
501
502# if _LIBCPP_STD_VER >= 20
503 template <class _SAlloc>
504 requires(!is_same_v<_SAlloc, allocator_type>)
505 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
506 __str_ = __s;
507 __init_buf_ptrs();
508 }
509
510 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) {
511 __str_ = std::move(__s);
512 __init_buf_ptrs();
513 }
514# endif // _LIBCPP_STD_VER >= 20
515
516# if _LIBCPP_STD_VER >= 26
517
518 template <class _Tp>
519 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
520 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
521 basic_string_view<_CharT, _Traits> __sv = __t;
522 __str_ = __sv;
523 __init_buf_ptrs();
524 }
525
526# endif // _LIBCPP_STD_VER >= 26
527
528protected:
529 // [stringbuf.virtuals] Overridden virtual functions:
530 int_type underflow() override;
531 int_type pbackfail(int_type __c = traits_type::eof()) override;
532 int_type overflow(int_type __c = traits_type::eof()) override;
533 pos_type
534 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override;
535 _LIBCPP_HIDE_FROM_ABI_VIRTUAL
536 pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override {
537 return seekoff(off: __sp, way: ios_base::beg, __wch);
538 }
539};
540
541template <class _CharT, class _Traits, class _Allocator>
542_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) {
543 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
544 ptrdiff_t __binp = -1;
545 ptrdiff_t __ninp = -1;
546 ptrdiff_t __einp = -1;
547 if (__rhs.eback() != nullptr) {
548 __binp = __rhs.eback() - __p;
549 __ninp = __rhs.gptr() - __p;
550 __einp = __rhs.egptr() - __p;
551 }
552 ptrdiff_t __bout = -1;
553 ptrdiff_t __nout = -1;
554 ptrdiff_t __eout = -1;
555 if (__rhs.pbase() != nullptr) {
556 __bout = __rhs.pbase() - __p;
557 __nout = __rhs.pptr() - __p;
558 __eout = __rhs.epptr() - __p;
559 }
560 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
561 __str_ = std::move(__rhs.__str_);
562 __p = const_cast<char_type*>(__str_.data());
563 if (__binp != -1)
564 this->setg(__p + __binp, __p + __ninp, __p + __einp);
565 if (__bout != -1) {
566 this->setp(__p + __bout, __p + __eout);
567 this->__pbump(__nout);
568 }
569 __hm_ = __hm == -1 ? nullptr : __p + __hm;
570 __p = const_cast<char_type*>(__rhs.__str_.data());
571 __rhs.setg(__p, __p, __p);
572 __rhs.setp(__p, __p);
573 __rhs.__hm_ = __p;
574 this->pubimbue(__rhs.getloc());
575}
576
577template <class _CharT, class _Traits, class _Allocator>
578basic_stringbuf<_CharT, _Traits, _Allocator>&
579basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) {
580 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
581 ptrdiff_t __binp = -1;
582 ptrdiff_t __ninp = -1;
583 ptrdiff_t __einp = -1;
584 if (__rhs.eback() != nullptr) {
585 __binp = __rhs.eback() - __p;
586 __ninp = __rhs.gptr() - __p;
587 __einp = __rhs.egptr() - __p;
588 }
589 ptrdiff_t __bout = -1;
590 ptrdiff_t __nout = -1;
591 ptrdiff_t __eout = -1;
592 if (__rhs.pbase() != nullptr) {
593 __bout = __rhs.pbase() - __p;
594 __nout = __rhs.pptr() - __p;
595 __eout = __rhs.epptr() - __p;
596 }
597 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
598 __str_ = std::move(__rhs.__str_);
599 __p = const_cast<char_type*>(__str_.data());
600 if (__binp != -1)
601 this->setg(__p + __binp, __p + __ninp, __p + __einp);
602 else
603 this->setg(nullptr, nullptr, nullptr);
604 if (__bout != -1) {
605 this->setp(__p + __bout, __p + __eout);
606 this->__pbump(__nout);
607 } else
608 this->setp(nullptr, nullptr);
609
610 __hm_ = __hm == -1 ? nullptr : __p + __hm;
611 __mode_ = __rhs.__mode_;
612 __p = const_cast<char_type*>(__rhs.__str_.data());
613 __rhs.setg(__p, __p, __p);
614 __rhs.setp(__p, __p);
615 __rhs.__hm_ = __p;
616 this->pubimbue(__rhs.getloc());
617 return *this;
618}
619
620template <class _CharT, class _Traits, class _Allocator>
621void basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
622# if _LIBCPP_STD_VER >= 20
623 noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value ||
624 allocator_traits<_Allocator>::is_always_equal::value)
625# endif
626{
627 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
628 ptrdiff_t __rbinp = -1;
629 ptrdiff_t __rninp = -1;
630 ptrdiff_t __reinp = -1;
631 if (__rhs.eback() != nullptr) {
632 __rbinp = __rhs.eback() - __p;
633 __rninp = __rhs.gptr() - __p;
634 __reinp = __rhs.egptr() - __p;
635 }
636 ptrdiff_t __rbout = -1;
637 ptrdiff_t __rnout = -1;
638 ptrdiff_t __reout = -1;
639 if (__rhs.pbase() != nullptr) {
640 __rbout = __rhs.pbase() - __p;
641 __rnout = __rhs.pptr() - __p;
642 __reout = __rhs.epptr() - __p;
643 }
644 ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
645 __p = const_cast<char_type*>(__str_.data());
646 ptrdiff_t __lbinp = -1;
647 ptrdiff_t __lninp = -1;
648 ptrdiff_t __leinp = -1;
649 if (this->eback() != nullptr) {
650 __lbinp = this->eback() - __p;
651 __lninp = this->gptr() - __p;
652 __leinp = this->egptr() - __p;
653 }
654 ptrdiff_t __lbout = -1;
655 ptrdiff_t __lnout = -1;
656 ptrdiff_t __leout = -1;
657 if (this->pbase() != nullptr) {
658 __lbout = this->pbase() - __p;
659 __lnout = this->pptr() - __p;
660 __leout = this->epptr() - __p;
661 }
662 ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
663 std::swap(x&: __mode_, y&: __rhs.__mode_);
664 __str_.swap(__rhs.__str_);
665 __p = const_cast<char_type*>(__str_.data());
666 if (__rbinp != -1)
667 this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
668 else
669 this->setg(nullptr, nullptr, nullptr);
670 if (__rbout != -1) {
671 this->setp(__p + __rbout, __p + __reout);
672 this->__pbump(__rnout);
673 } else
674 this->setp(nullptr, nullptr);
675 __hm_ = __rhm == -1 ? nullptr : __p + __rhm;
676 __p = const_cast<char_type*>(__rhs.__str_.data());
677 if (__lbinp != -1)
678 __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
679 else
680 __rhs.setg(nullptr, nullptr, nullptr);
681 if (__lbout != -1) {
682 __rhs.setp(__p + __lbout, __p + __leout);
683 __rhs.__pbump(__lnout);
684 } else
685 __rhs.setp(nullptr, nullptr);
686 __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
687 locale __tl = __rhs.getloc();
688 __rhs.pubimbue(this->getloc());
689 this->pubimbue(__tl);
690}
691
692template <class _CharT, class _Traits, class _Allocator>
693inline _LIBCPP_HIDE_FROM_ABI void
694swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
695# if _LIBCPP_STD_VER >= 20
696 noexcept(noexcept(__x.swap(__y)))
697# endif
698{
699 __x.swap(__y);
700}
701
702# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
703template <class _CharT, class _Traits, class _Allocator>
704basic_string<_CharT, _Traits, _Allocator> basic_stringbuf<_CharT, _Traits, _Allocator>::str() const {
705 if (__mode_ & ios_base::out) {
706 if (__hm_ < this->pptr())
707 __hm_ = this->pptr();
708 return string_type(this->pbase(), __hm_, __str_.get_allocator());
709 } else if (__mode_ & ios_base::in)
710 return string_type(this->eback(), this->egptr(), __str_.get_allocator());
711 return string_type(__str_.get_allocator());
712}
713# endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
714
715template <class _CharT, class _Traits, class _Allocator>
716_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() {
717 __hm_ = nullptr;
718 char_type* __data = const_cast<char_type*>(__str_.data());
719 typename string_type::size_type __sz = __str_.size();
720 if (__mode_ & ios_base::in) {
721 __hm_ = __data + __sz;
722 this->setg(__data, __data, __hm_);
723 }
724 if (__mode_ & ios_base::out) {
725 __hm_ = __data + __sz;
726 __str_.resize(__str_.capacity());
727 this->setp(__data, __data + __str_.size());
728 if (__mode_ & (ios_base::app | ios_base::ate)) {
729 while (__sz > INT_MAX) {
730 this->pbump(INT_MAX);
731 __sz -= INT_MAX;
732 }
733 if (__sz > 0)
734 this->pbump(__sz);
735 }
736 }
737}
738
739# if _LIBCPP_STD_VER >= 20
740template <class _CharT, class _Traits, class _Allocator>
741_LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits>
742basic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept {
743 if (__mode_ & ios_base::out) {
744 if (__hm_ < this->pptr())
745 __hm_ = this->pptr();
746 return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_);
747 } else if (__mode_ & ios_base::in)
748 return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr());
749 return basic_string_view<_CharT, _Traits>();
750}
751# endif // _LIBCPP_STD_VER >= 20
752
753template <class _CharT, class _Traits, class _Allocator>
754typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
755basic_stringbuf<_CharT, _Traits, _Allocator>::underflow() {
756 if (__hm_ < this->pptr())
757 __hm_ = this->pptr();
758 if (__mode_ & ios_base::in) {
759 if (this->egptr() < __hm_)
760 this->setg(this->eback(), this->gptr(), __hm_);
761 if (this->gptr() < this->egptr())
762 return traits_type::to_int_type(*this->gptr());
763 }
764 return traits_type::eof();
765}
766
767template <class _CharT, class _Traits, class _Allocator>
768typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
769basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) {
770 if (__hm_ < this->pptr())
771 __hm_ = this->pptr();
772 if (this->eback() < this->gptr()) {
773 if (traits_type::eq_int_type(__c, traits_type::eof())) {
774 this->setg(this->eback(), this->gptr() - 1, __hm_);
775 return traits_type::not_eof(__c);
776 }
777 if ((__mode_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
778 this->setg(this->eback(), this->gptr() - 1, __hm_);
779 *this->gptr() = traits_type::to_char_type(__c);
780 return __c;
781 }
782 }
783 return traits_type::eof();
784}
785
786template <class _CharT, class _Traits, class _Allocator>
787typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
788basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) {
789 if (!traits_type::eq_int_type(__c, traits_type::eof())) {
790 ptrdiff_t __ninp = this->gptr() - this->eback();
791 if (this->pptr() == this->epptr()) {
792 if (!(__mode_ & ios_base::out))
793 return traits_type::eof();
794# if _LIBCPP_HAS_EXCEPTIONS
795 try {
796# endif // _LIBCPP_HAS_EXCEPTIONS
797 ptrdiff_t __nout = this->pptr() - this->pbase();
798 ptrdiff_t __hm = __hm_ - this->pbase();
799 __str_.push_back(char_type());
800 __str_.resize(__str_.capacity());
801 char_type* __p = const_cast<char_type*>(__str_.data());
802 this->setp(__p, __p + __str_.size());
803 this->__pbump(__nout);
804 __hm_ = this->pbase() + __hm;
805# if _LIBCPP_HAS_EXCEPTIONS
806 } catch (...) {
807 return traits_type::eof();
808 }
809# endif // _LIBCPP_HAS_EXCEPTIONS
810 }
811 __hm_ = std::max(this->pptr() + 1, __hm_);
812 if (__mode_ & ios_base::in) {
813 char_type* __p = const_cast<char_type*>(__str_.data());
814 this->setg(__p, __p + __ninp, __hm_);
815 }
816 return this->sputc(traits_type::to_char_type(__c));
817 }
818 return traits_type::not_eof(__c);
819}
820
821template <class _CharT, class _Traits, class _Allocator>
822typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(
823 off_type __off, ios_base::seekdir __way, ios_base::openmode __wch) {
824 if (__hm_ < this->pptr())
825 __hm_ = this->pptr();
826 if ((__wch & (ios_base::in | ios_base::out)) == 0)
827 return pos_type(-1);
828 if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur)
829 return pos_type(-1);
830 const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
831 off_type __noff;
832 switch (__way) {
833 case ios_base::beg:
834 __noff = 0;
835 break;
836 case ios_base::cur:
837 if (__wch & ios_base::in)
838 __noff = this->gptr() - this->eback();
839 else
840 __noff = this->pptr() - this->pbase();
841 break;
842 case ios_base::end:
843 __noff = __hm;
844 break;
845 default:
846 return pos_type(-1);
847 }
848 __noff += __off;
849 if (__noff < 0 || __hm < __noff)
850 return pos_type(-1);
851 if (__noff != 0) {
852 if ((__wch & ios_base::in) && this->gptr() == nullptr)
853 return pos_type(-1);
854 if ((__wch & ios_base::out) && this->pptr() == nullptr)
855 return pos_type(-1);
856 }
857 if (__wch & ios_base::in)
858 this->setg(this->eback(), this->eback() + __noff, __hm_);
859 if (__wch & ios_base::out) {
860 this->setp(this->pbase(), this->epptr());
861 this->__pbump(__noff);
862 }
863 return pos_type(__noff);
864}
865
866// Class template basic_istringstream [istringstream]
867
868template <class _CharT, class _Traits, class _Allocator>
869class basic_istringstream : public basic_istream<_CharT, _Traits> {
870public:
871 typedef _CharT char_type;
872 typedef _Traits traits_type;
873 typedef typename traits_type::int_type int_type;
874 typedef typename traits_type::pos_type pos_type;
875 typedef typename traits_type::off_type off_type;
876 typedef _Allocator allocator_type;
877
878 typedef basic_string<char_type, traits_type, allocator_type> string_type;
879
880private:
881 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
882
883public:
884 // [istringstream.cons] Constructors:
885 _LIBCPP_HIDE_FROM_ABI basic_istringstream()
886 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in) {}
887
888 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(ios_base::openmode __wch)
889 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in) {}
890
891 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const string_type& __s, ios_base::openmode __wch = ios_base::in)
892 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
893
894# if _LIBCPP_STD_VER >= 20
895 _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a)
896 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {}
897
898 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in)
899 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {}
900
901 template <class _SAlloc>
902 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
903 : basic_istringstream(__s, ios_base::in, __a) {}
904
905 template <class _SAlloc>
906 _LIBCPP_HIDE_FROM_ABI basic_istringstream(
907 const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
908 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {}
909
910 template <class _SAlloc>
911 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
912 ios_base::openmode __wch = ios_base::in)
913 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {}
914# endif // _LIBCPP_STD_VER >= 20
915
916# if _LIBCPP_STD_VER >= 26
917
918 template <class _Tp>
919 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
920 _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const _Tp& __t, ios_base::openmode __which = ios_base::in)
921 : basic_istringstream(__t, __which, _Allocator()) {}
922
923 template <class _Tp>
924 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
925 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, const _Allocator& __a)
926 : basic_istringstream(__t, ios_base::in, __a) {}
927
928 template <class _Tp>
929 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
930 _LIBCPP_HIDE_FROM_ABI basic_istringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
931 : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::in, __a) {}
932
933# endif // _LIBCPP_STD_VER >= 26
934
935 basic_istringstream(const basic_istringstream&) = delete;
936 _LIBCPP_HIDE_FROM_ABI basic_istringstream(basic_istringstream&& __rhs)
937 : basic_istream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
938 basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
939 }
940
941 // [istringstream.assign] Assign and swap:
942 basic_istringstream& operator=(const basic_istringstream&) = delete;
943 basic_istringstream& operator=(basic_istringstream&& __rhs) {
944 basic_istream<char_type, traits_type>::operator=(std::move(__rhs));
945 __sb_ = std::move(__rhs.__sb_);
946 return *this;
947 }
948 _LIBCPP_HIDE_FROM_ABI void swap(basic_istringstream& __rhs) {
949 basic_istream<char_type, traits_type>::swap(__rhs);
950 __sb_.swap(__rhs.__sb_);
951 }
952
953 // [istringstream.members] Member functions:
954 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
955 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
956 }
957
958# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
959 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
960# else
961 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
962
963 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
964# endif
965
966# if _LIBCPP_STD_VER >= 20
967 template <class _SAlloc>
968 requires __is_allocator_v<_SAlloc>
969 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
970 return __sb_.str(__sa);
971 }
972
973 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept {
974 return __sb_.view();
975 }
976# endif // _LIBCPP_STD_VER >= 20
977
978 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
979
980# if _LIBCPP_STD_VER >= 20
981 template <class _SAlloc>
982 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
983 __sb_.str(__s);
984 }
985
986 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
987# endif // _LIBCPP_STD_VER >= 20
988
989# if _LIBCPP_STD_VER >= 26
990 template <class _Tp>
991 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
992 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
993 rdbuf()->str(__t);
994 }
995# endif // _LIBCPP_STD_VER >= 26
996};
997
998template <class _CharT, class _Traits, class _Allocator>
999inline _LIBCPP_HIDE_FROM_ABI void
1000swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, basic_istringstream<_CharT, _Traits, _Allocator>& __y) {
1001 __x.swap(__y);
1002}
1003
1004// Class template basic_ostringstream [ostringstream]
1005
1006template <class _CharT, class _Traits, class _Allocator>
1007class basic_ostringstream : public basic_ostream<_CharT, _Traits> {
1008public:
1009 typedef _CharT char_type;
1010 typedef _Traits traits_type;
1011 typedef typename traits_type::int_type int_type;
1012 typedef typename traits_type::pos_type pos_type;
1013 typedef typename traits_type::off_type off_type;
1014 typedef _Allocator allocator_type;
1015
1016 typedef basic_string<char_type, traits_type, allocator_type> string_type;
1017
1018private:
1019 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
1020
1021public:
1022 // [ostringstream.cons] Constructors:
1023 _LIBCPP_HIDE_FROM_ABI basic_ostringstream()
1024 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::out) {}
1025
1026 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(ios_base::openmode __wch)
1027 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out) {}
1028
1029 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const string_type& __s, ios_base::openmode __wch = ios_base::out)
1030 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1031
1032# if _LIBCPP_STD_VER >= 20
1033 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a)
1034 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {}
1035
1036 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out)
1037 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {}
1038
1039 template <class _SAlloc>
1040 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
1041 : basic_ostringstream(__s, ios_base::out, __a) {}
1042
1043 template <class _SAlloc>
1044 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(
1045 const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
1046 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {}
1047
1048 template <class _SAlloc>
1049 requires(!is_same_v<_SAlloc, allocator_type>)
1050 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
1051 ios_base::openmode __wch = ios_base::out)
1052 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {}
1053# endif // _LIBCPP_STD_VER >= 20
1054
1055# if _LIBCPP_STD_VER >= 26
1056
1057 template <class _Tp>
1058 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1059 _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const _Tp& __t, ios_base::openmode __which = ios_base::out)
1060 : basic_ostringstream(__t, __which | ios_base::out, _Allocator()) {}
1061
1062 template <class _Tp>
1063 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1064 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, const _Allocator& __a)
1065 : basic_ostringstream(__t, ios_base::out, __a) {}
1066
1067 template <class _Tp>
1068 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1069 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
1070 : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which | ios_base::out, __a) {}
1071
1072# endif // _LIBCPP_STD_VER >= 26
1073
1074 basic_ostringstream(const basic_ostringstream&) = delete;
1075 _LIBCPP_HIDE_FROM_ABI basic_ostringstream(basic_ostringstream&& __rhs)
1076 : basic_ostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1077 basic_ostream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
1078 }
1079
1080 // [ostringstream.assign] Assign and swap:
1081 basic_ostringstream& operator=(const basic_ostringstream&) = delete;
1082 basic_ostringstream& operator=(basic_ostringstream&& __rhs) {
1083 basic_ostream<char_type, traits_type>::operator=(std::move(__rhs));
1084 __sb_ = std::move(__rhs.__sb_);
1085 return *this;
1086 }
1087
1088 _LIBCPP_HIDE_FROM_ABI void swap(basic_ostringstream& __rhs) {
1089 basic_ostream<char_type, traits_type>::swap(__rhs);
1090 __sb_.swap(__rhs.__sb_);
1091 }
1092
1093 // [ostringstream.members] Member functions:
1094 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1095 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
1096 }
1097
1098# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1099 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1100# else
1101 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
1102
1103 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1104# endif
1105
1106# if _LIBCPP_STD_VER >= 20
1107 template <class _SAlloc>
1108 requires __is_allocator_v<_SAlloc>
1109 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
1110 return __sb_.str(__sa);
1111 }
1112
1113 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept {
1114 return __sb_.view();
1115 }
1116# endif // _LIBCPP_STD_VER >= 20
1117
1118 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
1119
1120# if _LIBCPP_STD_VER >= 20
1121 template <class _SAlloc>
1122 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
1123 __sb_.str(__s);
1124 }
1125
1126 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1127# endif // _LIBCPP_STD_VER >= 20
1128
1129# if _LIBCPP_STD_VER >= 26
1130 template <class _Tp>
1131 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1132 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
1133 rdbuf()->str(__t);
1134 }
1135# endif // _LIBCPP_STD_VER >= 26
1136};
1137
1138template <class _CharT, class _Traits, class _Allocator>
1139inline _LIBCPP_HIDE_FROM_ABI void
1140swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, basic_ostringstream<_CharT, _Traits, _Allocator>& __y) {
1141 __x.swap(__y);
1142}
1143
1144// Class template basic_stringstream [stringstream]
1145
1146template <class _CharT, class _Traits, class _Allocator>
1147class basic_stringstream : public basic_iostream<_CharT, _Traits> {
1148public:
1149 typedef _CharT char_type;
1150 typedef _Traits traits_type;
1151 typedef typename traits_type::int_type int_type;
1152 typedef typename traits_type::pos_type pos_type;
1153 typedef typename traits_type::off_type off_type;
1154 typedef _Allocator allocator_type;
1155
1156 typedef basic_string<char_type, traits_type, allocator_type> string_type;
1157
1158private:
1159 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
1160
1161public:
1162 // [stringstream.cons] constructors
1163 _LIBCPP_HIDE_FROM_ABI basic_stringstream()
1164 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(ios_base::in | ios_base::out) {}
1165
1166 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(ios_base::openmode __wch)
1167 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch) {}
1168
1169 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const string_type& __s,
1170 ios_base::openmode __wch = ios_base::in | ios_base::out)
1171 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1172
1173# if _LIBCPP_STD_VER >= 20
1174 _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a)
1175 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {}
1176
1177 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s,
1178 ios_base::openmode __wch = ios_base::out | ios_base::in)
1179 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {}
1180
1181 template <class _SAlloc>
1182 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a)
1183 : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {}
1184
1185 template <class _SAlloc>
1186 _LIBCPP_HIDE_FROM_ABI
1187 basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a)
1188 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {}
1189
1190 template <class _SAlloc>
1191 requires(!is_same_v<_SAlloc, allocator_type>)
1192 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s,
1193 ios_base::openmode __wch = ios_base::out | ios_base::in)
1194 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {}
1195# endif // _LIBCPP_STD_VER >= 20
1196
1197# if _LIBCPP_STD_VER >= 26
1198
1199 template <class _Tp>
1200 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1201 _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const _Tp& __t,
1202 ios_base::openmode __which = ios_base::out | ios_base::in)
1203 : basic_stringstream(__t, __which, _Allocator()) {}
1204
1205 template <class _Tp>
1206 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1207 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, const _Allocator& __a)
1208 : basic_stringstream(__t, ios_base::out | ios_base::in, __a) {}
1209
1210 template <class _Tp>
1211 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1212 _LIBCPP_HIDE_FROM_ABI basic_stringstream(const _Tp& __t, ios_base::openmode __which, const _Allocator& __a)
1213 : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__t, __which, __a) {}
1214
1215# endif // _LIBCPP_STD_VER >= 26
1216
1217 basic_stringstream(const basic_stringstream&) = delete;
1218 _LIBCPP_HIDE_FROM_ABI basic_stringstream(basic_stringstream&& __rhs)
1219 : basic_iostream<_CharT, _Traits>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1220 basic_istream<_CharT, _Traits>::set_rdbuf(std::addressof(__sb_));
1221 }
1222
1223 // [stringstream.assign] Assign and swap:
1224 basic_stringstream& operator=(const basic_stringstream&) = delete;
1225 basic_stringstream& operator=(basic_stringstream&& __rhs) {
1226 basic_iostream<char_type, traits_type>::operator=(std::move(__rhs));
1227 __sb_ = std::move(__rhs.__sb_);
1228 return *this;
1229 }
1230 _LIBCPP_HIDE_FROM_ABI void swap(basic_stringstream& __rhs) {
1231 basic_iostream<char_type, traits_type>::swap(__rhs);
1232 __sb_.swap(__rhs.__sb_);
1233 }
1234
1235 // [stringstream.members] Member functions:
1236 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const {
1237 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(std::addressof(__sb_));
1238 }
1239
1240# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY)
1241 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); }
1242# else
1243 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() const& { return __sb_.str(); }
1244
1245 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); }
1246# endif
1247
1248# if _LIBCPP_STD_VER >= 20
1249 template <class _SAlloc>
1250 requires __is_allocator_v<_SAlloc>
1251 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const {
1252 return __sb_.str(__sa);
1253 }
1254
1255 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept {
1256 return __sb_.view();
1257 }
1258# endif // _LIBCPP_STD_VER >= 20
1259
1260 _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); }
1261
1262# if _LIBCPP_STD_VER >= 20
1263 template <class _SAlloc>
1264 _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) {
1265 __sb_.str(__s);
1266 }
1267
1268 _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); }
1269# endif // _LIBCPP_STD_VER >= 20
1270
1271# if _LIBCPP_STD_VER >= 26
1272 template <class _Tp>
1273 requires is_convertible_v<const _Tp&, basic_string_view<_CharT, _Traits>>
1274 _LIBCPP_HIDE_FROM_ABI void str(const _Tp& __t) {
1275 rdbuf()->str(__t);
1276 }
1277# endif // _LIBCPP_STD_VER >= 26
1278};
1279
1280template <class _CharT, class _Traits, class _Allocator>
1281inline _LIBCPP_HIDE_FROM_ABI void
1282swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, basic_stringstream<_CharT, _Traits, _Allocator>& __y) {
1283 __x.swap(__y);
1284}
1285
1286# if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
1287extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>;
1288extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>;
1289extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>;
1290extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>;
1291# endif
1292
1293_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
1294_LIBCPP_END_NAMESPACE_STD
1295
1296_LIBCPP_POP_MACROS
1297
1298# endif // _LIBCPP_HAS_LOCALIZATION
1299
1300#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1301
1302#endif // _LIBCPP_SSTREAM
1303