blob: 9d96fd8d4b9de04a48faa182e937a45b02e63332 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- ostream -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_OSTREAM
12#define _LIBCPP_OSTREAM
13
14/*
15 ostream synopsis
16
17template <class charT, class traits = char_traits<charT> >
18class basic_ostream
19 : virtual public basic_ios<charT,traits>
20{
21public:
22 // types (inherited from basic_ios (27.5.4)):
23 typedef charT char_type;
24 typedef traits traits_type;
25 typedef typename traits_type::int_type int_type;
26 typedef typename traits_type::pos_type pos_type;
27 typedef typename traits_type::off_type off_type;
28
29 // 27.7.2.2 Constructor/destructor:
30 explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
31 basic_ostream(basic_ostream&& rhs);
32 virtual ~basic_ostream();
33
34 // 27.7.2.3 Assign/swap
Marshall Clow2df37002013-08-14 15:15:28 +000035 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036 basic_ostream& operator=(basic_ostream&& rhs);
37 void swap(basic_ostream& rhs);
38
39 // 27.7.2.4 Prefix/suffix:
40 class sentry;
41
42 // 27.7.2.6 Formatted output:
43 basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
44 basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
45 basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
46 basic_ostream& operator<<(bool n);
47 basic_ostream& operator<<(short n);
48 basic_ostream& operator<<(unsigned short n);
49 basic_ostream& operator<<(int n);
50 basic_ostream& operator<<(unsigned int n);
51 basic_ostream& operator<<(long n);
52 basic_ostream& operator<<(unsigned long n);
53 basic_ostream& operator<<(long long n);
54 basic_ostream& operator<<(unsigned long long n);
55 basic_ostream& operator<<(float f);
56 basic_ostream& operator<<(double f);
57 basic_ostream& operator<<(long double f);
58 basic_ostream& operator<<(const void* p);
59 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
60
61 // 27.7.2.7 Unformatted output:
62 basic_ostream& put(char_type c);
63 basic_ostream& write(const char_type* s, streamsize n);
64 basic_ostream& flush();
65
66 // 27.7.2.5 seeks:
67 pos_type tellp();
68 basic_ostream& seekp(pos_type);
69 basic_ostream& seekp(off_type, ios_base::seekdir);
70};
71
72// 27.7.2.6.4 character inserters
73
74template<class charT, class traits>
75 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
76
77template<class charT, class traits>
78 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
79
80template<class traits>
81 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
82
83// signed and unsigned
84
85template<class traits>
86 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
87
88template<class traits>
89 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
90
91// NTBS
92template<class charT, class traits>
93 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
94
95template<class charT, class traits>
96 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
97
98template<class traits>
99 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
100
101// signed and unsigned
102template<class traits>
103basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
104
105template<class traits>
106 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
107
108// swap:
109template <class charT, class traits>
110 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
111
112template <class charT, class traits>
113 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
114
115template <class charT, class traits>
116 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
117
118template <class charT, class traits>
119 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
120
121// rvalue stream insertion
122template <class charT, class traits, class T>
123 basic_ostream<charT, traits>&
124 operator<<(basic_ostream<charT, traits>&& os, const T& x);
125
126} // std
127
128*/
129
130#include <__config>
131#include <ios>
132#include <streambuf>
133#include <locale>
134#include <iterator>
135#include <bitset>
136
Howard Hinnant08e17472011-10-17 20:05:10 +0000137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000139#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140
141_LIBCPP_BEGIN_NAMESPACE_STD
142
143template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000144class _LIBCPP_TYPE_VIS_ONLY basic_ostream
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145 : virtual public basic_ios<_CharT, _Traits>
146{
147public:
148 // types (inherited from basic_ios (27.5.4)):
149 typedef _CharT char_type;
150 typedef _Traits traits_type;
151 typedef typename traits_type::int_type int_type;
152 typedef typename traits_type::pos_type pos_type;
153 typedef typename traits_type::off_type off_type;
154
155 // 27.7.2.2 Constructor/destructor:
156 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
157 virtual ~basic_ostream();
158protected:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000159#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000161 basic_ostream(basic_ostream&& __rhs);
162#endif
163
164 // 27.7.2.3 Assign/swap
Marshall Clow2df37002013-08-14 15:15:28 +0000165#if _LIBCPP_STD_VER > 11
166 basic_ostream& operator=(const basic_ostream&) = delete;
167#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000168#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170 basic_ostream& operator=(basic_ostream&& __rhs);
171#endif
172 void swap(basic_ostream& __rhs);
173public:
174
175 // 27.7.2.4 Prefix/suffix:
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000176 class _LIBCPP_TYPE_VIS_ONLY sentry;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177
178 // 27.7.2.6 Formatted output:
179 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
180 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
181 (*__pf)(basic_ios<char_type,traits_type>&));
182 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
183 basic_ostream& operator<<(bool __n);
184 basic_ostream& operator<<(short __n);
185 basic_ostream& operator<<(unsigned short __n);
186 basic_ostream& operator<<(int __n);
187 basic_ostream& operator<<(unsigned int __n);
188 basic_ostream& operator<<(long __n);
189 basic_ostream& operator<<(unsigned long __n);
190 basic_ostream& operator<<(long long __n);
191 basic_ostream& operator<<(unsigned long long __n);
192 basic_ostream& operator<<(float __f);
193 basic_ostream& operator<<(double __f);
194 basic_ostream& operator<<(long double __f);
195 basic_ostream& operator<<(const void* __p);
196 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
197
198 // 27.7.2.7 Unformatted output:
199 basic_ostream& put(char_type __c);
200 basic_ostream& write(const char_type* __s, streamsize __n);
201 basic_ostream& flush();
202
203 // 27.7.2.5 seeks:
204 pos_type tellp();
205 basic_ostream& seekp(pos_type __pos);
206 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
207
208protected:
209 _LIBCPP_ALWAYS_INLINE
210 basic_ostream() {} // extension, intentially does not initialize
211};
212
213template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000214class _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215{
216 bool __ok_;
217 basic_ostream<_CharT, _Traits>& __os_;
218
219 sentry(const sentry&); // = delete;
220 sentry& operator=(const sentry&); // = delete;
221
222public:
223 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
224 ~sentry();
225
226 _LIBCPP_ALWAYS_INLINE
Howard Hinnant77861882012-02-21 21:46:43 +0000227 _LIBCPP_EXPLICIT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228 operator bool() const {return __ok_;}
229};
230
231template <class _CharT, class _Traits>
232basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
233 : __ok_(false),
234 __os_(__os)
235{
236 if (__os.good())
237 {
238 if (__os.tie())
239 __os.tie()->flush();
240 __ok_ = true;
241 }
242}
243
244template <class _CharT, class _Traits>
245basic_ostream<_CharT, _Traits>::sentry::~sentry()
246{
247 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
248 && !uncaught_exception())
249 {
250#ifndef _LIBCPP_NO_EXCEPTIONS
251 try
252 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000253#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254 if (__os_.rdbuf()->pubsync() == -1)
255 __os_.setstate(ios_base::badbit);
256#ifndef _LIBCPP_NO_EXCEPTIONS
257 }
258 catch (...)
259 {
260 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000261#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 }
263}
264
265template <class _CharT, class _Traits>
266inline _LIBCPP_INLINE_VISIBILITY
267basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
268{
269 this->init(__sb);
270}
271
Howard Hinnant73d21a42010-09-04 23:28:19 +0000272#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273
274template <class _CharT, class _Traits>
275inline _LIBCPP_INLINE_VISIBILITY
276basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
277{
278 this->move(__rhs);
279}
280
281template <class _CharT, class _Traits>
282inline _LIBCPP_INLINE_VISIBILITY
283basic_ostream<_CharT, _Traits>&
284basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
285{
286 swap(__rhs);
287 return *this;
288}
289
Howard Hinnant73d21a42010-09-04 23:28:19 +0000290#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291
292template <class _CharT, class _Traits>
293basic_ostream<_CharT, _Traits>::~basic_ostream()
294{
295}
296
297template <class _CharT, class _Traits>
298inline _LIBCPP_INLINE_VISIBILITY
299void
300basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
301{
302 basic_ios<char_type, traits_type>::swap(__rhs);
303}
304
305template <class _CharT, class _Traits>
306inline _LIBCPP_INLINE_VISIBILITY
307basic_ostream<_CharT, _Traits>&
308basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
309{
310 return __pf(*this);
311}
312
313template <class _CharT, class _Traits>
314inline _LIBCPP_INLINE_VISIBILITY
315basic_ostream<_CharT, _Traits>&
316basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
317 (*__pf)(basic_ios<char_type,traits_type>&))
318{
319 __pf(*this);
320 return *this;
321}
322
323template <class _CharT, class _Traits>
324inline _LIBCPP_INLINE_VISIBILITY
325basic_ostream<_CharT, _Traits>&
326basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
327{
328 __pf(*this);
329 return *this;
330}
331
332template <class _CharT, class _Traits>
333basic_ostream<_CharT, _Traits>&
334basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
335{
336#ifndef _LIBCPP_NO_EXCEPTIONS
337 try
338 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000339#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340 sentry __s(*this);
341 if (__s)
342 {
343 if (__sb)
344 {
345#ifndef _LIBCPP_NO_EXCEPTIONS
346 try
347 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000348#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant99968442011-11-29 18:15:50 +0000349 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
350 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
351 _Ip __i(__sb);
352 _Ip __eof;
353 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 size_t __c = 0;
355 for (; __i != __eof; ++__i, ++__o, ++__c)
356 {
357 *__o = *__i;
358 if (__o.failed())
359 break;
360 }
361 if (__c == 0)
362 this->setstate(ios_base::failbit);
363#ifndef _LIBCPP_NO_EXCEPTIONS
364 }
365 catch (...)
366 {
367 this->__set_failbit_and_consider_rethrow();
368 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000369#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370 }
371 else
372 this->setstate(ios_base::badbit);
373 }
374#ifndef _LIBCPP_NO_EXCEPTIONS
375 }
376 catch (...)
377 {
378 this->__set_badbit_and_consider_rethrow();
379 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000380#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381 return *this;
382}
383
384template <class _CharT, class _Traits>
385basic_ostream<_CharT, _Traits>&
386basic_ostream<_CharT, _Traits>::operator<<(bool __n)
387{
388#ifndef _LIBCPP_NO_EXCEPTIONS
389 try
390 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000391#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392 sentry __s(*this);
393 if (__s)
394 {
Howard Hinnant99968442011-11-29 18:15:50 +0000395 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
396 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 if (__f.put(*this, *this, this->fill(), __n).failed())
398 this->setstate(ios_base::badbit | ios_base::failbit);
399 }
400#ifndef _LIBCPP_NO_EXCEPTIONS
401 }
402 catch (...)
403 {
404 this->__set_badbit_and_consider_rethrow();
405 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000406#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000407 return *this;
408}
409
410template <class _CharT, class _Traits>
411basic_ostream<_CharT, _Traits>&
412basic_ostream<_CharT, _Traits>::operator<<(short __n)
413{
414#ifndef _LIBCPP_NO_EXCEPTIONS
415 try
416 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000417#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 sentry __s(*this);
419 if (__s)
420 {
421 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnant99968442011-11-29 18:15:50 +0000422 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
423 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424 if (__f.put(*this, *this, this->fill(),
425 __flags == ios_base::oct || __flags == ios_base::hex ?
426 static_cast<long>(static_cast<unsigned short>(__n)) :
427 static_cast<long>(__n)).failed())
428 this->setstate(ios_base::badbit | ios_base::failbit);
429 }
430#ifndef _LIBCPP_NO_EXCEPTIONS
431 }
432 catch (...)
433 {
434 this->__set_badbit_and_consider_rethrow();
435 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000436#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 return *this;
438}
439
440template <class _CharT, class _Traits>
441basic_ostream<_CharT, _Traits>&
442basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
443{
444#ifndef _LIBCPP_NO_EXCEPTIONS
445 try
446 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000447#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 sentry __s(*this);
449 if (__s)
450 {
Howard Hinnant99968442011-11-29 18:15:50 +0000451 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
452 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
454 this->setstate(ios_base::badbit | ios_base::failbit);
455 }
456#ifndef _LIBCPP_NO_EXCEPTIONS
457 }
458 catch (...)
459 {
460 this->__set_badbit_and_consider_rethrow();
461 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000462#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463 return *this;
464}
465
466template <class _CharT, class _Traits>
467basic_ostream<_CharT, _Traits>&
468basic_ostream<_CharT, _Traits>::operator<<(int __n)
469{
470#ifndef _LIBCPP_NO_EXCEPTIONS
471 try
472 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000473#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 sentry __s(*this);
475 if (__s)
476 {
477 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnant99968442011-11-29 18:15:50 +0000478 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
479 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480 if (__f.put(*this, *this, this->fill(),
481 __flags == ios_base::oct || __flags == ios_base::hex ?
482 static_cast<long>(static_cast<unsigned int>(__n)) :
483 static_cast<long>(__n)).failed())
484 this->setstate(ios_base::badbit | ios_base::failbit);
485 }
486#ifndef _LIBCPP_NO_EXCEPTIONS
487 }
488 catch (...)
489 {
490 this->__set_badbit_and_consider_rethrow();
491 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000492#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 return *this;
494}
495
496template <class _CharT, class _Traits>
497basic_ostream<_CharT, _Traits>&
498basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
499{
500#ifndef _LIBCPP_NO_EXCEPTIONS
501 try
502 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000503#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 sentry __s(*this);
505 if (__s)
506 {
Howard Hinnant99968442011-11-29 18:15:50 +0000507 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
508 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
510 this->setstate(ios_base::badbit | ios_base::failbit);
511 }
512#ifndef _LIBCPP_NO_EXCEPTIONS
513 }
514 catch (...)
515 {
516 this->__set_badbit_and_consider_rethrow();
517 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000518#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519 return *this;
520}
521
522template <class _CharT, class _Traits>
523basic_ostream<_CharT, _Traits>&
524basic_ostream<_CharT, _Traits>::operator<<(long __n)
525{
526#ifndef _LIBCPP_NO_EXCEPTIONS
527 try
528 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000529#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 sentry __s(*this);
531 if (__s)
532 {
Howard Hinnant99968442011-11-29 18:15:50 +0000533 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
534 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535 if (__f.put(*this, *this, this->fill(), __n).failed())
536 this->setstate(ios_base::badbit | ios_base::failbit);
537 }
538#ifndef _LIBCPP_NO_EXCEPTIONS
539 }
540 catch (...)
541 {
542 this->__set_badbit_and_consider_rethrow();
543 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000544#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545 return *this;
546}
547
548template <class _CharT, class _Traits>
549basic_ostream<_CharT, _Traits>&
550basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
551{
552#ifndef _LIBCPP_NO_EXCEPTIONS
553 try
554 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000555#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556 sentry __s(*this);
557 if (__s)
558 {
Howard Hinnant99968442011-11-29 18:15:50 +0000559 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
560 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561 if (__f.put(*this, *this, this->fill(), __n).failed())
562 this->setstate(ios_base::badbit | ios_base::failbit);
563 }
564#ifndef _LIBCPP_NO_EXCEPTIONS
565 }
566 catch (...)
567 {
568 this->__set_badbit_and_consider_rethrow();
569 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000570#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571 return *this;
572}
573
574template <class _CharT, class _Traits>
575basic_ostream<_CharT, _Traits>&
576basic_ostream<_CharT, _Traits>::operator<<(long long __n)
577{
578#ifndef _LIBCPP_NO_EXCEPTIONS
579 try
580 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000581#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582 sentry __s(*this);
583 if (__s)
584 {
Howard Hinnant99968442011-11-29 18:15:50 +0000585 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
586 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587 if (__f.put(*this, *this, this->fill(), __n).failed())
588 this->setstate(ios_base::badbit | ios_base::failbit);
589 }
590#ifndef _LIBCPP_NO_EXCEPTIONS
591 }
592 catch (...)
593 {
594 this->__set_badbit_and_consider_rethrow();
595 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000596#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597 return *this;
598}
599
600template <class _CharT, class _Traits>
601basic_ostream<_CharT, _Traits>&
602basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
603{
604#ifndef _LIBCPP_NO_EXCEPTIONS
605 try
606 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000607#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 sentry __s(*this);
609 if (__s)
610 {
Howard Hinnant99968442011-11-29 18:15:50 +0000611 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
612 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613 if (__f.put(*this, *this, this->fill(), __n).failed())
614 this->setstate(ios_base::badbit | ios_base::failbit);
615 }
616#ifndef _LIBCPP_NO_EXCEPTIONS
617 }
618 catch (...)
619 {
620 this->__set_badbit_and_consider_rethrow();
621 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000622#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623 return *this;
624}
625
626template <class _CharT, class _Traits>
627basic_ostream<_CharT, _Traits>&
628basic_ostream<_CharT, _Traits>::operator<<(float __n)
629{
630#ifndef _LIBCPP_NO_EXCEPTIONS
631 try
632 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000633#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 sentry __s(*this);
635 if (__s)
636 {
Howard Hinnant99968442011-11-29 18:15:50 +0000637 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
638 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
640 this->setstate(ios_base::badbit | ios_base::failbit);
641 }
642#ifndef _LIBCPP_NO_EXCEPTIONS
643 }
644 catch (...)
645 {
646 this->__set_badbit_and_consider_rethrow();
647 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000648#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649 return *this;
650}
651
652template <class _CharT, class _Traits>
653basic_ostream<_CharT, _Traits>&
654basic_ostream<_CharT, _Traits>::operator<<(double __n)
655{
656#ifndef _LIBCPP_NO_EXCEPTIONS
657 try
658 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000659#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 sentry __s(*this);
661 if (__s)
662 {
Howard Hinnant99968442011-11-29 18:15:50 +0000663 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
664 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 if (__f.put(*this, *this, this->fill(), __n).failed())
666 this->setstate(ios_base::badbit | ios_base::failbit);
667 }
668#ifndef _LIBCPP_NO_EXCEPTIONS
669 }
670 catch (...)
671 {
672 this->__set_badbit_and_consider_rethrow();
673 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000674#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 return *this;
676}
677
678template <class _CharT, class _Traits>
679basic_ostream<_CharT, _Traits>&
680basic_ostream<_CharT, _Traits>::operator<<(long double __n)
681{
682#ifndef _LIBCPP_NO_EXCEPTIONS
683 try
684 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000685#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 sentry __s(*this);
687 if (__s)
688 {
Howard Hinnant99968442011-11-29 18:15:50 +0000689 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
690 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 if (__f.put(*this, *this, this->fill(), __n).failed())
692 this->setstate(ios_base::badbit | ios_base::failbit);
693 }
694#ifndef _LIBCPP_NO_EXCEPTIONS
695 }
696 catch (...)
697 {
698 this->__set_badbit_and_consider_rethrow();
699 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000700#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 return *this;
702}
703
704template <class _CharT, class _Traits>
705basic_ostream<_CharT, _Traits>&
706basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
707{
708#ifndef _LIBCPP_NO_EXCEPTIONS
709 try
710 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000711#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 sentry __s(*this);
713 if (__s)
714 {
Howard Hinnant99968442011-11-29 18:15:50 +0000715 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
716 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 if (__f.put(*this, *this, this->fill(), __n).failed())
718 this->setstate(ios_base::badbit | ios_base::failbit);
719 }
720#ifndef _LIBCPP_NO_EXCEPTIONS
721 }
722 catch (...)
723 {
724 this->__set_badbit_and_consider_rethrow();
725 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000726#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727 return *this;
728}
729
730template<class _CharT, class _Traits>
731basic_ostream<_CharT, _Traits>&
Marshall Clow73b46a72013-12-10 19:25:49 +0000732__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
733 const _CharT* __str, size_t __len)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734{
735#ifndef _LIBCPP_NO_EXCEPTIONS
736 try
737 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000738#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
740 if (__s)
741 {
Howard Hinnant99968442011-11-29 18:15:50 +0000742 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
743 if (__pad_and_output(_Ip(__os),
Marshall Clow73b46a72013-12-10 19:25:49 +0000744 __str,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow73b46a72013-12-10 19:25:49 +0000746 __str + __len :
747 __str,
748 __str + __len,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749 __os,
750 __os.fill()).failed())
751 __os.setstate(ios_base::badbit | ios_base::failbit);
752 }
753#ifndef _LIBCPP_NO_EXCEPTIONS
754 }
755 catch (...)
756 {
757 __os.__set_badbit_and_consider_rethrow();
758 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000759#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760 return __os;
761}
762
Marshall Clow73b46a72013-12-10 19:25:49 +0000763
764template<class _CharT, class _Traits>
765basic_ostream<_CharT, _Traits>&
766operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
767{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000768 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow73b46a72013-12-10 19:25:49 +0000769}
770
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771template<class _CharT, class _Traits>
772basic_ostream<_CharT, _Traits>&
773operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
774{
775#ifndef _LIBCPP_NO_EXCEPTIONS
776 try
777 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000778#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
780 if (__s)
781 {
782 _CharT __c = __os.widen(__cn);
Howard Hinnant99968442011-11-29 18:15:50 +0000783 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
784 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000785 &__c,
786 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
787 &__c + 1 :
788 &__c,
789 &__c + 1,
790 __os,
791 __os.fill()).failed())
792 __os.setstate(ios_base::badbit | ios_base::failbit);
793 }
794#ifndef _LIBCPP_NO_EXCEPTIONS
795 }
796 catch (...)
797 {
798 __os.__set_badbit_and_consider_rethrow();
799 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000800#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801 return __os;
802}
803
804template<class _Traits>
805basic_ostream<char, _Traits>&
806operator<<(basic_ostream<char, _Traits>& __os, char __c)
807{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000808 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809}
810
811template<class _Traits>
812basic_ostream<char, _Traits>&
813operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
814{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000815 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816}
817
818template<class _Traits>
819basic_ostream<char, _Traits>&
820operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
821{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000822 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823}
824
825template<class _CharT, class _Traits>
826basic_ostream<_CharT, _Traits>&
827operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
828{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000829 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830}
831
832template<class _CharT, class _Traits>
833basic_ostream<_CharT, _Traits>&
834operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
835{
836#ifndef _LIBCPP_NO_EXCEPTIONS
837 try
838 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000839#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
841 if (__s)
842 {
Howard Hinnant99968442011-11-29 18:15:50 +0000843 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844 size_t __len = char_traits<char>::length(__strn);
845 const int __bs = 100;
846 _CharT __wbb[__bs];
847 _CharT* __wb = __wbb;
848 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
849 if (__len > __bs)
850 {
851 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
852 if (__wb == 0)
853 __throw_bad_alloc();
854 __h.reset(__wb);
855 }
856 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
857 *__p = __os.widen(*__strn);
Howard Hinnant99968442011-11-29 18:15:50 +0000858 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 __wb,
860 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
861 __wb + __len :
862 __wb,
863 __wb + __len,
864 __os,
865 __os.fill()).failed())
866 __os.setstate(ios_base::badbit | ios_base::failbit);
867 }
868#ifndef _LIBCPP_NO_EXCEPTIONS
869 }
870 catch (...)
871 {
872 __os.__set_badbit_and_consider_rethrow();
873 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000874#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 return __os;
876}
877
878template<class _Traits>
879basic_ostream<char, _Traits>&
880operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
881{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000882 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883}
884
885template<class _Traits>
886basic_ostream<char, _Traits>&
887operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
888{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000889 const char *__s = (const char *) __str;
890 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891}
892
893template<class _Traits>
894basic_ostream<char, _Traits>&
895operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
896{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000897 const char *__s = (const char *) __str;
898 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899}
900
901template <class _CharT, class _Traits>
902basic_ostream<_CharT, _Traits>&
903basic_ostream<_CharT, _Traits>::put(char_type __c)
904{
905#ifndef _LIBCPP_NO_EXCEPTIONS
906 try
907 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000908#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 sentry __s(*this);
910 if (__s)
911 {
Howard Hinnant99968442011-11-29 18:15:50 +0000912 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
913 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 *__o = __c;
915 if (__o.failed())
916 this->setstate(ios_base::badbit);
917 }
918#ifndef _LIBCPP_NO_EXCEPTIONS
919 }
920 catch (...)
921 {
922 this->__set_badbit_and_consider_rethrow();
923 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000924#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925 return *this;
926}
927
928template <class _CharT, class _Traits>
929basic_ostream<_CharT, _Traits>&
930basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
931{
932#ifndef _LIBCPP_NO_EXCEPTIONS
933 try
934 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000935#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 sentry __sen(*this);
937 if (__sen && __n)
938 {
Howard Hinnant0b939632013-01-15 17:22:03 +0000939 if (this->rdbuf()->sputn(__s, __n) != __n)
940 this->setstate(ios_base::badbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941 }
942#ifndef _LIBCPP_NO_EXCEPTIONS
943 }
944 catch (...)
945 {
946 this->__set_badbit_and_consider_rethrow();
947 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000948#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 return *this;
950}
951
952template <class _CharT, class _Traits>
953basic_ostream<_CharT, _Traits>&
954basic_ostream<_CharT, _Traits>::flush()
955{
956#ifndef _LIBCPP_NO_EXCEPTIONS
957 try
958 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000959#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000960 if (this->rdbuf())
961 {
962 sentry __s(*this);
963 if (__s)
964 {
965 if (this->rdbuf()->pubsync() == -1)
966 this->setstate(ios_base::badbit);
967 }
968 }
969#ifndef _LIBCPP_NO_EXCEPTIONS
970 }
971 catch (...)
972 {
973 this->__set_badbit_and_consider_rethrow();
974 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000975#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 return *this;
977}
978
979template <class _CharT, class _Traits>
980inline _LIBCPP_INLINE_VISIBILITY
981typename basic_ostream<_CharT, _Traits>::pos_type
982basic_ostream<_CharT, _Traits>::tellp()
983{
984 if (this->fail())
985 return pos_type(-1);
986 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
987}
988
989template <class _CharT, class _Traits>
990inline _LIBCPP_INLINE_VISIBILITY
991basic_ostream<_CharT, _Traits>&
992basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
993{
Marshall Clow76a86702013-10-31 22:20:45 +0000994 sentry __s(*this);
995 if (__s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996 {
997 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
998 this->setstate(ios_base::failbit);
999 }
1000 return *this;
1001}
1002
1003template <class _CharT, class _Traits>
1004inline _LIBCPP_INLINE_VISIBILITY
1005basic_ostream<_CharT, _Traits>&
1006basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1007{
Marshall Clow76a86702013-10-31 22:20:45 +00001008 sentry __s(*this);
1009 if (__s)
1010 {
1011 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
1012 this->setstate(ios_base::failbit);
1013 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 return *this;
1015}
1016
1017template <class _CharT, class _Traits>
1018inline _LIBCPP_INLINE_VISIBILITY
1019basic_ostream<_CharT, _Traits>&
1020endl(basic_ostream<_CharT, _Traits>& __os)
1021{
1022 __os.put(__os.widen('\n'));
1023 __os.flush();
1024 return __os;
1025}
1026
1027template <class _CharT, class _Traits>
1028inline _LIBCPP_INLINE_VISIBILITY
1029basic_ostream<_CharT, _Traits>&
1030ends(basic_ostream<_CharT, _Traits>& __os)
1031{
1032 __os.put(_CharT());
1033 return __os;
1034}
1035
1036template <class _CharT, class _Traits>
1037inline _LIBCPP_INLINE_VISIBILITY
1038basic_ostream<_CharT, _Traits>&
1039flush(basic_ostream<_CharT, _Traits>& __os)
1040{
1041 __os.flush();
1042 return __os;
1043}
1044
Howard Hinnant73d21a42010-09-04 23:28:19 +00001045#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046
1047template <class _Stream, class _Tp>
1048inline _LIBCPP_INLINE_VISIBILITY
1049typename enable_if
1050<
1051 !is_lvalue_reference<_Stream>::value &&
1052 is_base_of<ios_base, _Stream>::value,
Howard Hinnante1a7b042012-01-12 23:37:51 +00001053 _Stream&&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054>::type
1055operator<<(_Stream&& __os, const _Tp& __x)
1056{
1057 __os << __x;
Howard Hinnante1a7b042012-01-12 23:37:51 +00001058 return _VSTD::move(__os);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059}
1060
Howard Hinnant73d21a42010-09-04 23:28:19 +00001061#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062
1063template<class _CharT, class _Traits, class _Allocator>
1064basic_ostream<_CharT, _Traits>&
1065operator<<(basic_ostream<_CharT, _Traits>& __os,
1066 const basic_string<_CharT, _Traits, _Allocator>& __str)
1067{
Marshall Clow8eb5acc2014-02-16 01:57:26 +00001068 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069}
1070
1071template <class _CharT, class _Traits>
1072inline _LIBCPP_INLINE_VISIBILITY
1073basic_ostream<_CharT, _Traits>&
1074operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1075{
1076 return __os << __ec.category().name() << ':' << __ec.value();
1077}
1078
Howard Hinnant99968442011-11-29 18:15:50 +00001079template<class _CharT, class _Traits, class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080inline _LIBCPP_INLINE_VISIBILITY
1081basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00001082operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083{
1084 return __os << __p.get();
1085}
1086
1087template <class _CharT, class _Traits, size_t _Size>
1088basic_ostream<_CharT, _Traits>&
Howard Hinnanta02851e2011-04-05 14:55:28 +00001089operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001090{
1091 return __os << __x.template to_string<_CharT, _Traits>
1092 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1093 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1094}
1095
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001096_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>)
1097_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098
1099_LIBCPP_END_NAMESPACE_STD
1100
1101#endif // _LIBCPP_OSTREAM