blob: b135ddb7713a874eae60d042fbd4c572135f0bf6 [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
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
Howard Hinnant08e17472011-10-17 20:05:10 +0000136#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000138#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000139
140_LIBCPP_BEGIN_NAMESPACE_STD
141
142template <class _CharT, class _Traits>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000143class _LIBCPP_VISIBLE basic_ostream
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144 : virtual public basic_ios<_CharT, _Traits>
145{
146public:
147 // types (inherited from basic_ios (27.5.4)):
148 typedef _CharT char_type;
149 typedef _Traits traits_type;
150 typedef typename traits_type::int_type int_type;
151 typedef typename traits_type::pos_type pos_type;
152 typedef typename traits_type::off_type off_type;
153
154 // 27.7.2.2 Constructor/destructor:
155 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
156 virtual ~basic_ostream();
157protected:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000158#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160 basic_ostream(basic_ostream&& __rhs);
161#endif
162
163 // 27.7.2.3 Assign/swap
Howard Hinnant73d21a42010-09-04 23:28:19 +0000164#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantac6de542011-07-07 21:03:52 +0000165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000166 basic_ostream& operator=(basic_ostream&& __rhs);
167#endif
168 void swap(basic_ostream& __rhs);
169public:
170
171 // 27.7.2.4 Prefix/suffix:
Howard Hinnant33be35e2012-09-14 00:39:16 +0000172 class _LIBCPP_VISIBLE sentry;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000173
174 // 27.7.2.6 Formatted output:
175 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
176 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
177 (*__pf)(basic_ios<char_type,traits_type>&));
178 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
179 basic_ostream& operator<<(bool __n);
180 basic_ostream& operator<<(short __n);
181 basic_ostream& operator<<(unsigned short __n);
182 basic_ostream& operator<<(int __n);
183 basic_ostream& operator<<(unsigned int __n);
184 basic_ostream& operator<<(long __n);
185 basic_ostream& operator<<(unsigned long __n);
186 basic_ostream& operator<<(long long __n);
187 basic_ostream& operator<<(unsigned long long __n);
188 basic_ostream& operator<<(float __f);
189 basic_ostream& operator<<(double __f);
190 basic_ostream& operator<<(long double __f);
191 basic_ostream& operator<<(const void* __p);
192 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
193
194 // 27.7.2.7 Unformatted output:
195 basic_ostream& put(char_type __c);
196 basic_ostream& write(const char_type* __s, streamsize __n);
197 basic_ostream& flush();
198
199 // 27.7.2.5 seeks:
200 pos_type tellp();
201 basic_ostream& seekp(pos_type __pos);
202 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
203
204protected:
205 _LIBCPP_ALWAYS_INLINE
206 basic_ostream() {} // extension, intentially does not initialize
207};
208
209template <class _CharT, class _Traits>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000210class _LIBCPP_VISIBLE basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000211{
212 bool __ok_;
213 basic_ostream<_CharT, _Traits>& __os_;
214
215 sentry(const sentry&); // = delete;
216 sentry& operator=(const sentry&); // = delete;
217
218public:
219 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
220 ~sentry();
221
222 _LIBCPP_ALWAYS_INLINE
Howard Hinnant77861882012-02-21 21:46:43 +0000223 _LIBCPP_EXPLICIT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000224 operator bool() const {return __ok_;}
225};
226
227template <class _CharT, class _Traits>
228basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
229 : __ok_(false),
230 __os_(__os)
231{
232 if (__os.good())
233 {
234 if (__os.tie())
235 __os.tie()->flush();
236 __ok_ = true;
237 }
238}
239
240template <class _CharT, class _Traits>
241basic_ostream<_CharT, _Traits>::sentry::~sentry()
242{
243 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
244 && !uncaught_exception())
245 {
246#ifndef _LIBCPP_NO_EXCEPTIONS
247 try
248 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000249#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250 if (__os_.rdbuf()->pubsync() == -1)
251 __os_.setstate(ios_base::badbit);
252#ifndef _LIBCPP_NO_EXCEPTIONS
253 }
254 catch (...)
255 {
256 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000257#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 }
259}
260
261template <class _CharT, class _Traits>
262inline _LIBCPP_INLINE_VISIBILITY
263basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
264{
265 this->init(__sb);
266}
267
Howard Hinnant73d21a42010-09-04 23:28:19 +0000268#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
270template <class _CharT, class _Traits>
271inline _LIBCPP_INLINE_VISIBILITY
272basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
273{
274 this->move(__rhs);
275}
276
277template <class _CharT, class _Traits>
278inline _LIBCPP_INLINE_VISIBILITY
279basic_ostream<_CharT, _Traits>&
280basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
281{
282 swap(__rhs);
283 return *this;
284}
285
Howard Hinnant73d21a42010-09-04 23:28:19 +0000286#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287
288template <class _CharT, class _Traits>
289basic_ostream<_CharT, _Traits>::~basic_ostream()
290{
291}
292
293template <class _CharT, class _Traits>
294inline _LIBCPP_INLINE_VISIBILITY
295void
296basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
297{
298 basic_ios<char_type, traits_type>::swap(__rhs);
299}
300
301template <class _CharT, class _Traits>
302inline _LIBCPP_INLINE_VISIBILITY
303basic_ostream<_CharT, _Traits>&
304basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
305{
306 return __pf(*this);
307}
308
309template <class _CharT, class _Traits>
310inline _LIBCPP_INLINE_VISIBILITY
311basic_ostream<_CharT, _Traits>&
312basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
313 (*__pf)(basic_ios<char_type,traits_type>&))
314{
315 __pf(*this);
316 return *this;
317}
318
319template <class _CharT, class _Traits>
320inline _LIBCPP_INLINE_VISIBILITY
321basic_ostream<_CharT, _Traits>&
322basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
323{
324 __pf(*this);
325 return *this;
326}
327
328template <class _CharT, class _Traits>
329basic_ostream<_CharT, _Traits>&
330basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
331{
332#ifndef _LIBCPP_NO_EXCEPTIONS
333 try
334 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000335#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336 sentry __s(*this);
337 if (__s)
338 {
339 if (__sb)
340 {
341#ifndef _LIBCPP_NO_EXCEPTIONS
342 try
343 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000344#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant99968442011-11-29 18:15:50 +0000345 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
346 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
347 _Ip __i(__sb);
348 _Ip __eof;
349 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350 size_t __c = 0;
351 for (; __i != __eof; ++__i, ++__o, ++__c)
352 {
353 *__o = *__i;
354 if (__o.failed())
355 break;
356 }
357 if (__c == 0)
358 this->setstate(ios_base::failbit);
359#ifndef _LIBCPP_NO_EXCEPTIONS
360 }
361 catch (...)
362 {
363 this->__set_failbit_and_consider_rethrow();
364 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000365#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366 }
367 else
368 this->setstate(ios_base::badbit);
369 }
370#ifndef _LIBCPP_NO_EXCEPTIONS
371 }
372 catch (...)
373 {
374 this->__set_badbit_and_consider_rethrow();
375 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000376#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 return *this;
378}
379
380template <class _CharT, class _Traits>
381basic_ostream<_CharT, _Traits>&
382basic_ostream<_CharT, _Traits>::operator<<(bool __n)
383{
384#ifndef _LIBCPP_NO_EXCEPTIONS
385 try
386 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000387#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 sentry __s(*this);
389 if (__s)
390 {
Howard Hinnant99968442011-11-29 18:15:50 +0000391 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
392 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393 if (__f.put(*this, *this, this->fill(), __n).failed())
394 this->setstate(ios_base::badbit | ios_base::failbit);
395 }
396#ifndef _LIBCPP_NO_EXCEPTIONS
397 }
398 catch (...)
399 {
400 this->__set_badbit_and_consider_rethrow();
401 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000402#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403 return *this;
404}
405
406template <class _CharT, class _Traits>
407basic_ostream<_CharT, _Traits>&
408basic_ostream<_CharT, _Traits>::operator<<(short __n)
409{
410#ifndef _LIBCPP_NO_EXCEPTIONS
411 try
412 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000413#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 sentry __s(*this);
415 if (__s)
416 {
417 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnant99968442011-11-29 18:15:50 +0000418 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
419 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 if (__f.put(*this, *this, this->fill(),
421 __flags == ios_base::oct || __flags == ios_base::hex ?
422 static_cast<long>(static_cast<unsigned short>(__n)) :
423 static_cast<long>(__n)).failed())
424 this->setstate(ios_base::badbit | ios_base::failbit);
425 }
426#ifndef _LIBCPP_NO_EXCEPTIONS
427 }
428 catch (...)
429 {
430 this->__set_badbit_and_consider_rethrow();
431 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000432#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 return *this;
434}
435
436template <class _CharT, class _Traits>
437basic_ostream<_CharT, _Traits>&
438basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
439{
440#ifndef _LIBCPP_NO_EXCEPTIONS
441 try
442 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000443#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 sentry __s(*this);
445 if (__s)
446 {
Howard Hinnant99968442011-11-29 18:15:50 +0000447 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
448 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
450 this->setstate(ios_base::badbit | ios_base::failbit);
451 }
452#ifndef _LIBCPP_NO_EXCEPTIONS
453 }
454 catch (...)
455 {
456 this->__set_badbit_and_consider_rethrow();
457 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000458#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 return *this;
460}
461
462template <class _CharT, class _Traits>
463basic_ostream<_CharT, _Traits>&
464basic_ostream<_CharT, _Traits>::operator<<(int __n)
465{
466#ifndef _LIBCPP_NO_EXCEPTIONS
467 try
468 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000469#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 sentry __s(*this);
471 if (__s)
472 {
473 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnant99968442011-11-29 18:15:50 +0000474 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
475 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 if (__f.put(*this, *this, this->fill(),
477 __flags == ios_base::oct || __flags == ios_base::hex ?
478 static_cast<long>(static_cast<unsigned int>(__n)) :
479 static_cast<long>(__n)).failed())
480 this->setstate(ios_base::badbit | ios_base::failbit);
481 }
482#ifndef _LIBCPP_NO_EXCEPTIONS
483 }
484 catch (...)
485 {
486 this->__set_badbit_and_consider_rethrow();
487 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000488#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 return *this;
490}
491
492template <class _CharT, class _Traits>
493basic_ostream<_CharT, _Traits>&
494basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
495{
496#ifndef _LIBCPP_NO_EXCEPTIONS
497 try
498 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000499#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 sentry __s(*this);
501 if (__s)
502 {
Howard Hinnant99968442011-11-29 18:15:50 +0000503 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
504 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
506 this->setstate(ios_base::badbit | ios_base::failbit);
507 }
508#ifndef _LIBCPP_NO_EXCEPTIONS
509 }
510 catch (...)
511 {
512 this->__set_badbit_and_consider_rethrow();
513 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000514#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 return *this;
516}
517
518template <class _CharT, class _Traits>
519basic_ostream<_CharT, _Traits>&
520basic_ostream<_CharT, _Traits>::operator<<(long __n)
521{
522#ifndef _LIBCPP_NO_EXCEPTIONS
523 try
524 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000525#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 sentry __s(*this);
527 if (__s)
528 {
Howard Hinnant99968442011-11-29 18:15:50 +0000529 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
530 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 if (__f.put(*this, *this, this->fill(), __n).failed())
532 this->setstate(ios_base::badbit | ios_base::failbit);
533 }
534#ifndef _LIBCPP_NO_EXCEPTIONS
535 }
536 catch (...)
537 {
538 this->__set_badbit_and_consider_rethrow();
539 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000540#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 return *this;
542}
543
544template <class _CharT, class _Traits>
545basic_ostream<_CharT, _Traits>&
546basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
547{
548#ifndef _LIBCPP_NO_EXCEPTIONS
549 try
550 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000551#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 sentry __s(*this);
553 if (__s)
554 {
Howard Hinnant99968442011-11-29 18:15:50 +0000555 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
556 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557 if (__f.put(*this, *this, this->fill(), __n).failed())
558 this->setstate(ios_base::badbit | ios_base::failbit);
559 }
560#ifndef _LIBCPP_NO_EXCEPTIONS
561 }
562 catch (...)
563 {
564 this->__set_badbit_and_consider_rethrow();
565 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000566#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567 return *this;
568}
569
570template <class _CharT, class _Traits>
571basic_ostream<_CharT, _Traits>&
572basic_ostream<_CharT, _Traits>::operator<<(long long __n)
573{
574#ifndef _LIBCPP_NO_EXCEPTIONS
575 try
576 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000577#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578 sentry __s(*this);
579 if (__s)
580 {
Howard Hinnant99968442011-11-29 18:15:50 +0000581 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
582 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583 if (__f.put(*this, *this, this->fill(), __n).failed())
584 this->setstate(ios_base::badbit | ios_base::failbit);
585 }
586#ifndef _LIBCPP_NO_EXCEPTIONS
587 }
588 catch (...)
589 {
590 this->__set_badbit_and_consider_rethrow();
591 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000592#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593 return *this;
594}
595
596template <class _CharT, class _Traits>
597basic_ostream<_CharT, _Traits>&
598basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
599{
600#ifndef _LIBCPP_NO_EXCEPTIONS
601 try
602 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000603#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604 sentry __s(*this);
605 if (__s)
606 {
Howard Hinnant99968442011-11-29 18:15:50 +0000607 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
608 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609 if (__f.put(*this, *this, this->fill(), __n).failed())
610 this->setstate(ios_base::badbit | ios_base::failbit);
611 }
612#ifndef _LIBCPP_NO_EXCEPTIONS
613 }
614 catch (...)
615 {
616 this->__set_badbit_and_consider_rethrow();
617 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000618#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619 return *this;
620}
621
622template <class _CharT, class _Traits>
623basic_ostream<_CharT, _Traits>&
624basic_ostream<_CharT, _Traits>::operator<<(float __n)
625{
626#ifndef _LIBCPP_NO_EXCEPTIONS
627 try
628 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000629#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630 sentry __s(*this);
631 if (__s)
632 {
Howard Hinnant99968442011-11-29 18:15:50 +0000633 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
634 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
636 this->setstate(ios_base::badbit | ios_base::failbit);
637 }
638#ifndef _LIBCPP_NO_EXCEPTIONS
639 }
640 catch (...)
641 {
642 this->__set_badbit_and_consider_rethrow();
643 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000644#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 return *this;
646}
647
648template <class _CharT, class _Traits>
649basic_ostream<_CharT, _Traits>&
650basic_ostream<_CharT, _Traits>::operator<<(double __n)
651{
652#ifndef _LIBCPP_NO_EXCEPTIONS
653 try
654 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000655#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 sentry __s(*this);
657 if (__s)
658 {
Howard Hinnant99968442011-11-29 18:15:50 +0000659 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
660 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 if (__f.put(*this, *this, this->fill(), __n).failed())
662 this->setstate(ios_base::badbit | ios_base::failbit);
663 }
664#ifndef _LIBCPP_NO_EXCEPTIONS
665 }
666 catch (...)
667 {
668 this->__set_badbit_and_consider_rethrow();
669 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000670#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671 return *this;
672}
673
674template <class _CharT, class _Traits>
675basic_ostream<_CharT, _Traits>&
676basic_ostream<_CharT, _Traits>::operator<<(long double __n)
677{
678#ifndef _LIBCPP_NO_EXCEPTIONS
679 try
680 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000681#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 sentry __s(*this);
683 if (__s)
684 {
Howard Hinnant99968442011-11-29 18:15:50 +0000685 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
686 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 if (__f.put(*this, *this, this->fill(), __n).failed())
688 this->setstate(ios_base::badbit | ios_base::failbit);
689 }
690#ifndef _LIBCPP_NO_EXCEPTIONS
691 }
692 catch (...)
693 {
694 this->__set_badbit_and_consider_rethrow();
695 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000696#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 return *this;
698}
699
700template <class _CharT, class _Traits>
701basic_ostream<_CharT, _Traits>&
702basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
703{
704#ifndef _LIBCPP_NO_EXCEPTIONS
705 try
706 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000707#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 sentry __s(*this);
709 if (__s)
710 {
Howard Hinnant99968442011-11-29 18:15:50 +0000711 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
712 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 if (__f.put(*this, *this, this->fill(), __n).failed())
714 this->setstate(ios_base::badbit | ios_base::failbit);
715 }
716#ifndef _LIBCPP_NO_EXCEPTIONS
717 }
718 catch (...)
719 {
720 this->__set_badbit_and_consider_rethrow();
721 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000722#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 return *this;
724}
725
726template<class _CharT, class _Traits>
727basic_ostream<_CharT, _Traits>&
728operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
729{
730#ifndef _LIBCPP_NO_EXCEPTIONS
731 try
732 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000733#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
735 if (__s)
736 {
Howard Hinnant99968442011-11-29 18:15:50 +0000737 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
738 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 &__c,
740 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
741 &__c + 1 :
742 &__c,
743 &__c + 1,
744 __os,
745 __os.fill()).failed())
746 __os.setstate(ios_base::badbit | ios_base::failbit);
747 }
748#ifndef _LIBCPP_NO_EXCEPTIONS
749 }
750 catch (...)
751 {
752 __os.__set_badbit_and_consider_rethrow();
753 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000754#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 return __os;
756}
757
758template<class _CharT, class _Traits>
759basic_ostream<_CharT, _Traits>&
760operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
761{
762#ifndef _LIBCPP_NO_EXCEPTIONS
763 try
764 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000765#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
767 if (__s)
768 {
769 _CharT __c = __os.widen(__cn);
Howard Hinnant99968442011-11-29 18:15:50 +0000770 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
771 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 &__c,
773 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
774 &__c + 1 :
775 &__c,
776 &__c + 1,
777 __os,
778 __os.fill()).failed())
779 __os.setstate(ios_base::badbit | ios_base::failbit);
780 }
781#ifndef _LIBCPP_NO_EXCEPTIONS
782 }
783 catch (...)
784 {
785 __os.__set_badbit_and_consider_rethrow();
786 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000787#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 return __os;
789}
790
791template<class _Traits>
792basic_ostream<char, _Traits>&
793operator<<(basic_ostream<char, _Traits>& __os, char __c)
794{
795#ifndef _LIBCPP_NO_EXCEPTIONS
796 try
797 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 typename basic_ostream<char, _Traits>::sentry __s(__os);
800 if (__s)
801 {
Howard Hinnant99968442011-11-29 18:15:50 +0000802 typedef ostreambuf_iterator<char, _Traits> _Ip;
803 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 &__c,
805 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
806 &__c + 1 :
807 &__c,
808 &__c + 1,
809 __os,
810 __os.fill()).failed())
811 __os.setstate(ios_base::badbit | ios_base::failbit);
812 }
813#ifndef _LIBCPP_NO_EXCEPTIONS
814 }
815 catch (...)
816 {
817 __os.__set_badbit_and_consider_rethrow();
818 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000819#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820 return __os;
821}
822
823template<class _Traits>
824basic_ostream<char, _Traits>&
825operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
826{
827#ifndef _LIBCPP_NO_EXCEPTIONS
828 try
829 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000830#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831 typename basic_ostream<char, _Traits>::sentry __s(__os);
832 if (__s)
833 {
Howard Hinnant99968442011-11-29 18:15:50 +0000834 typedef ostreambuf_iterator<char, _Traits> _Ip;
835 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000836 (char*)&__c,
837 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
838 (char*)&__c + 1 :
839 (char*)&__c,
840 (char*)&__c + 1,
841 __os,
842 __os.fill()).failed())
843 __os.setstate(ios_base::badbit | ios_base::failbit);
844 }
845#ifndef _LIBCPP_NO_EXCEPTIONS
846 }
847 catch (...)
848 {
849 __os.__set_badbit_and_consider_rethrow();
850 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000851#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 return __os;
853}
854
855template<class _Traits>
856basic_ostream<char, _Traits>&
857operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
858{
859#ifndef _LIBCPP_NO_EXCEPTIONS
860 try
861 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000862#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 typename basic_ostream<char, _Traits>::sentry __s(__os);
864 if (__s)
865 {
Howard Hinnant99968442011-11-29 18:15:50 +0000866 typedef ostreambuf_iterator<char, _Traits> _Ip;
867 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 (char*)&__c,
869 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
870 (char*)&__c + 1 :
871 (char*)&__c,
872 (char*)&__c + 1,
873 __os,
874 __os.fill()).failed())
875 __os.setstate(ios_base::badbit | ios_base::failbit);
876 }
877#ifndef _LIBCPP_NO_EXCEPTIONS
878 }
879 catch (...)
880 {
881 __os.__set_badbit_and_consider_rethrow();
882 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000883#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 return __os;
885}
886
887template<class _CharT, class _Traits>
888basic_ostream<_CharT, _Traits>&
889operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
890{
891#ifndef _LIBCPP_NO_EXCEPTIONS
892 try
893 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000894#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
896 if (__s)
897 {
Howard Hinnant99968442011-11-29 18:15:50 +0000898 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 size_t __len = _Traits::length(__str);
Howard Hinnant99968442011-11-29 18:15:50 +0000900 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 __str,
902 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
903 __str + __len :
904 __str,
905 __str + __len,
906 __os,
907 __os.fill()).failed())
908 __os.setstate(ios_base::badbit | ios_base::failbit);
909 }
910#ifndef _LIBCPP_NO_EXCEPTIONS
911 }
912 catch (...)
913 {
914 __os.__set_badbit_and_consider_rethrow();
915 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000916#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 return __os;
918}
919
920template<class _CharT, class _Traits>
921basic_ostream<_CharT, _Traits>&
922operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
923{
924#ifndef _LIBCPP_NO_EXCEPTIONS
925 try
926 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000927#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
929 if (__s)
930 {
Howard Hinnant99968442011-11-29 18:15:50 +0000931 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 size_t __len = char_traits<char>::length(__strn);
933 const int __bs = 100;
934 _CharT __wbb[__bs];
935 _CharT* __wb = __wbb;
936 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
937 if (__len > __bs)
938 {
939 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
940 if (__wb == 0)
941 __throw_bad_alloc();
942 __h.reset(__wb);
943 }
944 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
945 *__p = __os.widen(*__strn);
Howard Hinnant99968442011-11-29 18:15:50 +0000946 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 __wb,
948 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
949 __wb + __len :
950 __wb,
951 __wb + __len,
952 __os,
953 __os.fill()).failed())
954 __os.setstate(ios_base::badbit | ios_base::failbit);
955 }
956#ifndef _LIBCPP_NO_EXCEPTIONS
957 }
958 catch (...)
959 {
960 __os.__set_badbit_and_consider_rethrow();
961 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000962#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 return __os;
964}
965
966template<class _Traits>
967basic_ostream<char, _Traits>&
968operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
969{
970#ifndef _LIBCPP_NO_EXCEPTIONS
971 try
972 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000973#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974 typename basic_ostream<char, _Traits>::sentry __s(__os);
975 if (__s)
976 {
Howard Hinnant99968442011-11-29 18:15:50 +0000977 typedef ostreambuf_iterator<char, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 size_t __len = _Traits::length(__str);
Howard Hinnant99968442011-11-29 18:15:50 +0000979 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980 __str,
981 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
982 __str + __len :
983 __str,
984 __str + __len,
985 __os,
986 __os.fill()).failed())
987 __os.setstate(ios_base::badbit | ios_base::failbit);
988 }
989#ifndef _LIBCPP_NO_EXCEPTIONS
990 }
991 catch (...)
992 {
993 __os.__set_badbit_and_consider_rethrow();
994 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000995#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996 return __os;
997}
998
999template<class _Traits>
1000basic_ostream<char, _Traits>&
1001operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
1002{
1003#ifndef _LIBCPP_NO_EXCEPTIONS
1004 try
1005 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001006#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007 typename basic_ostream<char, _Traits>::sentry __s(__os);
1008 if (__s)
1009 {
Howard Hinnant99968442011-11-29 18:15:50 +00001010 typedef ostreambuf_iterator<char, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011 size_t __len = _Traits::length((const char*)__str);
Howard Hinnant99968442011-11-29 18:15:50 +00001012 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013 (const char*)__str,
1014 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1015 (const char*)__str + __len :
1016 (const char*)__str,
1017 (const char*)__str + __len,
1018 __os,
1019 __os.fill()).failed())
1020 __os.setstate(ios_base::badbit | ios_base::failbit);
1021 }
1022#ifndef _LIBCPP_NO_EXCEPTIONS
1023 }
1024 catch (...)
1025 {
1026 __os.__set_badbit_and_consider_rethrow();
1027 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001028#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001029 return __os;
1030}
1031
1032template<class _Traits>
1033basic_ostream<char, _Traits>&
1034operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
1035{
1036#ifndef _LIBCPP_NO_EXCEPTIONS
1037 try
1038 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001039#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040 typename basic_ostream<char, _Traits>::sentry __s(__os);
1041 if (__s)
1042 {
Howard Hinnant99968442011-11-29 18:15:50 +00001043 typedef ostreambuf_iterator<char, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 size_t __len = _Traits::length((const char*)__str);
Howard Hinnant99968442011-11-29 18:15:50 +00001045 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046 (const char*)__str,
1047 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1048 (const char*)__str + __len :
1049 (const char*)__str,
1050 (const char*)__str + __len,
1051 __os,
1052 __os.fill()).failed())
1053 __os.setstate(ios_base::badbit | ios_base::failbit);
1054 }
1055#ifndef _LIBCPP_NO_EXCEPTIONS
1056 }
1057 catch (...)
1058 {
1059 __os.__set_badbit_and_consider_rethrow();
1060 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001061#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062 return __os;
1063}
1064
1065template <class _CharT, class _Traits>
1066basic_ostream<_CharT, _Traits>&
1067basic_ostream<_CharT, _Traits>::put(char_type __c)
1068{
1069#ifndef _LIBCPP_NO_EXCEPTIONS
1070 try
1071 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001072#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 sentry __s(*this);
1074 if (__s)
1075 {
Howard Hinnant99968442011-11-29 18:15:50 +00001076 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
1077 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078 *__o = __c;
1079 if (__o.failed())
1080 this->setstate(ios_base::badbit);
1081 }
1082#ifndef _LIBCPP_NO_EXCEPTIONS
1083 }
1084 catch (...)
1085 {
1086 this->__set_badbit_and_consider_rethrow();
1087 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001088#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 return *this;
1090}
1091
1092template <class _CharT, class _Traits>
1093basic_ostream<_CharT, _Traits>&
1094basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
1095{
1096#ifndef _LIBCPP_NO_EXCEPTIONS
1097 try
1098 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001099#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 sentry __sen(*this);
1101 if (__sen && __n)
1102 {
Howard Hinnant99968442011-11-29 18:15:50 +00001103 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
1104 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 for (; __n; --__n, ++__o, ++__s)
1106 {
1107 *__o = *__s;
1108 if (__o.failed())
1109 {
1110 this->setstate(ios_base::badbit);
1111 break;
1112 }
1113 }
1114 }
1115#ifndef _LIBCPP_NO_EXCEPTIONS
1116 }
1117 catch (...)
1118 {
1119 this->__set_badbit_and_consider_rethrow();
1120 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001121#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122 return *this;
1123}
1124
1125template <class _CharT, class _Traits>
1126basic_ostream<_CharT, _Traits>&
1127basic_ostream<_CharT, _Traits>::flush()
1128{
1129#ifndef _LIBCPP_NO_EXCEPTIONS
1130 try
1131 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001132#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 if (this->rdbuf())
1134 {
1135 sentry __s(*this);
1136 if (__s)
1137 {
1138 if (this->rdbuf()->pubsync() == -1)
1139 this->setstate(ios_base::badbit);
1140 }
1141 }
1142#ifndef _LIBCPP_NO_EXCEPTIONS
1143 }
1144 catch (...)
1145 {
1146 this->__set_badbit_and_consider_rethrow();
1147 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001148#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 return *this;
1150}
1151
1152template <class _CharT, class _Traits>
1153inline _LIBCPP_INLINE_VISIBILITY
1154typename basic_ostream<_CharT, _Traits>::pos_type
1155basic_ostream<_CharT, _Traits>::tellp()
1156{
1157 if (this->fail())
1158 return pos_type(-1);
1159 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1160}
1161
1162template <class _CharT, class _Traits>
1163inline _LIBCPP_INLINE_VISIBILITY
1164basic_ostream<_CharT, _Traits>&
1165basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1166{
1167 if (!this->fail())
1168 {
1169 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1170 this->setstate(ios_base::failbit);
1171 }
1172 return *this;
1173}
1174
1175template <class _CharT, class _Traits>
1176inline _LIBCPP_INLINE_VISIBILITY
1177basic_ostream<_CharT, _Traits>&
1178basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1179{
1180 if (!this->fail())
1181 this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
1182 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 Hinnant73d21a42010-09-04 23:28:19 +00001213#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-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 Hinnante1a7b042012-01-12 23:37:51 +00001221 _Stream&&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222>::type
1223operator<<(_Stream&& __os, const _Tp& __x)
1224{
1225 __os << __x;
Howard Hinnante1a7b042012-01-12 23:37:51 +00001226 return _VSTD::move(__os);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227}
1228
Howard Hinnant73d21a42010-09-04 23:28:19 +00001229#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-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 Hinnant324bb032010-08-22 00:02:43 +00001239#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
1241 if (__s)
1242 {
Howard Hinnant99968442011-11-29 18:15:50 +00001243 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001244 size_t __len = __str.size();
Howard Hinnant99968442011-11-29 18:15:50 +00001245 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-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 Hinnant324bb032010-08-22 00:02:43 +00001261#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-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 Hinnant99968442011-11-29 18:15:50 +00001273template<class _CharT, class _Traits, class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274inline _LIBCPP_INLINE_VISIBILITY
1275basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00001276operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantbc8d3f92010-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 Hinnanta02851e2011-04-05 14:55:28 +00001283operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantbc8d3f92010-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
1290extern template class basic_ostream<char>;
1291extern template class basic_ostream<wchar_t>;
1292
1293_LIBCPP_END_NAMESPACE_STD
1294
1295#endif // _LIBCPP_OSTREAM