blob: 4b1d17cfde33274b83c43b5a433628e5912ca0e9 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- sstream ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SSTREAM
11#define _LIBCPP_SSTREAM
12
13/*
14 sstream synopsis
15
16template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
17class basic_stringbuf
18 : public basic_streambuf<charT, traits>
19{
20public:
21 typedef charT char_type;
22 typedef traits traits_type;
23 typedef typename traits_type::int_type int_type;
24 typedef typename traits_type::pos_type pos_type;
25 typedef typename traits_type::off_type off_type;
26 typedef Allocator allocator_type;
27
28 // 27.8.1.1 Constructors:
29 explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out);
30 explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str,
31 ios_base::openmode which = ios_base::in | ios_base::out);
32 basic_stringbuf(basic_stringbuf&& rhs);
33
34 // 27.8.1.2 Assign and swap:
35 basic_stringbuf& operator=(basic_stringbuf&& rhs);
36 void swap(basic_stringbuf& rhs);
37
38 // 27.8.1.3 Get and set:
39 basic_string<char_type, traits_type, allocator_type> str() const;
40 void str(const basic_string<char_type, traits_type, allocator_type>& s);
41
42protected:
43 // 27.8.1.4 Overridden virtual functions:
44 virtual int_type underflow();
45 virtual int_type pbackfail(int_type c = traits_type::eof());
46 virtual int_type overflow (int_type c = traits_type::eof());
47 virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize);
48 virtual pos_type seekoff(off_type off, ios_base::seekdir way,
49 ios_base::openmode which = ios_base::in | ios_base::out);
50 virtual pos_type seekpos(pos_type sp,
51 ios_base::openmode which = ios_base::in | ios_base::out);
52};
53
54template <class charT, class traits, class Allocator>
55 void swap(basic_stringbuf<charT, traits, Allocator>& x,
56 basic_stringbuf<charT, traits, Allocator>& y);
57
58typedef basic_stringbuf<char> stringbuf;
59typedef basic_stringbuf<wchar_t> wstringbuf;
60
61template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
62class basic_istringstream
63 : public basic_istream<charT, traits>
64{
65public:
66 typedef charT char_type;
67 typedef traits traits_type;
68 typedef typename traits_type::int_type int_type;
69 typedef typename traits_type::pos_type pos_type;
70 typedef typename traits_type::off_type off_type;
71 typedef Allocator allocator_type;
72
73 // 27.8.2.1 Constructors:
74 explicit basic_istringstream(ios_base::openmode which = ios_base::in);
75 explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str,
76 ios_base::openmode which = ios_base::in);
77 basic_istringstream(basic_istringstream&& rhs);
78
79 // 27.8.2.2 Assign and swap:
80 basic_istringstream& operator=(basic_istringstream&& rhs);
81 void swap(basic_istringstream& rhs);
82
83 // 27.8.2.3 Members:
84 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
85 basic_string<char_type, traits_type, allocator_type> str() const;
86 void str(const basic_string<char_type, traits_type, allocator_type>& s);
87};
88
89template <class charT, class traits, class Allocator>
90 void swap(basic_istringstream<charT, traits, Allocator>& x,
91 basic_istringstream<charT, traits, Allocator>& y);
92
93typedef basic_istringstream<char> istringstream;
94typedef basic_istringstream<wchar_t> wistringstream;
95
96template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
97class basic_ostringstream
98 : public basic_ostream<charT, traits>
99{
100public:
101 // types:
102 typedef charT char_type;
103 typedef traits traits_type;
104 typedef typename traits_type::int_type int_type;
105 typedef typename traits_type::pos_type pos_type;
106 typedef typename traits_type::off_type off_type;
107 typedef Allocator allocator_type;
108
109 // 27.8.3.1 Constructors/destructor:
110 explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
111 explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str,
112 ios_base::openmode which = ios_base::out);
113 basic_ostringstream(basic_ostringstream&& rhs);
114
115 // 27.8.3.2 Assign/swap:
116 basic_ostringstream& operator=(basic_ostringstream&& rhs);
117 void swap(basic_ostringstream& rhs);
118
119 // 27.8.3.3 Members:
120 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
121 basic_string<char_type, traits_type, allocator_type> str() const;
122 void str(const basic_string<char_type, traits_type, allocator_type>& s);
123};
124
125template <class charT, class traits, class Allocator>
126 void swap(basic_ostringstream<charT, traits, Allocator>& x,
127 basic_ostringstream<charT, traits, Allocator>& y);
128
129typedef basic_ostringstream<char> ostringstream;
130typedef basic_ostringstream<wchar_t> wostringstream;
131
132template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
133class basic_stringstream
134 : public basic_iostream<charT, traits>
135{
136public:
137 // types:
138 typedef charT char_type;
139 typedef traits traits_type;
140 typedef typename traits_type::int_type int_type;
141 typedef typename traits_type::pos_type pos_type;
142 typedef typename traits_type::off_type off_type;
143 typedef Allocator allocator_type;
144
145 // constructors/destructor
146 explicit basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in);
147 explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str,
148 ios_base::openmode which = ios_base::out|ios_base::in);
149 basic_stringstream(basic_stringstream&& rhs);
150
151 // 27.8.5.1 Assign/swap:
152 basic_stringstream& operator=(basic_stringstream&& rhs);
153 void swap(basic_stringstream& rhs);
154
155 // Members:
156 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
157 basic_string<char_type, traits_type, allocator_type> str() const;
158 void str(const basic_string<char_type, traits_type, allocator_type>& str);
159};
160
161template <class charT, class traits, class Allocator>
162 void swap(basic_stringstream<charT, traits, Allocator>& x,
163 basic_stringstream<charT, traits, Allocator>& y);
164
165typedef basic_stringstream<char> stringstream;
166typedef basic_stringstream<wchar_t> wstringstream;
167
168} // std
169
170*/
171
172#include <__config>
173#include <ostream>
174#include <istream>
175#include <string>
176
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000177#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000179#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180
Eric Fiselierf4433a32017-05-31 22:07:49 +0000181_LIBCPP_PUSH_MACROS
182#include <__undef_macros>
183
184
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185_LIBCPP_BEGIN_NAMESPACE_STD
186
187// basic_stringbuf
188
189template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000190class _LIBCPP_TEMPLATE_VIS basic_stringbuf
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191 : public basic_streambuf<_CharT, _Traits>
192{
193public:
194 typedef _CharT char_type;
195 typedef _Traits traits_type;
196 typedef typename traits_type::int_type int_type;
197 typedef typename traits_type::pos_type pos_type;
198 typedef typename traits_type::off_type off_type;
199 typedef _Allocator allocator_type;
200
201 typedef basic_string<char_type, traits_type, allocator_type> string_type;
202
203private:
204
205 string_type __str_;
206 mutable char_type* __hm_;
207 ios_base::openmode __mode_;
208
209public:
210 // 27.8.1.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000211 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000213 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214 explicit basic_stringbuf(const string_type& __s,
215 ios_base::openmode __wch = ios_base::in | ios_base::out);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216 basic_stringbuf(basic_stringbuf&& __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
218 // 27.8.1.2 Assign and swap:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 basic_stringbuf& operator=(basic_stringbuf&& __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220 void swap(basic_stringbuf& __rhs);
221
222 // 27.8.1.3 Get and set:
223 string_type str() const;
224 void str(const string_type& __s);
225
226protected:
227 // 27.8.1.4 Overridden virtual functions:
228 virtual int_type underflow();
229 virtual int_type pbackfail(int_type __c = traits_type::eof());
230 virtual int_type overflow (int_type __c = traits_type::eof());
231 virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
232 ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000233 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234 virtual pos_type seekpos(pos_type __sp,
235 ios_base::openmode __wch = ios_base::in | ios_base::out);
236};
237
238template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch)
240 : __hm_(0),
241 __mode_(__wch)
242{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243}
244
245template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s,
247 ios_base::openmode __wch)
Marshall Clowa3f7e062017-08-02 17:31:09 +0000248 : __str_(__s.get_allocator()),
249 __hm_(0),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 __mode_(__wch)
251{
252 str(__s);
253}
254
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255template <class _CharT, class _Traits, class _Allocator>
256basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs)
257 : __mode_(__rhs.__mode_)
258{
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000259 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
260 ptrdiff_t __binp = -1;
261 ptrdiff_t __ninp = -1;
262 ptrdiff_t __einp = -1;
263 if (__rhs.eback() != nullptr)
264 {
265 __binp = __rhs.eback() - __p;
266 __ninp = __rhs.gptr() - __p;
267 __einp = __rhs.egptr() - __p;
268 }
269 ptrdiff_t __bout = -1;
270 ptrdiff_t __nout = -1;
271 ptrdiff_t __eout = -1;
272 if (__rhs.pbase() != nullptr)
273 {
274 __bout = __rhs.pbase() - __p;
275 __nout = __rhs.pptr() - __p;
276 __eout = __rhs.epptr() - __p;
277 }
278 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000279 __str_ = _VSTD::move(__rhs.__str_);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000280 __p = const_cast<char_type*>(__str_.data());
281 if (__binp != -1)
282 this->setg(__p + __binp, __p + __ninp, __p + __einp);
283 if (__bout != -1)
284 {
285 this->setp(__p + __bout, __p + __eout);
Marshall Clow33932622017-09-12 15:00:43 +0000286 this->__pbump(__nout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000287 }
288 __hm_ = __hm == -1 ? nullptr : __p + __hm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 __p = const_cast<char_type*>(__rhs.__str_.data());
290 __rhs.setg(__p, __p, __p);
291 __rhs.setp(__p, __p);
292 __rhs.__hm_ = __p;
293 this->pubimbue(__rhs.getloc());
294}
295
296template <class _CharT, class _Traits, class _Allocator>
297basic_stringbuf<_CharT, _Traits, _Allocator>&
298basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
299{
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000300 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
301 ptrdiff_t __binp = -1;
302 ptrdiff_t __ninp = -1;
303 ptrdiff_t __einp = -1;
304 if (__rhs.eback() != nullptr)
305 {
306 __binp = __rhs.eback() - __p;
307 __ninp = __rhs.gptr() - __p;
308 __einp = __rhs.egptr() - __p;
309 }
310 ptrdiff_t __bout = -1;
311 ptrdiff_t __nout = -1;
312 ptrdiff_t __eout = -1;
313 if (__rhs.pbase() != nullptr)
314 {
315 __bout = __rhs.pbase() - __p;
316 __nout = __rhs.pptr() - __p;
317 __eout = __rhs.epptr() - __p;
318 }
319 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000320 __str_ = _VSTD::move(__rhs.__str_);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000321 __p = const_cast<char_type*>(__str_.data());
322 if (__binp != -1)
323 this->setg(__p + __binp, __p + __ninp, __p + __einp);
Marshall Clow45e157b2014-09-16 18:57:52 +0000324 else
325 this->setg(nullptr, nullptr, nullptr);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000326 if (__bout != -1)
327 {
328 this->setp(__p + __bout, __p + __eout);
Marshall Clow33932622017-09-12 15:00:43 +0000329 this->__pbump(__nout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000330 }
Marshall Clow45e157b2014-09-16 18:57:52 +0000331 else
332 this->setp(nullptr, nullptr);
333
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000334 __hm_ = __hm == -1 ? nullptr : __p + __hm;
335 __mode_ = __rhs.__mode_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 __p = const_cast<char_type*>(__rhs.__str_.data());
337 __rhs.setg(__p, __p, __p);
338 __rhs.setp(__p, __p);
339 __rhs.__hm_ = __p;
340 this->pubimbue(__rhs.getloc());
341 return *this;
342}
343
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344template <class _CharT, class _Traits, class _Allocator>
345void
346basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
347{
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000348 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
349 ptrdiff_t __rbinp = -1;
350 ptrdiff_t __rninp = -1;
351 ptrdiff_t __reinp = -1;
352 if (__rhs.eback() != nullptr)
353 {
354 __rbinp = __rhs.eback() - __p;
355 __rninp = __rhs.gptr() - __p;
356 __reinp = __rhs.egptr() - __p;
357 }
358 ptrdiff_t __rbout = -1;
359 ptrdiff_t __rnout = -1;
360 ptrdiff_t __reout = -1;
361 if (__rhs.pbase() != nullptr)
362 {
363 __rbout = __rhs.pbase() - __p;
364 __rnout = __rhs.pptr() - __p;
365 __reout = __rhs.epptr() - __p;
366 }
367 ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
368 __p = const_cast<char_type*>(__str_.data());
369 ptrdiff_t __lbinp = -1;
370 ptrdiff_t __lninp = -1;
371 ptrdiff_t __leinp = -1;
372 if (this->eback() != nullptr)
373 {
374 __lbinp = this->eback() - __p;
375 __lninp = this->gptr() - __p;
376 __leinp = this->egptr() - __p;
377 }
378 ptrdiff_t __lbout = -1;
379 ptrdiff_t __lnout = -1;
380 ptrdiff_t __leout = -1;
381 if (this->pbase() != nullptr)
382 {
383 __lbout = this->pbase() - __p;
384 __lnout = this->pptr() - __p;
385 __leout = this->epptr() - __p;
386 }
387 ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000388 _VSTD::swap(__mode_, __rhs.__mode_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389 __str_.swap(__rhs.__str_);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000390 __p = const_cast<char_type*>(__str_.data());
391 if (__rbinp != -1)
392 this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
393 else
394 this->setg(nullptr, nullptr, nullptr);
395 if (__rbout != -1)
396 {
397 this->setp(__p + __rbout, __p + __reout);
Marshall Clow33932622017-09-12 15:00:43 +0000398 this->__pbump(__rnout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000399 }
400 else
401 this->setp(nullptr, nullptr);
402 __hm_ = __rhm == -1 ? nullptr : __p + __rhm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 __p = const_cast<char_type*>(__rhs.__str_.data());
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000404 if (__lbinp != -1)
405 __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
406 else
407 __rhs.setg(nullptr, nullptr, nullptr);
408 if (__lbout != -1)
409 {
410 __rhs.setp(__p + __lbout, __p + __leout);
Marshall Clow33932622017-09-12 15:00:43 +0000411 __rhs.__pbump(__lnout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000412 }
413 else
414 __rhs.setp(nullptr, nullptr);
415 __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 locale __tl = __rhs.getloc();
417 __rhs.pubimbue(this->getloc());
418 this->pubimbue(__tl);
419}
420
421template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000422inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423void
424swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
425 basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
426{
427 __x.swap(__y);
428}
429
430template <class _CharT, class _Traits, class _Allocator>
431basic_string<_CharT, _Traits, _Allocator>
432basic_stringbuf<_CharT, _Traits, _Allocator>::str() const
433{
434 if (__mode_ & ios_base::out)
435 {
436 if (__hm_ < this->pptr())
437 __hm_ = this->pptr();
438 return string_type(this->pbase(), __hm_, __str_.get_allocator());
439 }
440 else if (__mode_ & ios_base::in)
441 return string_type(this->eback(), this->egptr(), __str_.get_allocator());
442 return string_type(__str_.get_allocator());
443}
444
445template <class _CharT, class _Traits, class _Allocator>
446void
447basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s)
448{
449 __str_ = __s;
450 __hm_ = 0;
451 if (__mode_ & ios_base::in)
452 {
453 __hm_ = const_cast<char_type*>(__str_.data()) + __str_.size();
454 this->setg(const_cast<char_type*>(__str_.data()),
455 const_cast<char_type*>(__str_.data()),
456 __hm_);
457 }
458 if (__mode_ & ios_base::out)
459 {
460 typename string_type::size_type __sz = __str_.size();
461 __hm_ = const_cast<char_type*>(__str_.data()) + __sz;
462 __str_.resize(__str_.capacity());
463 this->setp(const_cast<char_type*>(__str_.data()),
464 const_cast<char_type*>(__str_.data()) + __str_.size());
465 if (__mode_ & (ios_base::app | ios_base::ate))
Marshall Clow33932622017-09-12 15:00:43 +0000466 {
467 while (__sz > INT_MAX)
468 {
Louis Dionne44bcff92018-08-03 22:36:53 +0000469 this->pbump(INT_MAX);
470 __sz -= INT_MAX;
Marshall Clow33932622017-09-12 15:00:43 +0000471 }
472 if (__sz > 0)
Louis Dionne44bcff92018-08-03 22:36:53 +0000473 this->pbump(__sz);
474 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475 }
476}
477
478template <class _CharT, class _Traits, class _Allocator>
479typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
480basic_stringbuf<_CharT, _Traits, _Allocator>::underflow()
481{
482 if (__hm_ < this->pptr())
483 __hm_ = this->pptr();
484 if (__mode_ & ios_base::in)
485 {
486 if (this->egptr() < __hm_)
487 this->setg(this->eback(), this->gptr(), __hm_);
488 if (this->gptr() < this->egptr())
489 return traits_type::to_int_type(*this->gptr());
490 }
491 return traits_type::eof();
492}
493
494template <class _CharT, class _Traits, class _Allocator>
495typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
496basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c)
497{
498 if (__hm_ < this->pptr())
499 __hm_ = this->pptr();
500 if (this->eback() < this->gptr())
501 {
502 if (traits_type::eq_int_type(__c, traits_type::eof()))
503 {
504 this->setg(this->eback(), this->gptr()-1, __hm_);
505 return traits_type::not_eof(__c);
506 }
507 if ((__mode_ & ios_base::out) ||
508 traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
509 {
510 this->setg(this->eback(), this->gptr()-1, __hm_);
511 *this->gptr() = traits_type::to_char_type(__c);
512 return __c;
513 }
514 }
515 return traits_type::eof();
516}
517
518template <class _CharT, class _Traits, class _Allocator>
519typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
520basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c)
521{
522 if (!traits_type::eq_int_type(__c, traits_type::eof()))
523 {
524 ptrdiff_t __ninp = this->gptr() - this->eback();
525 if (this->pptr() == this->epptr())
526 {
527 if (!(__mode_ & ios_base::out))
528 return traits_type::eof();
529#ifndef _LIBCPP_NO_EXCEPTIONS
530 try
531 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000532#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 ptrdiff_t __nout = this->pptr() - this->pbase();
534 ptrdiff_t __hm = __hm_ - this->pbase();
535 __str_.push_back(char_type());
536 __str_.resize(__str_.capacity());
537 char_type* __p = const_cast<char_type*>(__str_.data());
538 this->setp(__p, __p + __str_.size());
Marshall Clow33932622017-09-12 15:00:43 +0000539 this->__pbump(__nout);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540 __hm_ = this->pbase() + __hm;
541#ifndef _LIBCPP_NO_EXCEPTIONS
542 }
543 catch (...)
544 {
545 return traits_type::eof();
546 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000547#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548 }
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000549 __hm_ = _VSTD::max(this->pptr() + 1, __hm_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550 if (__mode_ & ios_base::in)
551 {
552 char_type* __p = const_cast<char_type*>(__str_.data());
553 this->setg(__p, __p + __ninp, __hm_);
554 }
Marshall Clow5ca73ad2019-02-01 21:59:27 +0000555 return this->sputc(traits_type::to_char_type(__c));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556 }
557 return traits_type::not_eof(__c);
558}
559
560template <class _CharT, class _Traits, class _Allocator>
561typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
562basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
563 ios_base::seekdir __way,
564 ios_base::openmode __wch)
565{
566 if (__hm_ < this->pptr())
567 __hm_ = this->pptr();
568 if ((__wch & (ios_base::in | ios_base::out)) == 0)
569 return pos_type(-1);
570 if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)
571 && __way == ios_base::cur)
572 return pos_type(-1);
Peter Collingbourne28b5a562017-12-19 23:33:16 +0000573 const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 off_type __noff;
575 switch (__way)
576 {
577 case ios_base::beg:
578 __noff = 0;
579 break;
580 case ios_base::cur:
581 if (__wch & ios_base::in)
582 __noff = this->gptr() - this->eback();
583 else
584 __noff = this->pptr() - this->pbase();
585 break;
586 case ios_base::end:
Peter Collingbourne28b5a562017-12-19 23:33:16 +0000587 __noff = __hm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 break;
589 default:
590 return pos_type(-1);
591 }
592 __noff += __off;
Peter Collingbourne28b5a562017-12-19 23:33:16 +0000593 if (__noff < 0 || __hm < __noff)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 return pos_type(-1);
595 if (__noff != 0)
596 {
597 if ((__wch & ios_base::in) && this->gptr() == 0)
598 return pos_type(-1);
599 if ((__wch & ios_base::out) && this->pptr() == 0)
600 return pos_type(-1);
601 }
602 if (__wch & ios_base::in)
603 this->setg(this->eback(), this->eback() + __noff, __hm_);
604 if (__wch & ios_base::out)
605 {
606 this->setp(this->pbase(), this->epptr());
607 this->pbump(__noff);
608 }
609 return pos_type(__noff);
610}
611
612template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
614basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp,
615 ios_base::openmode __wch)
616{
617 return seekoff(__sp, ios_base::beg, __wch);
618}
619
620// basic_istringstream
621
622template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000623class _LIBCPP_TEMPLATE_VIS basic_istringstream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624 : public basic_istream<_CharT, _Traits>
625{
626public:
627 typedef _CharT char_type;
628 typedef _Traits traits_type;
629 typedef typename traits_type::int_type int_type;
630 typedef typename traits_type::pos_type pos_type;
631 typedef typename traits_type::off_type off_type;
632 typedef _Allocator allocator_type;
633
634 typedef basic_string<char_type, traits_type, allocator_type> string_type;
635
636private:
637 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
638
639public:
640 // 27.8.2.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000641 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 explicit basic_istringstream(ios_base::openmode __wch = ios_base::in);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000643 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 explicit basic_istringstream(const string_type& __s,
645 ios_base::openmode __wch = ios_base::in);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000646 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647 basic_istringstream(basic_istringstream&& __rhs);
648
649 // 27.8.2.2 Assign and swap:
650 basic_istringstream& operator=(basic_istringstream&& __rhs);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000651 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652 void swap(basic_istringstream& __rhs);
653
654 // 27.8.2.3 Members:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000655 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000657 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 string_type str() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000659 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 void str(const string_type& __s);
661};
662
663template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch)
665 : basic_istream<_CharT, _Traits>(&__sb_),
666 __sb_(__wch | ios_base::in)
667{
668}
669
670template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s,
672 ios_base::openmode __wch)
673 : basic_istream<_CharT, _Traits>(&__sb_),
674 __sb_(__s, __wch | ios_base::in)
675{
676}
677
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000680 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)),
681 __sb_(_VSTD::move(__rhs.__sb_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682{
683 basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
684}
685
686template <class _CharT, class _Traits, class _Allocator>
687basic_istringstream<_CharT, _Traits, _Allocator>&
688basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream&& __rhs)
689{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000690 basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
691 __sb_ = _VSTD::move(__rhs.__sb_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 return *this;
693}
694
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000696void basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697{
698 basic_istream<char_type, traits_type>::swap(__rhs);
699 __sb_.swap(__rhs.__sb_);
700}
701
702template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704void
705swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
706 basic_istringstream<_CharT, _Traits, _Allocator>& __y)
707{
708 __x.swap(__y);
709}
710
711template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712basic_stringbuf<_CharT, _Traits, _Allocator>*
713basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const
714{
715 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
716}
717
718template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719basic_string<_CharT, _Traits, _Allocator>
720basic_istringstream<_CharT, _Traits, _Allocator>::str() const
721{
722 return __sb_.str();
723}
724
725template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000726void basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727{
728 __sb_.str(__s);
729}
730
731// basic_ostringstream
732
733template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000734class _LIBCPP_TEMPLATE_VIS basic_ostringstream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 : public basic_ostream<_CharT, _Traits>
736{
737public:
738 typedef _CharT char_type;
739 typedef _Traits traits_type;
740 typedef typename traits_type::int_type int_type;
741 typedef typename traits_type::pos_type pos_type;
742 typedef typename traits_type::off_type off_type;
743 typedef _Allocator allocator_type;
744
745 typedef basic_string<char_type, traits_type, allocator_type> string_type;
746
747private:
748 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
749
750public:
751 // 27.8.2.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000752 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000754 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755 explicit basic_ostringstream(const string_type& __s,
756 ios_base::openmode __wch = ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000757 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758 basic_ostringstream(basic_ostringstream&& __rhs);
759
760 // 27.8.2.2 Assign and swap:
761 basic_ostringstream& operator=(basic_ostringstream&& __rhs);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000762 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 void swap(basic_ostringstream& __rhs);
764
765 // 27.8.2.3 Members:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000766 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000768 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 string_type str() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000770 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771 void str(const string_type& __s);
772};
773
774template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch)
776 : basic_ostream<_CharT, _Traits>(&__sb_),
777 __sb_(__wch | ios_base::out)
778{
779}
780
781template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s,
783 ios_base::openmode __wch)
784 : basic_ostream<_CharT, _Traits>(&__sb_),
785 __sb_(__s, __wch | ios_base::out)
786{
787}
788
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000791 : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)),
792 __sb_(_VSTD::move(__rhs.__sb_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793{
794 basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
795}
796
797template <class _CharT, class _Traits, class _Allocator>
798basic_ostringstream<_CharT, _Traits, _Allocator>&
799basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream&& __rhs)
800{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000801 basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
802 __sb_ = _VSTD::move(__rhs.__sb_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 return *this;
804}
805
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807void
808basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs)
809{
810 basic_ostream<char_type, traits_type>::swap(__rhs);
811 __sb_.swap(__rhs.__sb_);
812}
813
814template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000815inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816void
817swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
818 basic_ostringstream<_CharT, _Traits, _Allocator>& __y)
819{
820 __x.swap(__y);
821}
822
823template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824basic_stringbuf<_CharT, _Traits, _Allocator>*
825basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const
826{
827 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
828}
829
830template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831basic_string<_CharT, _Traits, _Allocator>
832basic_ostringstream<_CharT, _Traits, _Allocator>::str() const
833{
834 return __sb_.str();
835}
836
837template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838void
839basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
840{
841 __sb_.str(__s);
842}
843
844// basic_stringstream
845
846template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000847class _LIBCPP_TEMPLATE_VIS basic_stringstream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848 : public basic_iostream<_CharT, _Traits>
849{
850public:
851 typedef _CharT char_type;
852 typedef _Traits traits_type;
853 typedef typename traits_type::int_type int_type;
854 typedef typename traits_type::pos_type pos_type;
855 typedef typename traits_type::off_type off_type;
856 typedef _Allocator allocator_type;
857
858 typedef basic_string<char_type, traits_type, allocator_type> string_type;
859
860private:
861 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
862
863public:
864 // 27.8.2.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000865 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000867 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 explicit basic_stringstream(const string_type& __s,
869 ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000870 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 basic_stringstream(basic_stringstream&& __rhs);
872
873 // 27.8.2.2 Assign and swap:
874 basic_stringstream& operator=(basic_stringstream&& __rhs);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000875 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876 void swap(basic_stringstream& __rhs);
877
878 // 27.8.2.3 Members:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000879 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000881 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 string_type str() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000883 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 void str(const string_type& __s);
885};
886
887template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch)
889 : basic_iostream<_CharT, _Traits>(&__sb_),
890 __sb_(__wch)
891{
892}
893
894template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s,
896 ios_base::openmode __wch)
897 : basic_iostream<_CharT, _Traits>(&__sb_),
898 __sb_(__s, __wch)
899{
900}
901
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000904 : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)),
905 __sb_(_VSTD::move(__rhs.__sb_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906{
907 basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
908}
909
910template <class _CharT, class _Traits, class _Allocator>
911basic_stringstream<_CharT, _Traits, _Allocator>&
912basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& __rhs)
913{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000914 basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
915 __sb_ = _VSTD::move(__rhs.__sb_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 return *this;
917}
918
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920void
921basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs)
922{
923 basic_iostream<char_type, traits_type>::swap(__rhs);
924 __sb_.swap(__rhs.__sb_);
925}
926
927template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929void
930swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
931 basic_stringstream<_CharT, _Traits, _Allocator>& __y)
932{
933 __x.swap(__y);
934}
935
936template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937basic_stringbuf<_CharT, _Traits, _Allocator>*
938basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const
939{
940 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
941}
942
943template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944basic_string<_CharT, _Traits, _Allocator>
945basic_stringstream<_CharT, _Traits, _Allocator>::str() const
946{
947 return __sb_.str();
948}
949
950template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951void
952basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
953{
954 __sb_.str(__s);
955}
956
957_LIBCPP_END_NAMESPACE_STD
958
Eric Fiselierf4433a32017-05-31 22:07:49 +0000959_LIBCPP_POP_MACROS
960
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961#endif // _LIBCPP_SSTREAM