blob: 041314acc7568a8b8089b5a4a8e3affc6432a98b [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- ostream -----------------------------------===//
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_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 Clowe9ca0272013-08-14 15:15:28 +000035 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
Howard Hinnantc51e1022010-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 Hinnantaaaa52b2011-10-17 20:05:10 +0000137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000139#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140
141_LIBCPP_BEGIN_NAMESPACE_STD
142
143template <class _CharT, class _Traits>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000144class _LIBCPP_TYPE_VIS_ONLY basic_ostream
Howard Hinnantc51e1022010-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 Hinnant74279a52010-09-04 23:28:19 +0000159#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0dcdf022011-07-07 21:03:52 +0000160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161 basic_ostream(basic_ostream&& __rhs);
162#endif
163
164 // 27.7.2.3 Assign/swap
Marshall Clowe9ca0272013-08-14 15:15:28 +0000165#if _LIBCPP_STD_VER > 11
166 basic_ostream& operator=(const basic_ostream&) = delete;
167#endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000168#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0dcdf022011-07-07 21:03:52 +0000169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnanta37d3cf2013-08-12 18:38:34 +0000176 class _LIBCPP_TYPE_VIS_ONLY sentry;
Howard Hinnantc51e1022010-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 Hinnanta37d3cf2013-08-12 18:38:34 +0000214class _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-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 Hinnant86a291f2012-02-21 21:46:43 +0000227 _LIBCPP_EXPLICIT
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000253#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000261#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant74279a52010-09-04 23:28:19 +0000272#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-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 Hinnant74279a52010-09-04 23:28:19 +0000290#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000339#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000348#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000369#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000380#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000391#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 sentry __s(*this);
393 if (__s)
394 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000406#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000417#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000436#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000447#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 sentry __s(*this);
449 if (__s)
450 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000462#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000473#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000492#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000503#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 sentry __s(*this);
505 if (__s)
506 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000518#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000529#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 sentry __s(*this);
531 if (__s)
532 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000544#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000555#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556 sentry __s(*this);
557 if (__s)
558 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000570#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000581#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582 sentry __s(*this);
583 if (__s)
584 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000596#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000607#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 sentry __s(*this);
609 if (__s)
610 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000622#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000633#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 sentry __s(*this);
635 if (__s)
636 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000648#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000659#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 sentry __s(*this);
661 if (__s)
662 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000674#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000685#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686 sentry __s(*this);
687 if (__s)
688 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000700#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000711#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712 sentry __s(*this);
713 if (__s)
714 {
Howard Hinnantc834c512011-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000726#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727 return *this;
728}
729
730template<class _CharT, class _Traits>
731basic_ostream<_CharT, _Traits>&
732operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
733{
734#ifndef _LIBCPP_NO_EXCEPTIONS
735 try
736 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000737#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
739 if (__s)
740 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000741 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
742 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743 &__c,
744 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
745 &__c + 1 :
746 &__c,
747 &__c + 1,
748 __os,
749 __os.fill()).failed())
750 __os.setstate(ios_base::badbit | ios_base::failbit);
751 }
752#ifndef _LIBCPP_NO_EXCEPTIONS
753 }
754 catch (...)
755 {
756 __os.__set_badbit_and_consider_rethrow();
757 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000758#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759 return __os;
760}
761
762template<class _CharT, class _Traits>
763basic_ostream<_CharT, _Traits>&
764operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
765{
766#ifndef _LIBCPP_NO_EXCEPTIONS
767 try
768 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000769#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
771 if (__s)
772 {
773 _CharT __c = __os.widen(__cn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000774 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
775 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 &__c,
777 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
778 &__c + 1 :
779 &__c,
780 &__c + 1,
781 __os,
782 __os.fill()).failed())
783 __os.setstate(ios_base::badbit | ios_base::failbit);
784 }
785#ifndef _LIBCPP_NO_EXCEPTIONS
786 }
787 catch (...)
788 {
789 __os.__set_badbit_and_consider_rethrow();
790 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000791#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792 return __os;
793}
794
795template<class _Traits>
796basic_ostream<char, _Traits>&
797operator<<(basic_ostream<char, _Traits>& __os, char __c)
798{
799#ifndef _LIBCPP_NO_EXCEPTIONS
800 try
801 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000802#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 typename basic_ostream<char, _Traits>::sentry __s(__os);
804 if (__s)
805 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000806 typedef ostreambuf_iterator<char, _Traits> _Ip;
807 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 &__c,
809 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
810 &__c + 1 :
811 &__c,
812 &__c + 1,
813 __os,
814 __os.fill()).failed())
815 __os.setstate(ios_base::badbit | ios_base::failbit);
816 }
817#ifndef _LIBCPP_NO_EXCEPTIONS
818 }
819 catch (...)
820 {
821 __os.__set_badbit_and_consider_rethrow();
822 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000823#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 return __os;
825}
826
827template<class _Traits>
828basic_ostream<char, _Traits>&
829operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
830{
831#ifndef _LIBCPP_NO_EXCEPTIONS
832 try
833 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000834#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 typename basic_ostream<char, _Traits>::sentry __s(__os);
836 if (__s)
837 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000838 typedef ostreambuf_iterator<char, _Traits> _Ip;
839 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 (char*)&__c,
841 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
842 (char*)&__c + 1 :
843 (char*)&__c,
844 (char*)&__c + 1,
845 __os,
846 __os.fill()).failed())
847 __os.setstate(ios_base::badbit | ios_base::failbit);
848 }
849#ifndef _LIBCPP_NO_EXCEPTIONS
850 }
851 catch (...)
852 {
853 __os.__set_badbit_and_consider_rethrow();
854 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000855#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 return __os;
857}
858
859template<class _Traits>
860basic_ostream<char, _Traits>&
861operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
862{
863#ifndef _LIBCPP_NO_EXCEPTIONS
864 try
865 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000866#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867 typename basic_ostream<char, _Traits>::sentry __s(__os);
868 if (__s)
869 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000870 typedef ostreambuf_iterator<char, _Traits> _Ip;
871 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 (char*)&__c,
873 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
874 (char*)&__c + 1 :
875 (char*)&__c,
876 (char*)&__c + 1,
877 __os,
878 __os.fill()).failed())
879 __os.setstate(ios_base::badbit | ios_base::failbit);
880 }
881#ifndef _LIBCPP_NO_EXCEPTIONS
882 }
883 catch (...)
884 {
885 __os.__set_badbit_and_consider_rethrow();
886 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000887#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 return __os;
889}
890
891template<class _CharT, class _Traits>
892basic_ostream<_CharT, _Traits>&
893operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
894{
895#ifndef _LIBCPP_NO_EXCEPTIONS
896 try
897 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000898#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
900 if (__s)
901 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000902 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 size_t __len = _Traits::length(__str);
Howard Hinnantc834c512011-11-29 18:15:50 +0000904 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 __str,
906 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
907 __str + __len :
908 __str,
909 __str + __len,
910 __os,
911 __os.fill()).failed())
912 __os.setstate(ios_base::badbit | ios_base::failbit);
913 }
914#ifndef _LIBCPP_NO_EXCEPTIONS
915 }
916 catch (...)
917 {
918 __os.__set_badbit_and_consider_rethrow();
919 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000920#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921 return __os;
922}
923
924template<class _CharT, class _Traits>
925basic_ostream<_CharT, _Traits>&
926operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
927{
928#ifndef _LIBCPP_NO_EXCEPTIONS
929 try
930 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000931#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
933 if (__s)
934 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000935 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936 size_t __len = char_traits<char>::length(__strn);
937 const int __bs = 100;
938 _CharT __wbb[__bs];
939 _CharT* __wb = __wbb;
940 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
941 if (__len > __bs)
942 {
943 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
944 if (__wb == 0)
945 __throw_bad_alloc();
946 __h.reset(__wb);
947 }
948 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
949 *__p = __os.widen(*__strn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000950 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951 __wb,
952 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
953 __wb + __len :
954 __wb,
955 __wb + __len,
956 __os,
957 __os.fill()).failed())
958 __os.setstate(ios_base::badbit | ios_base::failbit);
959 }
960#ifndef _LIBCPP_NO_EXCEPTIONS
961 }
962 catch (...)
963 {
964 __os.__set_badbit_and_consider_rethrow();
965 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000966#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000967 return __os;
968}
969
970template<class _Traits>
971basic_ostream<char, _Traits>&
972operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
973{
974#ifndef _LIBCPP_NO_EXCEPTIONS
975 try
976 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000977#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 typename basic_ostream<char, _Traits>::sentry __s(__os);
979 if (__s)
980 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000981 typedef ostreambuf_iterator<char, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 size_t __len = _Traits::length(__str);
Howard Hinnantc834c512011-11-29 18:15:50 +0000983 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 __str,
985 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
986 __str + __len :
987 __str,
988 __str + __len,
989 __os,
990 __os.fill()).failed())
991 __os.setstate(ios_base::badbit | ios_base::failbit);
992 }
993#ifndef _LIBCPP_NO_EXCEPTIONS
994 }
995 catch (...)
996 {
997 __os.__set_badbit_and_consider_rethrow();
998 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000999#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 return __os;
1001}
1002
1003template<class _Traits>
1004basic_ostream<char, _Traits>&
1005operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
1006{
1007#ifndef _LIBCPP_NO_EXCEPTIONS
1008 try
1009 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001010#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011 typename basic_ostream<char, _Traits>::sentry __s(__os);
1012 if (__s)
1013 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001014 typedef ostreambuf_iterator<char, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 size_t __len = _Traits::length((const char*)__str);
Howard Hinnantc834c512011-11-29 18:15:50 +00001016 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 (const char*)__str,
1018 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1019 (const char*)__str + __len :
1020 (const char*)__str,
1021 (const char*)__str + __len,
1022 __os,
1023 __os.fill()).failed())
1024 __os.setstate(ios_base::badbit | ios_base::failbit);
1025 }
1026#ifndef _LIBCPP_NO_EXCEPTIONS
1027 }
1028 catch (...)
1029 {
1030 __os.__set_badbit_and_consider_rethrow();
1031 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001032#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 return __os;
1034}
1035
1036template<class _Traits>
1037basic_ostream<char, _Traits>&
1038operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
1039{
1040#ifndef _LIBCPP_NO_EXCEPTIONS
1041 try
1042 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001043#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 typename basic_ostream<char, _Traits>::sentry __s(__os);
1045 if (__s)
1046 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001047 typedef ostreambuf_iterator<char, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 size_t __len = _Traits::length((const char*)__str);
Howard Hinnantc834c512011-11-29 18:15:50 +00001049 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 (const char*)__str,
1051 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1052 (const char*)__str + __len :
1053 (const char*)__str,
1054 (const char*)__str + __len,
1055 __os,
1056 __os.fill()).failed())
1057 __os.setstate(ios_base::badbit | ios_base::failbit);
1058 }
1059#ifndef _LIBCPP_NO_EXCEPTIONS
1060 }
1061 catch (...)
1062 {
1063 __os.__set_badbit_and_consider_rethrow();
1064 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001065#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 return __os;
1067}
1068
1069template <class _CharT, class _Traits>
1070basic_ostream<_CharT, _Traits>&
1071basic_ostream<_CharT, _Traits>::put(char_type __c)
1072{
1073#ifndef _LIBCPP_NO_EXCEPTIONS
1074 try
1075 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001076#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 sentry __s(*this);
1078 if (__s)
1079 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001080 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
1081 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082 *__o = __c;
1083 if (__o.failed())
1084 this->setstate(ios_base::badbit);
1085 }
1086#ifndef _LIBCPP_NO_EXCEPTIONS
1087 }
1088 catch (...)
1089 {
1090 this->__set_badbit_and_consider_rethrow();
1091 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001092#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093 return *this;
1094}
1095
1096template <class _CharT, class _Traits>
1097basic_ostream<_CharT, _Traits>&
1098basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
1099{
1100#ifndef _LIBCPP_NO_EXCEPTIONS
1101 try
1102 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001103#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104 sentry __sen(*this);
1105 if (__sen && __n)
1106 {
Howard Hinnant79cef932013-01-15 17:22:03 +00001107 if (this->rdbuf()->sputn(__s, __n) != __n)
1108 this->setstate(ios_base::badbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 }
1110#ifndef _LIBCPP_NO_EXCEPTIONS
1111 }
1112 catch (...)
1113 {
1114 this->__set_badbit_and_consider_rethrow();
1115 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001116#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117 return *this;
1118}
1119
1120template <class _CharT, class _Traits>
1121basic_ostream<_CharT, _Traits>&
1122basic_ostream<_CharT, _Traits>::flush()
1123{
1124#ifndef _LIBCPP_NO_EXCEPTIONS
1125 try
1126 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001127#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 if (this->rdbuf())
1129 {
1130 sentry __s(*this);
1131 if (__s)
1132 {
1133 if (this->rdbuf()->pubsync() == -1)
1134 this->setstate(ios_base::badbit);
1135 }
1136 }
1137#ifndef _LIBCPP_NO_EXCEPTIONS
1138 }
1139 catch (...)
1140 {
1141 this->__set_badbit_and_consider_rethrow();
1142 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001143#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 return *this;
1145}
1146
1147template <class _CharT, class _Traits>
1148inline _LIBCPP_INLINE_VISIBILITY
1149typename basic_ostream<_CharT, _Traits>::pos_type
1150basic_ostream<_CharT, _Traits>::tellp()
1151{
1152 if (this->fail())
1153 return pos_type(-1);
1154 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1155}
1156
1157template <class _CharT, class _Traits>
1158inline _LIBCPP_INLINE_VISIBILITY
1159basic_ostream<_CharT, _Traits>&
1160basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1161{
Marshall Clow29c4daa2013-10-31 22:20:45 +00001162 sentry __s(*this);
1163 if (__s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164 {
1165 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1166 this->setstate(ios_base::failbit);
1167 }
1168 return *this;
1169}
1170
1171template <class _CharT, class _Traits>
1172inline _LIBCPP_INLINE_VISIBILITY
1173basic_ostream<_CharT, _Traits>&
1174basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1175{
Marshall Clow29c4daa2013-10-31 22:20:45 +00001176 sentry __s(*this);
1177 if (__s)
1178 {
1179 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
1180 this->setstate(ios_base::failbit);
1181 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182 return *this;
1183}
1184
1185template <class _CharT, class _Traits>
1186inline _LIBCPP_INLINE_VISIBILITY
1187basic_ostream<_CharT, _Traits>&
1188endl(basic_ostream<_CharT, _Traits>& __os)
1189{
1190 __os.put(__os.widen('\n'));
1191 __os.flush();
1192 return __os;
1193}
1194
1195template <class _CharT, class _Traits>
1196inline _LIBCPP_INLINE_VISIBILITY
1197basic_ostream<_CharT, _Traits>&
1198ends(basic_ostream<_CharT, _Traits>& __os)
1199{
1200 __os.put(_CharT());
1201 return __os;
1202}
1203
1204template <class _CharT, class _Traits>
1205inline _LIBCPP_INLINE_VISIBILITY
1206basic_ostream<_CharT, _Traits>&
1207flush(basic_ostream<_CharT, _Traits>& __os)
1208{
1209 __os.flush();
1210 return __os;
1211}
1212
Howard Hinnant74279a52010-09-04 23:28:19 +00001213#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214
1215template <class _Stream, class _Tp>
1216inline _LIBCPP_INLINE_VISIBILITY
1217typename enable_if
1218<
1219 !is_lvalue_reference<_Stream>::value &&
1220 is_base_of<ios_base, _Stream>::value,
Howard Hinnantc8697b62012-01-12 23:37:51 +00001221 _Stream&&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222>::type
1223operator<<(_Stream&& __os, const _Tp& __x)
1224{
1225 __os << __x;
Howard Hinnantc8697b62012-01-12 23:37:51 +00001226 return _VSTD::move(__os);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227}
1228
Howard Hinnant74279a52010-09-04 23:28:19 +00001229#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230
1231template<class _CharT, class _Traits, class _Allocator>
1232basic_ostream<_CharT, _Traits>&
1233operator<<(basic_ostream<_CharT, _Traits>& __os,
1234 const basic_string<_CharT, _Traits, _Allocator>& __str)
1235{
1236#ifndef _LIBCPP_NO_EXCEPTIONS
1237 try
1238 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001239#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
1241 if (__s)
1242 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001243 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244 size_t __len = __str.size();
Howard Hinnantc834c512011-11-29 18:15:50 +00001245 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246 __str.data(),
1247 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1248 __str.data() + __len :
1249 __str.data(),
1250 __str.data() + __len,
1251 __os,
1252 __os.fill()).failed())
1253 __os.setstate(ios_base::badbit | ios_base::failbit);
1254 }
1255#ifndef _LIBCPP_NO_EXCEPTIONS
1256 }
1257 catch (...)
1258 {
1259 __os.__set_badbit_and_consider_rethrow();
1260 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001261#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262 return __os;
1263}
1264
1265template <class _CharT, class _Traits>
1266inline _LIBCPP_INLINE_VISIBILITY
1267basic_ostream<_CharT, _Traits>&
1268operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1269{
1270 return __os << __ec.category().name() << ':' << __ec.value();
1271}
1272
Howard Hinnantc834c512011-11-29 18:15:50 +00001273template<class _CharT, class _Traits, class _Yp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274inline _LIBCPP_INLINE_VISIBILITY
1275basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001276operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277{
1278 return __os << __p.get();
1279}
1280
1281template <class _CharT, class _Traits, size_t _Size>
1282basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001283operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284{
1285 return __os << __x.template to_string<_CharT, _Traits>
1286 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1287 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1288}
1289
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001290_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>)
1291_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292
1293_LIBCPP_END_NAMESPACE_STD
1294
1295#endif // _LIBCPP_OSTREAM