blob: 34b0014c14ada02f5a1305a0b28220864fc6c75d [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- sstream ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SSTREAM
12#define _LIBCPP_SSTREAM
13
14/*
15 sstream synopsis
16
17template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
18class basic_stringbuf
19 : public basic_streambuf<charT, traits>
20{
21public:
22 typedef charT char_type;
23 typedef traits traits_type;
24 typedef typename traits_type::int_type int_type;
25 typedef typename traits_type::pos_type pos_type;
26 typedef typename traits_type::off_type off_type;
27 typedef Allocator allocator_type;
28
29 // 27.8.1.1 Constructors:
30 explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out);
31 explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str,
32 ios_base::openmode which = ios_base::in | ios_base::out);
33 basic_stringbuf(basic_stringbuf&& rhs);
34
35 // 27.8.1.2 Assign and swap:
36 basic_stringbuf& operator=(basic_stringbuf&& rhs);
37 void swap(basic_stringbuf& rhs);
38
39 // 27.8.1.3 Get and set:
40 basic_string<char_type, traits_type, allocator_type> str() const;
41 void str(const basic_string<char_type, traits_type, allocator_type>& s);
42
43protected:
44 // 27.8.1.4 Overridden virtual functions:
45 virtual int_type underflow();
46 virtual int_type pbackfail(int_type c = traits_type::eof());
47 virtual int_type overflow (int_type c = traits_type::eof());
48 virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize);
49 virtual pos_type seekoff(off_type off, ios_base::seekdir way,
50 ios_base::openmode which = ios_base::in | ios_base::out);
51 virtual pos_type seekpos(pos_type sp,
52 ios_base::openmode which = ios_base::in | ios_base::out);
53};
54
55template <class charT, class traits, class Allocator>
56 void swap(basic_stringbuf<charT, traits, Allocator>& x,
57 basic_stringbuf<charT, traits, Allocator>& y);
58
59typedef basic_stringbuf<char> stringbuf;
60typedef basic_stringbuf<wchar_t> wstringbuf;
61
62template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
63class basic_istringstream
64 : public basic_istream<charT, traits>
65{
66public:
67 typedef charT char_type;
68 typedef traits traits_type;
69 typedef typename traits_type::int_type int_type;
70 typedef typename traits_type::pos_type pos_type;
71 typedef typename traits_type::off_type off_type;
72 typedef Allocator allocator_type;
73
74 // 27.8.2.1 Constructors:
75 explicit basic_istringstream(ios_base::openmode which = ios_base::in);
76 explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str,
77 ios_base::openmode which = ios_base::in);
78 basic_istringstream(basic_istringstream&& rhs);
79
80 // 27.8.2.2 Assign and swap:
81 basic_istringstream& operator=(basic_istringstream&& rhs);
82 void swap(basic_istringstream& rhs);
83
84 // 27.8.2.3 Members:
85 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
86 basic_string<char_type, traits_type, allocator_type> str() const;
87 void str(const basic_string<char_type, traits_type, allocator_type>& s);
88};
89
90template <class charT, class traits, class Allocator>
91 void swap(basic_istringstream<charT, traits, Allocator>& x,
92 basic_istringstream<charT, traits, Allocator>& y);
93
94typedef basic_istringstream<char> istringstream;
95typedef basic_istringstream<wchar_t> wistringstream;
96
97template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
98class basic_ostringstream
99 : public basic_ostream<charT, traits>
100{
101public:
102 // types:
103 typedef charT char_type;
104 typedef traits traits_type;
105 typedef typename traits_type::int_type int_type;
106 typedef typename traits_type::pos_type pos_type;
107 typedef typename traits_type::off_type off_type;
108 typedef Allocator allocator_type;
109
110 // 27.8.3.1 Constructors/destructor:
111 explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
112 explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str,
113 ios_base::openmode which = ios_base::out);
114 basic_ostringstream(basic_ostringstream&& rhs);
115
116 // 27.8.3.2 Assign/swap:
117 basic_ostringstream& operator=(basic_ostringstream&& rhs);
118 void swap(basic_ostringstream& rhs);
119
120 // 27.8.3.3 Members:
121 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
122 basic_string<char_type, traits_type, allocator_type> str() const;
123 void str(const basic_string<char_type, traits_type, allocator_type>& s);
124};
125
126template <class charT, class traits, class Allocator>
127 void swap(basic_ostringstream<charT, traits, Allocator>& x,
128 basic_ostringstream<charT, traits, Allocator>& y);
129
130typedef basic_ostringstream<char> ostringstream;
131typedef basic_ostringstream<wchar_t> wostringstream;
132
133template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
134class basic_stringstream
135 : public basic_iostream<charT, traits>
136{
137public:
138 // types:
139 typedef charT char_type;
140 typedef traits traits_type;
141 typedef typename traits_type::int_type int_type;
142 typedef typename traits_type::pos_type pos_type;
143 typedef typename traits_type::off_type off_type;
144 typedef Allocator allocator_type;
145
146 // constructors/destructor
147 explicit basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in);
148 explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str,
149 ios_base::openmode which = ios_base::out|ios_base::in);
150 basic_stringstream(basic_stringstream&& rhs);
151
152 // 27.8.5.1 Assign/swap:
153 basic_stringstream& operator=(basic_stringstream&& rhs);
154 void swap(basic_stringstream& rhs);
155
156 // Members:
157 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
158 basic_string<char_type, traits_type, allocator_type> str() const;
159 void str(const basic_string<char_type, traits_type, allocator_type>& str);
160};
161
162template <class charT, class traits, class Allocator>
163 void swap(basic_stringstream<charT, traits, Allocator>& x,
164 basic_stringstream<charT, traits, Allocator>& y);
165
166typedef basic_stringstream<char> stringstream;
167typedef basic_stringstream<wchar_t> wstringstream;
168
169} // std
170
171*/
172
173#include <__config>
174#include <ostream>
175#include <istream>
176#include <string>
177
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000178#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000180#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181
Eric Fiselierf4433a32017-05-31 22:07:49 +0000182_LIBCPP_PUSH_MACROS
183#include <__undef_macros>
184
185
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186_LIBCPP_BEGIN_NAMESPACE_STD
187
188// basic_stringbuf
189
190template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000191class _LIBCPP_TEMPLATE_VIS basic_stringbuf
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 : public basic_streambuf<_CharT, _Traits>
193{
194public:
195 typedef _CharT char_type;
196 typedef _Traits traits_type;
197 typedef typename traits_type::int_type int_type;
198 typedef typename traits_type::pos_type pos_type;
199 typedef typename traits_type::off_type off_type;
200 typedef _Allocator allocator_type;
201
202 typedef basic_string<char_type, traits_type, allocator_type> string_type;
203
204private:
205
206 string_type __str_;
207 mutable char_type* __hm_;
208 ios_base::openmode __mode_;
209
210public:
211 // 27.8.1.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000212 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000214 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215 explicit basic_stringbuf(const string_type& __s,
216 ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000217#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218 basic_stringbuf(basic_stringbuf&& __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219
220 // 27.8.1.2 Assign and swap:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 basic_stringbuf& operator=(basic_stringbuf&& __rhs);
222#endif
223 void swap(basic_stringbuf& __rhs);
224
225 // 27.8.1.3 Get and set:
226 string_type str() const;
227 void str(const string_type& __s);
228
229protected:
230 // 27.8.1.4 Overridden virtual functions:
231 virtual int_type underflow();
232 virtual int_type pbackfail(int_type __c = traits_type::eof());
233 virtual int_type overflow (int_type __c = traits_type::eof());
234 virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
235 ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000236 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 virtual pos_type seekpos(pos_type __sp,
238 ios_base::openmode __wch = ios_base::in | ios_base::out);
239};
240
241template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch)
243 : __hm_(0),
244 __mode_(__wch)
245{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246}
247
248template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s,
250 ios_base::openmode __wch)
Marshall Clowa3f7e062017-08-02 17:31:09 +0000251 : __str_(__s.get_allocator()),
252 __hm_(0),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 __mode_(__wch)
254{
255 str(__s);
256}
257
Eric Fiselier78ccf772017-04-18 23:38:41 +0000258#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259
260template <class _CharT, class _Traits, class _Allocator>
261basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs)
262 : __mode_(__rhs.__mode_)
263{
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000264 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
265 ptrdiff_t __binp = -1;
266 ptrdiff_t __ninp = -1;
267 ptrdiff_t __einp = -1;
268 if (__rhs.eback() != nullptr)
269 {
270 __binp = __rhs.eback() - __p;
271 __ninp = __rhs.gptr() - __p;
272 __einp = __rhs.egptr() - __p;
273 }
274 ptrdiff_t __bout = -1;
275 ptrdiff_t __nout = -1;
276 ptrdiff_t __eout = -1;
277 if (__rhs.pbase() != nullptr)
278 {
279 __bout = __rhs.pbase() - __p;
280 __nout = __rhs.pptr() - __p;
281 __eout = __rhs.epptr() - __p;
282 }
283 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000284 __str_ = _VSTD::move(__rhs.__str_);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000285 __p = const_cast<char_type*>(__str_.data());
286 if (__binp != -1)
287 this->setg(__p + __binp, __p + __ninp, __p + __einp);
288 if (__bout != -1)
289 {
290 this->setp(__p + __bout, __p + __eout);
Marshall Clow33932622017-09-12 15:00:43 +0000291 this->__pbump(__nout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000292 }
293 __hm_ = __hm == -1 ? nullptr : __p + __hm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 __p = const_cast<char_type*>(__rhs.__str_.data());
295 __rhs.setg(__p, __p, __p);
296 __rhs.setp(__p, __p);
297 __rhs.__hm_ = __p;
298 this->pubimbue(__rhs.getloc());
299}
300
301template <class _CharT, class _Traits, class _Allocator>
302basic_stringbuf<_CharT, _Traits, _Allocator>&
303basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
304{
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000305 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
306 ptrdiff_t __binp = -1;
307 ptrdiff_t __ninp = -1;
308 ptrdiff_t __einp = -1;
309 if (__rhs.eback() != nullptr)
310 {
311 __binp = __rhs.eback() - __p;
312 __ninp = __rhs.gptr() - __p;
313 __einp = __rhs.egptr() - __p;
314 }
315 ptrdiff_t __bout = -1;
316 ptrdiff_t __nout = -1;
317 ptrdiff_t __eout = -1;
318 if (__rhs.pbase() != nullptr)
319 {
320 __bout = __rhs.pbase() - __p;
321 __nout = __rhs.pptr() - __p;
322 __eout = __rhs.epptr() - __p;
323 }
324 ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000325 __str_ = _VSTD::move(__rhs.__str_);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000326 __p = const_cast<char_type*>(__str_.data());
327 if (__binp != -1)
328 this->setg(__p + __binp, __p + __ninp, __p + __einp);
Marshall Clow45e157b2014-09-16 18:57:52 +0000329 else
330 this->setg(nullptr, nullptr, nullptr);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000331 if (__bout != -1)
332 {
333 this->setp(__p + __bout, __p + __eout);
Marshall Clow33932622017-09-12 15:00:43 +0000334 this->__pbump(__nout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000335 }
Marshall Clow45e157b2014-09-16 18:57:52 +0000336 else
337 this->setp(nullptr, nullptr);
338
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000339 __hm_ = __hm == -1 ? nullptr : __p + __hm;
340 __mode_ = __rhs.__mode_;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341 __p = const_cast<char_type*>(__rhs.__str_.data());
342 __rhs.setg(__p, __p, __p);
343 __rhs.setp(__p, __p);
344 __rhs.__hm_ = __p;
345 this->pubimbue(__rhs.getloc());
346 return *this;
347}
348
Eric Fiselier78ccf772017-04-18 23:38:41 +0000349#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350
351template <class _CharT, class _Traits, class _Allocator>
352void
353basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
354{
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000355 char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
356 ptrdiff_t __rbinp = -1;
357 ptrdiff_t __rninp = -1;
358 ptrdiff_t __reinp = -1;
359 if (__rhs.eback() != nullptr)
360 {
361 __rbinp = __rhs.eback() - __p;
362 __rninp = __rhs.gptr() - __p;
363 __reinp = __rhs.egptr() - __p;
364 }
365 ptrdiff_t __rbout = -1;
366 ptrdiff_t __rnout = -1;
367 ptrdiff_t __reout = -1;
368 if (__rhs.pbase() != nullptr)
369 {
370 __rbout = __rhs.pbase() - __p;
371 __rnout = __rhs.pptr() - __p;
372 __reout = __rhs.epptr() - __p;
373 }
374 ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
375 __p = const_cast<char_type*>(__str_.data());
376 ptrdiff_t __lbinp = -1;
377 ptrdiff_t __lninp = -1;
378 ptrdiff_t __leinp = -1;
379 if (this->eback() != nullptr)
380 {
381 __lbinp = this->eback() - __p;
382 __lninp = this->gptr() - __p;
383 __leinp = this->egptr() - __p;
384 }
385 ptrdiff_t __lbout = -1;
386 ptrdiff_t __lnout = -1;
387 ptrdiff_t __leout = -1;
388 if (this->pbase() != nullptr)
389 {
390 __lbout = this->pbase() - __p;
391 __lnout = this->pptr() - __p;
392 __leout = this->epptr() - __p;
393 }
394 ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000395 _VSTD::swap(__mode_, __rhs.__mode_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 __str_.swap(__rhs.__str_);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000397 __p = const_cast<char_type*>(__str_.data());
398 if (__rbinp != -1)
399 this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
400 else
401 this->setg(nullptr, nullptr, nullptr);
402 if (__rbout != -1)
403 {
404 this->setp(__p + __rbout, __p + __reout);
Marshall Clow33932622017-09-12 15:00:43 +0000405 this->__pbump(__rnout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000406 }
407 else
408 this->setp(nullptr, nullptr);
409 __hm_ = __rhm == -1 ? nullptr : __p + __rhm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 __p = const_cast<char_type*>(__rhs.__str_.data());
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000411 if (__lbinp != -1)
412 __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
413 else
414 __rhs.setg(nullptr, nullptr, nullptr);
415 if (__lbout != -1)
416 {
417 __rhs.setp(__p + __lbout, __p + __leout);
Marshall Clow33932622017-09-12 15:00:43 +0000418 __rhs.__pbump(__lnout);
Howard Hinnantd6d6e102013-04-03 20:21:29 +0000419 }
420 else
421 __rhs.setp(nullptr, nullptr);
422 __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 locale __tl = __rhs.getloc();
424 __rhs.pubimbue(this->getloc());
425 this->pubimbue(__tl);
426}
427
428template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000429inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430void
431swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
432 basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
433{
434 __x.swap(__y);
435}
436
437template <class _CharT, class _Traits, class _Allocator>
438basic_string<_CharT, _Traits, _Allocator>
439basic_stringbuf<_CharT, _Traits, _Allocator>::str() const
440{
441 if (__mode_ & ios_base::out)
442 {
443 if (__hm_ < this->pptr())
444 __hm_ = this->pptr();
445 return string_type(this->pbase(), __hm_, __str_.get_allocator());
446 }
447 else if (__mode_ & ios_base::in)
448 return string_type(this->eback(), this->egptr(), __str_.get_allocator());
449 return string_type(__str_.get_allocator());
450}
451
452template <class _CharT, class _Traits, class _Allocator>
453void
454basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s)
455{
456 __str_ = __s;
457 __hm_ = 0;
458 if (__mode_ & ios_base::in)
459 {
460 __hm_ = const_cast<char_type*>(__str_.data()) + __str_.size();
461 this->setg(const_cast<char_type*>(__str_.data()),
462 const_cast<char_type*>(__str_.data()),
463 __hm_);
464 }
465 if (__mode_ & ios_base::out)
466 {
467 typename string_type::size_type __sz = __str_.size();
468 __hm_ = const_cast<char_type*>(__str_.data()) + __sz;
469 __str_.resize(__str_.capacity());
470 this->setp(const_cast<char_type*>(__str_.data()),
471 const_cast<char_type*>(__str_.data()) + __str_.size());
472 if (__mode_ & (ios_base::app | ios_base::ate))
Marshall Clow33932622017-09-12 15:00:43 +0000473 {
474 while (__sz > INT_MAX)
475 {
476 this->pbump(INT_MAX);
477 __sz -= INT_MAX;
478 }
479 if (__sz > 0)
480 this->pbump(__sz);
481 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 }
483}
484
485template <class _CharT, class _Traits, class _Allocator>
486typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
487basic_stringbuf<_CharT, _Traits, _Allocator>::underflow()
488{
489 if (__hm_ < this->pptr())
490 __hm_ = this->pptr();
491 if (__mode_ & ios_base::in)
492 {
493 if (this->egptr() < __hm_)
494 this->setg(this->eback(), this->gptr(), __hm_);
495 if (this->gptr() < this->egptr())
496 return traits_type::to_int_type(*this->gptr());
497 }
498 return traits_type::eof();
499}
500
501template <class _CharT, class _Traits, class _Allocator>
502typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
503basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c)
504{
505 if (__hm_ < this->pptr())
506 __hm_ = this->pptr();
507 if (this->eback() < this->gptr())
508 {
509 if (traits_type::eq_int_type(__c, traits_type::eof()))
510 {
511 this->setg(this->eback(), this->gptr()-1, __hm_);
512 return traits_type::not_eof(__c);
513 }
514 if ((__mode_ & ios_base::out) ||
515 traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
516 {
517 this->setg(this->eback(), this->gptr()-1, __hm_);
518 *this->gptr() = traits_type::to_char_type(__c);
519 return __c;
520 }
521 }
522 return traits_type::eof();
523}
524
525template <class _CharT, class _Traits, class _Allocator>
526typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
527basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c)
528{
529 if (!traits_type::eq_int_type(__c, traits_type::eof()))
530 {
531 ptrdiff_t __ninp = this->gptr() - this->eback();
532 if (this->pptr() == this->epptr())
533 {
534 if (!(__mode_ & ios_base::out))
535 return traits_type::eof();
536#ifndef _LIBCPP_NO_EXCEPTIONS
537 try
538 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000539#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540 ptrdiff_t __nout = this->pptr() - this->pbase();
541 ptrdiff_t __hm = __hm_ - this->pbase();
542 __str_.push_back(char_type());
543 __str_.resize(__str_.capacity());
544 char_type* __p = const_cast<char_type*>(__str_.data());
545 this->setp(__p, __p + __str_.size());
Marshall Clow33932622017-09-12 15:00:43 +0000546 this->__pbump(__nout);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547 __hm_ = this->pbase() + __hm;
548#ifndef _LIBCPP_NO_EXCEPTIONS
549 }
550 catch (...)
551 {
552 return traits_type::eof();
553 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000554#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 }
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000556 __hm_ = _VSTD::max(this->pptr() + 1, __hm_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 if (__mode_ & ios_base::in)
558 {
559 char_type* __p = const_cast<char_type*>(__str_.data());
560 this->setg(__p, __p + __ninp, __hm_);
561 }
562 return this->sputc(__c);
563 }
564 return traits_type::not_eof(__c);
565}
566
567template <class _CharT, class _Traits, class _Allocator>
568typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
569basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
570 ios_base::seekdir __way,
571 ios_base::openmode __wch)
572{
573 if (__hm_ < this->pptr())
574 __hm_ = this->pptr();
575 if ((__wch & (ios_base::in | ios_base::out)) == 0)
576 return pos_type(-1);
577 if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)
578 && __way == ios_base::cur)
579 return pos_type(-1);
580 off_type __noff;
581 switch (__way)
582 {
583 case ios_base::beg:
584 __noff = 0;
585 break;
586 case ios_base::cur:
587 if (__wch & ios_base::in)
588 __noff = this->gptr() - this->eback();
589 else
590 __noff = this->pptr() - this->pbase();
591 break;
592 case ios_base::end:
593 __noff = __hm_ - __str_.data();
594 break;
595 default:
596 return pos_type(-1);
597 }
598 __noff += __off;
599 if (__noff < 0 || __hm_ - __str_.data() < __noff)
600 return pos_type(-1);
601 if (__noff != 0)
602 {
603 if ((__wch & ios_base::in) && this->gptr() == 0)
604 return pos_type(-1);
605 if ((__wch & ios_base::out) && this->pptr() == 0)
606 return pos_type(-1);
607 }
608 if (__wch & ios_base::in)
609 this->setg(this->eback(), this->eback() + __noff, __hm_);
610 if (__wch & ios_base::out)
611 {
612 this->setp(this->pbase(), this->epptr());
613 this->pbump(__noff);
614 }
615 return pos_type(__noff);
616}
617
618template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
620basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp,
621 ios_base::openmode __wch)
622{
623 return seekoff(__sp, ios_base::beg, __wch);
624}
625
626// basic_istringstream
627
628template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000629class _LIBCPP_TEMPLATE_VIS basic_istringstream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630 : public basic_istream<_CharT, _Traits>
631{
632public:
633 typedef _CharT char_type;
634 typedef _Traits traits_type;
635 typedef typename traits_type::int_type int_type;
636 typedef typename traits_type::pos_type pos_type;
637 typedef typename traits_type::off_type off_type;
638 typedef _Allocator allocator_type;
639
640 typedef basic_string<char_type, traits_type, allocator_type> string_type;
641
642private:
643 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
644
645public:
646 // 27.8.2.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000647 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 explicit basic_istringstream(ios_base::openmode __wch = ios_base::in);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000649 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 explicit basic_istringstream(const string_type& __s,
651 ios_base::openmode __wch = ios_base::in);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000652#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000653 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 basic_istringstream(basic_istringstream&& __rhs);
655
656 // 27.8.2.2 Assign and swap:
657 basic_istringstream& operator=(basic_istringstream&& __rhs);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000658#endif // _LIBCPP_CXX03_LANG
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000659 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 void swap(basic_istringstream& __rhs);
661
662 // 27.8.2.3 Members:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000663 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000665 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 string_type str() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000667 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668 void str(const string_type& __s);
669};
670
671template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch)
673 : basic_istream<_CharT, _Traits>(&__sb_),
674 __sb_(__wch | ios_base::in)
675{
676}
677
678template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s,
680 ios_base::openmode __wch)
681 : basic_istream<_CharT, _Traits>(&__sb_),
682 __sb_(__s, __wch | ios_base::in)
683{
684}
685
Eric Fiselier78ccf772017-04-18 23:38:41 +0000686#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687
688template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000690 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)),
691 __sb_(_VSTD::move(__rhs.__sb_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692{
693 basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
694}
695
696template <class _CharT, class _Traits, class _Allocator>
697basic_istringstream<_CharT, _Traits, _Allocator>&
698basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream&& __rhs)
699{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000700 basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
701 __sb_ = _VSTD::move(__rhs.__sb_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 return *this;
703}
704
Eric Fiselier78ccf772017-04-18 23:38:41 +0000705#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706
707template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000708void basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709{
710 basic_istream<char_type, traits_type>::swap(__rhs);
711 __sb_.swap(__rhs.__sb_);
712}
713
714template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000715inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716void
717swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
718 basic_istringstream<_CharT, _Traits, _Allocator>& __y)
719{
720 __x.swap(__y);
721}
722
723template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724basic_stringbuf<_CharT, _Traits, _Allocator>*
725basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const
726{
727 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
728}
729
730template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731basic_string<_CharT, _Traits, _Allocator>
732basic_istringstream<_CharT, _Traits, _Allocator>::str() const
733{
734 return __sb_.str();
735}
736
737template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000738void basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739{
740 __sb_.str(__s);
741}
742
743// basic_ostringstream
744
745template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000746class _LIBCPP_TEMPLATE_VIS basic_ostringstream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747 : public basic_ostream<_CharT, _Traits>
748{
749public:
750 typedef _CharT char_type;
751 typedef _Traits traits_type;
752 typedef typename traits_type::int_type int_type;
753 typedef typename traits_type::pos_type pos_type;
754 typedef typename traits_type::off_type off_type;
755 typedef _Allocator allocator_type;
756
757 typedef basic_string<char_type, traits_type, allocator_type> string_type;
758
759private:
760 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
761
762public:
763 // 27.8.2.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000764 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000766 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767 explicit basic_ostringstream(const string_type& __s,
768 ios_base::openmode __wch = ios_base::out);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000769#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000770 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771 basic_ostringstream(basic_ostringstream&& __rhs);
772
773 // 27.8.2.2 Assign and swap:
774 basic_ostringstream& operator=(basic_ostringstream&& __rhs);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000775#endif // _LIBCPP_CXX03_LANG
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000776 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777 void swap(basic_ostringstream& __rhs);
778
779 // 27.8.2.3 Members:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000780 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000782 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 string_type str() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000784 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 void str(const string_type& __s);
786};
787
788template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch)
790 : basic_ostream<_CharT, _Traits>(&__sb_),
791 __sb_(__wch | ios_base::out)
792{
793}
794
795template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s,
797 ios_base::openmode __wch)
798 : basic_ostream<_CharT, _Traits>(&__sb_),
799 __sb_(__s, __wch | ios_base::out)
800{
801}
802
Eric Fiselier78ccf772017-04-18 23:38:41 +0000803#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804
805template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000807 : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)),
808 __sb_(_VSTD::move(__rhs.__sb_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809{
810 basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
811}
812
813template <class _CharT, class _Traits, class _Allocator>
814basic_ostringstream<_CharT, _Traits, _Allocator>&
815basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream&& __rhs)
816{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000817 basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
818 __sb_ = _VSTD::move(__rhs.__sb_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 return *this;
820}
821
Eric Fiselier78ccf772017-04-18 23:38:41 +0000822#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823
824template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825void
826basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs)
827{
828 basic_ostream<char_type, traits_type>::swap(__rhs);
829 __sb_.swap(__rhs.__sb_);
830}
831
832template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834void
835swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
836 basic_ostringstream<_CharT, _Traits, _Allocator>& __y)
837{
838 __x.swap(__y);
839}
840
841template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842basic_stringbuf<_CharT, _Traits, _Allocator>*
843basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const
844{
845 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
846}
847
848template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849basic_string<_CharT, _Traits, _Allocator>
850basic_ostringstream<_CharT, _Traits, _Allocator>::str() const
851{
852 return __sb_.str();
853}
854
855template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856void
857basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
858{
859 __sb_.str(__s);
860}
861
862// basic_stringstream
863
864template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000865class _LIBCPP_TEMPLATE_VIS basic_stringstream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 : public basic_iostream<_CharT, _Traits>
867{
868public:
869 typedef _CharT char_type;
870 typedef _Traits traits_type;
871 typedef typename traits_type::int_type int_type;
872 typedef typename traits_type::pos_type pos_type;
873 typedef typename traits_type::off_type off_type;
874 typedef _Allocator allocator_type;
875
876 typedef basic_string<char_type, traits_type, allocator_type> string_type;
877
878private:
879 basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
880
881public:
882 // 27.8.2.1 Constructors:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000883 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000885 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 explicit basic_stringstream(const string_type& __s,
887 ios_base::openmode __wch = ios_base::in | ios_base::out);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000888#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000889 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 basic_stringstream(basic_stringstream&& __rhs);
891
892 // 27.8.2.2 Assign and swap:
893 basic_stringstream& operator=(basic_stringstream&& __rhs);
Eric Fiselier78ccf772017-04-18 23:38:41 +0000894#endif // _LIBCPP_CXX03_LANG
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000895 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896 void swap(basic_stringstream& __rhs);
897
898 // 27.8.2.3 Members:
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000899 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000901 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 string_type str() const;
Eric Fiselier7fdc71a2016-09-16 02:09:26 +0000903 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 void str(const string_type& __s);
905};
906
907template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch)
909 : basic_iostream<_CharT, _Traits>(&__sb_),
910 __sb_(__wch)
911{
912}
913
914template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s,
916 ios_base::openmode __wch)
917 : basic_iostream<_CharT, _Traits>(&__sb_),
918 __sb_(__s, __wch)
919{
920}
921
Eric Fiselier78ccf772017-04-18 23:38:41 +0000922#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923
924template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000926 : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)),
927 __sb_(_VSTD::move(__rhs.__sb_))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928{
929 basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
930}
931
932template <class _CharT, class _Traits, class _Allocator>
933basic_stringstream<_CharT, _Traits, _Allocator>&
934basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& __rhs)
935{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000936 basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
937 __sb_ = _VSTD::move(__rhs.__sb_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938 return *this;
939}
940
Eric Fiselier78ccf772017-04-18 23:38:41 +0000941#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942
943template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944void
945basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs)
946{
947 basic_iostream<char_type, traits_type>::swap(__rhs);
948 __sb_.swap(__rhs.__sb_);
949}
950
951template <class _CharT, class _Traits, class _Allocator>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000953void
954swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
955 basic_stringstream<_CharT, _Traits, _Allocator>& __y)
956{
957 __x.swap(__y);
958}
959
960template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961basic_stringbuf<_CharT, _Traits, _Allocator>*
962basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const
963{
964 return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
965}
966
967template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968basic_string<_CharT, _Traits, _Allocator>
969basic_stringstream<_CharT, _Traits, _Allocator>::str() const
970{
971 return __sb_.str();
972}
973
974template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975void
976basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
977{
978 __sb_.str(__s);
979}
980
981_LIBCPP_END_NAMESPACE_STD
982
Eric Fiselierf4433a32017-05-31 22:07:49 +0000983_LIBCPP_POP_MACROS
984
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985#endif // _LIBCPP_SSTREAM