blob: f1a3de9c6df49769213b98b65b7fc0f442a0cf95 [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
35 basic_ostream& operator=(basic_ostream&& rhs);
36 void swap(basic_ostream& rhs);
37
38 // 27.7.2.4 Prefix/suffix:
39 class sentry;
40
41 // 27.7.2.6 Formatted output:
42 basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
43 basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
44 basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
45 basic_ostream& operator<<(bool n);
46 basic_ostream& operator<<(short n);
47 basic_ostream& operator<<(unsigned short n);
48 basic_ostream& operator<<(int n);
49 basic_ostream& operator<<(unsigned int n);
50 basic_ostream& operator<<(long n);
51 basic_ostream& operator<<(unsigned long n);
52 basic_ostream& operator<<(long long n);
53 basic_ostream& operator<<(unsigned long long n);
54 basic_ostream& operator<<(float f);
55 basic_ostream& operator<<(double f);
56 basic_ostream& operator<<(long double f);
57 basic_ostream& operator<<(const void* p);
58 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
59
60 // 27.7.2.7 Unformatted output:
61 basic_ostream& put(char_type c);
62 basic_ostream& write(const char_type* s, streamsize n);
63 basic_ostream& flush();
64
65 // 27.7.2.5 seeks:
66 pos_type tellp();
67 basic_ostream& seekp(pos_type);
68 basic_ostream& seekp(off_type, ios_base::seekdir);
69};
70
71// 27.7.2.6.4 character inserters
72
73template<class charT, class traits>
74 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
75
76template<class charT, class traits>
77 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
78
79template<class traits>
80 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
81
82// signed and unsigned
83
84template<class traits>
85 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
86
87template<class traits>
88 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
89
90// NTBS
91template<class charT, class traits>
92 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
93
94template<class charT, class traits>
95 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
96
97template<class traits>
98 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
99
100// signed and unsigned
101template<class traits>
102basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
103
104template<class traits>
105 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
106
107// swap:
108template <class charT, class traits>
109 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
110
111template <class charT, class traits>
112 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
113
114template <class charT, class traits>
115 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
116
117template <class charT, class traits>
118 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
119
120// rvalue stream insertion
121template <class charT, class traits, class T>
122 basic_ostream<charT, traits>&
123 operator<<(basic_ostream<charT, traits>&& os, const T& x);
124
125} // std
126
127*/
128
129#include <__config>
130#include <ios>
131#include <streambuf>
132#include <locale>
133#include <iterator>
134#include <bitset>
135
136#pragma GCC system_header
137
138_LIBCPP_BEGIN_NAMESPACE_STD
139
140template <class _CharT, class _Traits>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000141class _LIBCPP_VISIBLE basic_ostream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142 : virtual public basic_ios<_CharT, _Traits>
143{
144public:
145 // types (inherited from basic_ios (27.5.4)):
146 typedef _CharT char_type;
147 typedef _Traits traits_type;
148 typedef typename traits_type::int_type int_type;
149 typedef typename traits_type::pos_type pos_type;
150 typedef typename traits_type::off_type off_type;
151
152 // 27.7.2.2 Constructor/destructor:
153 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
154 virtual ~basic_ostream();
155protected:
Howard Hinnant74279a52010-09-04 23:28:19 +0000156#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0dcdf022011-07-07 21:03:52 +0000157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000158 basic_ostream(basic_ostream&& __rhs);
159#endif
160
161 // 27.7.2.3 Assign/swap
Howard Hinnant74279a52010-09-04 23:28:19 +0000162#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0dcdf022011-07-07 21:03:52 +0000163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000164 basic_ostream& operator=(basic_ostream&& __rhs);
165#endif
166 void swap(basic_ostream& __rhs);
167public:
168
169 // 27.7.2.4 Prefix/suffix:
170 class sentry;
171
172 // 27.7.2.6 Formatted output:
173 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
174 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
175 (*__pf)(basic_ios<char_type,traits_type>&));
176 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
177 basic_ostream& operator<<(bool __n);
178 basic_ostream& operator<<(short __n);
179 basic_ostream& operator<<(unsigned short __n);
180 basic_ostream& operator<<(int __n);
181 basic_ostream& operator<<(unsigned int __n);
182 basic_ostream& operator<<(long __n);
183 basic_ostream& operator<<(unsigned long __n);
184 basic_ostream& operator<<(long long __n);
185 basic_ostream& operator<<(unsigned long long __n);
186 basic_ostream& operator<<(float __f);
187 basic_ostream& operator<<(double __f);
188 basic_ostream& operator<<(long double __f);
189 basic_ostream& operator<<(const void* __p);
190 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
191
192 // 27.7.2.7 Unformatted output:
193 basic_ostream& put(char_type __c);
194 basic_ostream& write(const char_type* __s, streamsize __n);
195 basic_ostream& flush();
196
197 // 27.7.2.5 seeks:
198 pos_type tellp();
199 basic_ostream& seekp(pos_type __pos);
200 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
201
202protected:
203 _LIBCPP_ALWAYS_INLINE
204 basic_ostream() {} // extension, intentially does not initialize
205};
206
207template <class _CharT, class _Traits>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000208class _LIBCPP_VISIBLE basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209{
210 bool __ok_;
211 basic_ostream<_CharT, _Traits>& __os_;
212
213 sentry(const sentry&); // = delete;
214 sentry& operator=(const sentry&); // = delete;
215
216public:
217 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
218 ~sentry();
219
220 _LIBCPP_ALWAYS_INLINE
221 // explicit
222 operator bool() const {return __ok_;}
223};
224
225template <class _CharT, class _Traits>
226basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
227 : __ok_(false),
228 __os_(__os)
229{
230 if (__os.good())
231 {
232 if (__os.tie())
233 __os.tie()->flush();
234 __ok_ = true;
235 }
236}
237
238template <class _CharT, class _Traits>
239basic_ostream<_CharT, _Traits>::sentry::~sentry()
240{
241 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
242 && !uncaught_exception())
243 {
244#ifndef _LIBCPP_NO_EXCEPTIONS
245 try
246 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000247#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000248 if (__os_.rdbuf()->pubsync() == -1)
249 __os_.setstate(ios_base::badbit);
250#ifndef _LIBCPP_NO_EXCEPTIONS
251 }
252 catch (...)
253 {
254 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000255#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 }
257}
258
259template <class _CharT, class _Traits>
260inline _LIBCPP_INLINE_VISIBILITY
261basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
262{
263 this->init(__sb);
264}
265
Howard Hinnant74279a52010-09-04 23:28:19 +0000266#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267
268template <class _CharT, class _Traits>
269inline _LIBCPP_INLINE_VISIBILITY
270basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
271{
272 this->move(__rhs);
273}
274
275template <class _CharT, class _Traits>
276inline _LIBCPP_INLINE_VISIBILITY
277basic_ostream<_CharT, _Traits>&
278basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
279{
280 swap(__rhs);
281 return *this;
282}
283
Howard Hinnant74279a52010-09-04 23:28:19 +0000284#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285
286template <class _CharT, class _Traits>
287basic_ostream<_CharT, _Traits>::~basic_ostream()
288{
289}
290
291template <class _CharT, class _Traits>
292inline _LIBCPP_INLINE_VISIBILITY
293void
294basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
295{
296 basic_ios<char_type, traits_type>::swap(__rhs);
297}
298
299template <class _CharT, class _Traits>
300inline _LIBCPP_INLINE_VISIBILITY
301basic_ostream<_CharT, _Traits>&
302basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
303{
304 return __pf(*this);
305}
306
307template <class _CharT, class _Traits>
308inline _LIBCPP_INLINE_VISIBILITY
309basic_ostream<_CharT, _Traits>&
310basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
311 (*__pf)(basic_ios<char_type,traits_type>&))
312{
313 __pf(*this);
314 return *this;
315}
316
317template <class _CharT, class _Traits>
318inline _LIBCPP_INLINE_VISIBILITY
319basic_ostream<_CharT, _Traits>&
320basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
321{
322 __pf(*this);
323 return *this;
324}
325
326template <class _CharT, class _Traits>
327basic_ostream<_CharT, _Traits>&
328basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
329{
330#ifndef _LIBCPP_NO_EXCEPTIONS
331 try
332 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000333#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334 sentry __s(*this);
335 if (__s)
336 {
337 if (__sb)
338 {
339#ifndef _LIBCPP_NO_EXCEPTIONS
340 try
341 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000342#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343 typedef istreambuf_iterator<_CharT, _Traits> _I;
344 typedef ostreambuf_iterator<_CharT, _Traits> _O;
345 _I __i(__sb);
346 _I __eof;
347 _O __o(*this);
348 size_t __c = 0;
349 for (; __i != __eof; ++__i, ++__o, ++__c)
350 {
351 *__o = *__i;
352 if (__o.failed())
353 break;
354 }
355 if (__c == 0)
356 this->setstate(ios_base::failbit);
357#ifndef _LIBCPP_NO_EXCEPTIONS
358 }
359 catch (...)
360 {
361 this->__set_failbit_and_consider_rethrow();
362 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000363#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 }
365 else
366 this->setstate(ios_base::badbit);
367 }
368#ifndef _LIBCPP_NO_EXCEPTIONS
369 }
370 catch (...)
371 {
372 this->__set_badbit_and_consider_rethrow();
373 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000374#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 return *this;
376}
377
378template <class _CharT, class _Traits>
379basic_ostream<_CharT, _Traits>&
380basic_ostream<_CharT, _Traits>::operator<<(bool __n)
381{
382#ifndef _LIBCPP_NO_EXCEPTIONS
383 try
384 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000385#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 sentry __s(*this);
387 if (__s)
388 {
389 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
390 const _F& __f = use_facet<_F>(this->getloc());
391 if (__f.put(*this, *this, this->fill(), __n).failed())
392 this->setstate(ios_base::badbit | ios_base::failbit);
393 }
394#ifndef _LIBCPP_NO_EXCEPTIONS
395 }
396 catch (...)
397 {
398 this->__set_badbit_and_consider_rethrow();
399 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000400#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 return *this;
402}
403
404template <class _CharT, class _Traits>
405basic_ostream<_CharT, _Traits>&
406basic_ostream<_CharT, _Traits>::operator<<(short __n)
407{
408#ifndef _LIBCPP_NO_EXCEPTIONS
409 try
410 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000411#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 sentry __s(*this);
413 if (__s)
414 {
415 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
416 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
417 const _F& __f = use_facet<_F>(this->getloc());
418 if (__f.put(*this, *this, this->fill(),
419 __flags == ios_base::oct || __flags == ios_base::hex ?
420 static_cast<long>(static_cast<unsigned short>(__n)) :
421 static_cast<long>(__n)).failed())
422 this->setstate(ios_base::badbit | ios_base::failbit);
423 }
424#ifndef _LIBCPP_NO_EXCEPTIONS
425 }
426 catch (...)
427 {
428 this->__set_badbit_and_consider_rethrow();
429 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000430#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431 return *this;
432}
433
434template <class _CharT, class _Traits>
435basic_ostream<_CharT, _Traits>&
436basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
437{
438#ifndef _LIBCPP_NO_EXCEPTIONS
439 try
440 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000441#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 sentry __s(*this);
443 if (__s)
444 {
445 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
446 const _F& __f = use_facet<_F>(this->getloc());
447 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
448 this->setstate(ios_base::badbit | ios_base::failbit);
449 }
450#ifndef _LIBCPP_NO_EXCEPTIONS
451 }
452 catch (...)
453 {
454 this->__set_badbit_and_consider_rethrow();
455 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000456#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457 return *this;
458}
459
460template <class _CharT, class _Traits>
461basic_ostream<_CharT, _Traits>&
462basic_ostream<_CharT, _Traits>::operator<<(int __n)
463{
464#ifndef _LIBCPP_NO_EXCEPTIONS
465 try
466 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000467#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 sentry __s(*this);
469 if (__s)
470 {
471 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
472 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
473 const _F& __f = use_facet<_F>(this->getloc());
474 if (__f.put(*this, *this, this->fill(),
475 __flags == ios_base::oct || __flags == ios_base::hex ?
476 static_cast<long>(static_cast<unsigned int>(__n)) :
477 static_cast<long>(__n)).failed())
478 this->setstate(ios_base::badbit | ios_base::failbit);
479 }
480#ifndef _LIBCPP_NO_EXCEPTIONS
481 }
482 catch (...)
483 {
484 this->__set_badbit_and_consider_rethrow();
485 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000486#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 return *this;
488}
489
490template <class _CharT, class _Traits>
491basic_ostream<_CharT, _Traits>&
492basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
493{
494#ifndef _LIBCPP_NO_EXCEPTIONS
495 try
496 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000497#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 sentry __s(*this);
499 if (__s)
500 {
501 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
502 const _F& __f = use_facet<_F>(this->getloc());
503 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
504 this->setstate(ios_base::badbit | ios_base::failbit);
505 }
506#ifndef _LIBCPP_NO_EXCEPTIONS
507 }
508 catch (...)
509 {
510 this->__set_badbit_and_consider_rethrow();
511 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000512#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 return *this;
514}
515
516template <class _CharT, class _Traits>
517basic_ostream<_CharT, _Traits>&
518basic_ostream<_CharT, _Traits>::operator<<(long __n)
519{
520#ifndef _LIBCPP_NO_EXCEPTIONS
521 try
522 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000523#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 sentry __s(*this);
525 if (__s)
526 {
527 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
528 const _F& __f = use_facet<_F>(this->getloc());
529 if (__f.put(*this, *this, this->fill(), __n).failed())
530 this->setstate(ios_base::badbit | ios_base::failbit);
531 }
532#ifndef _LIBCPP_NO_EXCEPTIONS
533 }
534 catch (...)
535 {
536 this->__set_badbit_and_consider_rethrow();
537 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000538#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539 return *this;
540}
541
542template <class _CharT, class _Traits>
543basic_ostream<_CharT, _Traits>&
544basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
545{
546#ifndef _LIBCPP_NO_EXCEPTIONS
547 try
548 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000549#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550 sentry __s(*this);
551 if (__s)
552 {
553 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
554 const _F& __f = use_facet<_F>(this->getloc());
555 if (__f.put(*this, *this, this->fill(), __n).failed())
556 this->setstate(ios_base::badbit | ios_base::failbit);
557 }
558#ifndef _LIBCPP_NO_EXCEPTIONS
559 }
560 catch (...)
561 {
562 this->__set_badbit_and_consider_rethrow();
563 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000564#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 return *this;
566}
567
568template <class _CharT, class _Traits>
569basic_ostream<_CharT, _Traits>&
570basic_ostream<_CharT, _Traits>::operator<<(long long __n)
571{
572#ifndef _LIBCPP_NO_EXCEPTIONS
573 try
574 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000575#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576 sentry __s(*this);
577 if (__s)
578 {
579 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
580 const _F& __f = use_facet<_F>(this->getloc());
581 if (__f.put(*this, *this, this->fill(), __n).failed())
582 this->setstate(ios_base::badbit | ios_base::failbit);
583 }
584#ifndef _LIBCPP_NO_EXCEPTIONS
585 }
586 catch (...)
587 {
588 this->__set_badbit_and_consider_rethrow();
589 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000590#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 return *this;
592}
593
594template <class _CharT, class _Traits>
595basic_ostream<_CharT, _Traits>&
596basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
597{
598#ifndef _LIBCPP_NO_EXCEPTIONS
599 try
600 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000601#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602 sentry __s(*this);
603 if (__s)
604 {
605 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
606 const _F& __f = use_facet<_F>(this->getloc());
607 if (__f.put(*this, *this, this->fill(), __n).failed())
608 this->setstate(ios_base::badbit | ios_base::failbit);
609 }
610#ifndef _LIBCPP_NO_EXCEPTIONS
611 }
612 catch (...)
613 {
614 this->__set_badbit_and_consider_rethrow();
615 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000616#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 return *this;
618}
619
620template <class _CharT, class _Traits>
621basic_ostream<_CharT, _Traits>&
622basic_ostream<_CharT, _Traits>::operator<<(float __n)
623{
624#ifndef _LIBCPP_NO_EXCEPTIONS
625 try
626 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000627#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628 sentry __s(*this);
629 if (__s)
630 {
631 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
632 const _F& __f = use_facet<_F>(this->getloc());
633 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
634 this->setstate(ios_base::badbit | ios_base::failbit);
635 }
636#ifndef _LIBCPP_NO_EXCEPTIONS
637 }
638 catch (...)
639 {
640 this->__set_badbit_and_consider_rethrow();
641 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000642#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 return *this;
644}
645
646template <class _CharT, class _Traits>
647basic_ostream<_CharT, _Traits>&
648basic_ostream<_CharT, _Traits>::operator<<(double __n)
649{
650#ifndef _LIBCPP_NO_EXCEPTIONS
651 try
652 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000653#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 sentry __s(*this);
655 if (__s)
656 {
657 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
658 const _F& __f = use_facet<_F>(this->getloc());
659 if (__f.put(*this, *this, this->fill(), __n).failed())
660 this->setstate(ios_base::badbit | ios_base::failbit);
661 }
662#ifndef _LIBCPP_NO_EXCEPTIONS
663 }
664 catch (...)
665 {
666 this->__set_badbit_and_consider_rethrow();
667 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000668#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 return *this;
670}
671
672template <class _CharT, class _Traits>
673basic_ostream<_CharT, _Traits>&
674basic_ostream<_CharT, _Traits>::operator<<(long double __n)
675{
676#ifndef _LIBCPP_NO_EXCEPTIONS
677 try
678 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000679#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680 sentry __s(*this);
681 if (__s)
682 {
683 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
684 const _F& __f = use_facet<_F>(this->getloc());
685 if (__f.put(*this, *this, this->fill(), __n).failed())
686 this->setstate(ios_base::badbit | ios_base::failbit);
687 }
688#ifndef _LIBCPP_NO_EXCEPTIONS
689 }
690 catch (...)
691 {
692 this->__set_badbit_and_consider_rethrow();
693 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000694#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 return *this;
696}
697
698template <class _CharT, class _Traits>
699basic_ostream<_CharT, _Traits>&
700basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
701{
702#ifndef _LIBCPP_NO_EXCEPTIONS
703 try
704 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000705#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706 sentry __s(*this);
707 if (__s)
708 {
709 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _F;
710 const _F& __f = use_facet<_F>(this->getloc());
711 if (__f.put(*this, *this, this->fill(), __n).failed())
712 this->setstate(ios_base::badbit | ios_base::failbit);
713 }
714#ifndef _LIBCPP_NO_EXCEPTIONS
715 }
716 catch (...)
717 {
718 this->__set_badbit_and_consider_rethrow();
719 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000720#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721 return *this;
722}
723
724template<class _CharT, class _Traits>
725basic_ostream<_CharT, _Traits>&
726operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
727{
728#ifndef _LIBCPP_NO_EXCEPTIONS
729 try
730 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000731#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
733 if (__s)
734 {
735 typedef ostreambuf_iterator<_CharT, _Traits> _I;
736 if (__pad_and_output(_I(__os),
737 &__c,
738 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
739 &__c + 1 :
740 &__c,
741 &__c + 1,
742 __os,
743 __os.fill()).failed())
744 __os.setstate(ios_base::badbit | ios_base::failbit);
745 }
746#ifndef _LIBCPP_NO_EXCEPTIONS
747 }
748 catch (...)
749 {
750 __os.__set_badbit_and_consider_rethrow();
751 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000752#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 return __os;
754}
755
756template<class _CharT, class _Traits>
757basic_ostream<_CharT, _Traits>&
758operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
759{
760#ifndef _LIBCPP_NO_EXCEPTIONS
761 try
762 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000763#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
765 if (__s)
766 {
767 _CharT __c = __os.widen(__cn);
768 typedef ostreambuf_iterator<_CharT, _Traits> _I;
769 if (__pad_and_output(_I(__os),
770 &__c,
771 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
772 &__c + 1 :
773 &__c,
774 &__c + 1,
775 __os,
776 __os.fill()).failed())
777 __os.setstate(ios_base::badbit | ios_base::failbit);
778 }
779#ifndef _LIBCPP_NO_EXCEPTIONS
780 }
781 catch (...)
782 {
783 __os.__set_badbit_and_consider_rethrow();
784 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000785#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786 return __os;
787}
788
789template<class _Traits>
790basic_ostream<char, _Traits>&
791operator<<(basic_ostream<char, _Traits>& __os, char __c)
792{
793#ifndef _LIBCPP_NO_EXCEPTIONS
794 try
795 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000796#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797 typename basic_ostream<char, _Traits>::sentry __s(__os);
798 if (__s)
799 {
800 typedef ostreambuf_iterator<char, _Traits> _I;
801 if (__pad_and_output(_I(__os),
802 &__c,
803 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
804 &__c + 1 :
805 &__c,
806 &__c + 1,
807 __os,
808 __os.fill()).failed())
809 __os.setstate(ios_base::badbit | ios_base::failbit);
810 }
811#ifndef _LIBCPP_NO_EXCEPTIONS
812 }
813 catch (...)
814 {
815 __os.__set_badbit_and_consider_rethrow();
816 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000817#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 return __os;
819}
820
821template<class _Traits>
822basic_ostream<char, _Traits>&
823operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
824{
825#ifndef _LIBCPP_NO_EXCEPTIONS
826 try
827 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000828#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 typename basic_ostream<char, _Traits>::sentry __s(__os);
830 if (__s)
831 {
832 typedef ostreambuf_iterator<char, _Traits> _I;
833 if (__pad_and_output(_I(__os),
834 (char*)&__c,
835 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
836 (char*)&__c + 1 :
837 (char*)&__c,
838 (char*)&__c + 1,
839 __os,
840 __os.fill()).failed())
841 __os.setstate(ios_base::badbit | ios_base::failbit);
842 }
843#ifndef _LIBCPP_NO_EXCEPTIONS
844 }
845 catch (...)
846 {
847 __os.__set_badbit_and_consider_rethrow();
848 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000849#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 return __os;
851}
852
853template<class _Traits>
854basic_ostream<char, _Traits>&
855operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
856{
857#ifndef _LIBCPP_NO_EXCEPTIONS
858 try
859 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000860#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 typename basic_ostream<char, _Traits>::sentry __s(__os);
862 if (__s)
863 {
864 typedef ostreambuf_iterator<char, _Traits> _I;
865 if (__pad_and_output(_I(__os),
866 (char*)&__c,
867 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
868 (char*)&__c + 1 :
869 (char*)&__c,
870 (char*)&__c + 1,
871 __os,
872 __os.fill()).failed())
873 __os.setstate(ios_base::badbit | ios_base::failbit);
874 }
875#ifndef _LIBCPP_NO_EXCEPTIONS
876 }
877 catch (...)
878 {
879 __os.__set_badbit_and_consider_rethrow();
880 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000881#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 return __os;
883}
884
885template<class _CharT, class _Traits>
886basic_ostream<_CharT, _Traits>&
887operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
888{
889#ifndef _LIBCPP_NO_EXCEPTIONS
890 try
891 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000892#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
894 if (__s)
895 {
896 typedef ostreambuf_iterator<_CharT, _Traits> _I;
897 size_t __len = _Traits::length(__str);
898 if (__pad_and_output(_I(__os),
899 __str,
900 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
901 __str + __len :
902 __str,
903 __str + __len,
904 __os,
905 __os.fill()).failed())
906 __os.setstate(ios_base::badbit | ios_base::failbit);
907 }
908#ifndef _LIBCPP_NO_EXCEPTIONS
909 }
910 catch (...)
911 {
912 __os.__set_badbit_and_consider_rethrow();
913 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000914#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 return __os;
916}
917
918template<class _CharT, class _Traits>
919basic_ostream<_CharT, _Traits>&
920operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
921{
922#ifndef _LIBCPP_NO_EXCEPTIONS
923 try
924 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000925#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
927 if (__s)
928 {
929 typedef ostreambuf_iterator<_CharT, _Traits> _I;
930 size_t __len = char_traits<char>::length(__strn);
931 const int __bs = 100;
932 _CharT __wbb[__bs];
933 _CharT* __wb = __wbb;
934 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
935 if (__len > __bs)
936 {
937 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
938 if (__wb == 0)
939 __throw_bad_alloc();
940 __h.reset(__wb);
941 }
942 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
943 *__p = __os.widen(*__strn);
944 if (__pad_and_output(_I(__os),
945 __wb,
946 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
947 __wb + __len :
948 __wb,
949 __wb + __len,
950 __os,
951 __os.fill()).failed())
952 __os.setstate(ios_base::badbit | ios_base::failbit);
953 }
954#ifndef _LIBCPP_NO_EXCEPTIONS
955 }
956 catch (...)
957 {
958 __os.__set_badbit_and_consider_rethrow();
959 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000960#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 return __os;
962}
963
964template<class _Traits>
965basic_ostream<char, _Traits>&
966operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
967{
968#ifndef _LIBCPP_NO_EXCEPTIONS
969 try
970 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000971#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 typename basic_ostream<char, _Traits>::sentry __s(__os);
973 if (__s)
974 {
975 typedef ostreambuf_iterator<char, _Traits> _I;
976 size_t __len = _Traits::length(__str);
977 if (__pad_and_output(_I(__os),
978 __str,
979 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
980 __str + __len :
981 __str,
982 __str + __len,
983 __os,
984 __os.fill()).failed())
985 __os.setstate(ios_base::badbit | ios_base::failbit);
986 }
987#ifndef _LIBCPP_NO_EXCEPTIONS
988 }
989 catch (...)
990 {
991 __os.__set_badbit_and_consider_rethrow();
992 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000993#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 return __os;
995}
996
997template<class _Traits>
998basic_ostream<char, _Traits>&
999operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
1000{
1001#ifndef _LIBCPP_NO_EXCEPTIONS
1002 try
1003 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001004#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 typename basic_ostream<char, _Traits>::sentry __s(__os);
1006 if (__s)
1007 {
1008 typedef ostreambuf_iterator<char, _Traits> _I;
1009 size_t __len = _Traits::length((const char*)__str);
1010 if (__pad_and_output(_I(__os),
1011 (const char*)__str,
1012 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1013 (const char*)__str + __len :
1014 (const char*)__str,
1015 (const char*)__str + __len,
1016 __os,
1017 __os.fill()).failed())
1018 __os.setstate(ios_base::badbit | ios_base::failbit);
1019 }
1020#ifndef _LIBCPP_NO_EXCEPTIONS
1021 }
1022 catch (...)
1023 {
1024 __os.__set_badbit_and_consider_rethrow();
1025 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001026#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 return __os;
1028}
1029
1030template<class _Traits>
1031basic_ostream<char, _Traits>&
1032operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
1033{
1034#ifndef _LIBCPP_NO_EXCEPTIONS
1035 try
1036 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001037#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038 typename basic_ostream<char, _Traits>::sentry __s(__os);
1039 if (__s)
1040 {
1041 typedef ostreambuf_iterator<char, _Traits> _I;
1042 size_t __len = _Traits::length((const char*)__str);
1043 if (__pad_and_output(_I(__os),
1044 (const char*)__str,
1045 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1046 (const char*)__str + __len :
1047 (const char*)__str,
1048 (const char*)__str + __len,
1049 __os,
1050 __os.fill()).failed())
1051 __os.setstate(ios_base::badbit | ios_base::failbit);
1052 }
1053#ifndef _LIBCPP_NO_EXCEPTIONS
1054 }
1055 catch (...)
1056 {
1057 __os.__set_badbit_and_consider_rethrow();
1058 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001059#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 return __os;
1061}
1062
1063template <class _CharT, class _Traits>
1064basic_ostream<_CharT, _Traits>&
1065basic_ostream<_CharT, _Traits>::put(char_type __c)
1066{
1067#ifndef _LIBCPP_NO_EXCEPTIONS
1068 try
1069 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001070#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071 sentry __s(*this);
1072 if (__s)
1073 {
1074 typedef ostreambuf_iterator<_CharT, _Traits> _O;
1075 _O __o(*this);
1076 *__o = __c;
1077 if (__o.failed())
1078 this->setstate(ios_base::badbit);
1079 }
1080#ifndef _LIBCPP_NO_EXCEPTIONS
1081 }
1082 catch (...)
1083 {
1084 this->__set_badbit_and_consider_rethrow();
1085 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001086#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 return *this;
1088}
1089
1090template <class _CharT, class _Traits>
1091basic_ostream<_CharT, _Traits>&
1092basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
1093{
1094#ifndef _LIBCPP_NO_EXCEPTIONS
1095 try
1096 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001097#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098 sentry __sen(*this);
1099 if (__sen && __n)
1100 {
1101 typedef ostreambuf_iterator<_CharT, _Traits> _O;
1102 _O __o(*this);
1103 for (; __n; --__n, ++__o, ++__s)
1104 {
1105 *__o = *__s;
1106 if (__o.failed())
1107 {
1108 this->setstate(ios_base::badbit);
1109 break;
1110 }
1111 }
1112 }
1113#ifndef _LIBCPP_NO_EXCEPTIONS
1114 }
1115 catch (...)
1116 {
1117 this->__set_badbit_and_consider_rethrow();
1118 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001119#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 return *this;
1121}
1122
1123template <class _CharT, class _Traits>
1124basic_ostream<_CharT, _Traits>&
1125basic_ostream<_CharT, _Traits>::flush()
1126{
1127#ifndef _LIBCPP_NO_EXCEPTIONS
1128 try
1129 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001130#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131 if (this->rdbuf())
1132 {
1133 sentry __s(*this);
1134 if (__s)
1135 {
1136 if (this->rdbuf()->pubsync() == -1)
1137 this->setstate(ios_base::badbit);
1138 }
1139 }
1140#ifndef _LIBCPP_NO_EXCEPTIONS
1141 }
1142 catch (...)
1143 {
1144 this->__set_badbit_and_consider_rethrow();
1145 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001146#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 return *this;
1148}
1149
1150template <class _CharT, class _Traits>
1151inline _LIBCPP_INLINE_VISIBILITY
1152typename basic_ostream<_CharT, _Traits>::pos_type
1153basic_ostream<_CharT, _Traits>::tellp()
1154{
1155 if (this->fail())
1156 return pos_type(-1);
1157 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1158}
1159
1160template <class _CharT, class _Traits>
1161inline _LIBCPP_INLINE_VISIBILITY
1162basic_ostream<_CharT, _Traits>&
1163basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1164{
1165 if (!this->fail())
1166 {
1167 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1168 this->setstate(ios_base::failbit);
1169 }
1170 return *this;
1171}
1172
1173template <class _CharT, class _Traits>
1174inline _LIBCPP_INLINE_VISIBILITY
1175basic_ostream<_CharT, _Traits>&
1176basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1177{
1178 if (!this->fail())
1179 this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
1180 return *this;
1181}
1182
1183template <class _CharT, class _Traits>
1184inline _LIBCPP_INLINE_VISIBILITY
1185basic_ostream<_CharT, _Traits>&
1186endl(basic_ostream<_CharT, _Traits>& __os)
1187{
1188 __os.put(__os.widen('\n'));
1189 __os.flush();
1190 return __os;
1191}
1192
1193template <class _CharT, class _Traits>
1194inline _LIBCPP_INLINE_VISIBILITY
1195basic_ostream<_CharT, _Traits>&
1196ends(basic_ostream<_CharT, _Traits>& __os)
1197{
1198 __os.put(_CharT());
1199 return __os;
1200}
1201
1202template <class _CharT, class _Traits>
1203inline _LIBCPP_INLINE_VISIBILITY
1204basic_ostream<_CharT, _Traits>&
1205flush(basic_ostream<_CharT, _Traits>& __os)
1206{
1207 __os.flush();
1208 return __os;
1209}
1210
Howard Hinnant74279a52010-09-04 23:28:19 +00001211#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212
1213template <class _Stream, class _Tp>
1214inline _LIBCPP_INLINE_VISIBILITY
1215typename enable_if
1216<
1217 !is_lvalue_reference<_Stream>::value &&
1218 is_base_of<ios_base, _Stream>::value,
1219 _Stream&
1220>::type
1221operator<<(_Stream&& __os, const _Tp& __x)
1222{
1223 __os << __x;
1224 return __os;
1225}
1226
Howard Hinnant74279a52010-09-04 23:28:19 +00001227#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
1229template<class _CharT, class _Traits, class _Allocator>
1230basic_ostream<_CharT, _Traits>&
1231operator<<(basic_ostream<_CharT, _Traits>& __os,
1232 const basic_string<_CharT, _Traits, _Allocator>& __str)
1233{
1234#ifndef _LIBCPP_NO_EXCEPTIONS
1235 try
1236 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001237#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
1239 if (__s)
1240 {
1241 typedef ostreambuf_iterator<_CharT, _Traits> _I;
1242 size_t __len = __str.size();
1243 if (__pad_and_output(_I(__os),
1244 __str.data(),
1245 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1246 __str.data() + __len :
1247 __str.data(),
1248 __str.data() + __len,
1249 __os,
1250 __os.fill()).failed())
1251 __os.setstate(ios_base::badbit | ios_base::failbit);
1252 }
1253#ifndef _LIBCPP_NO_EXCEPTIONS
1254 }
1255 catch (...)
1256 {
1257 __os.__set_badbit_and_consider_rethrow();
1258 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001259#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260 return __os;
1261}
1262
1263template <class _CharT, class _Traits>
1264inline _LIBCPP_INLINE_VISIBILITY
1265basic_ostream<_CharT, _Traits>&
1266operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1267{
1268 return __os << __ec.category().name() << ':' << __ec.value();
1269}
1270
1271template<class _CharT, class _Traits, class _Y>
1272inline _LIBCPP_INLINE_VISIBILITY
1273basic_ostream<_CharT, _Traits>&
1274operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Y> const& __p)
1275{
1276 return __os << __p.get();
1277}
1278
1279template <class _CharT, class _Traits, size_t _Size>
1280basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001281operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282{
1283 return __os << __x.template to_string<_CharT, _Traits>
1284 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1285 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1286}
1287
1288extern template class basic_ostream<char>;
1289extern template class basic_ostream<wchar_t>;
1290
1291_LIBCPP_END_NAMESPACE_STD
1292
1293#endif // _LIBCPP_OSTREAM