blob: 36f08617e64ba478785608cdb1ce6c56b16a38ec [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);
Marshall Clow27d29872014-09-16 15:27:01 +000070protected:
71 basic_ostream(const basic_ostream& rhs) = delete;
72 basic_ostream(basic_ostream&& rhs);
73 // 27.7.3.3 Assign/swap
74 basic_ostream& operator=(basic_ostream& rhs) = delete;
75 basic_ostream& operator=(const basic_ostream&& rhs);
76 void swap(basic_ostream& rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +000077};
78
79// 27.7.2.6.4 character inserters
80
81template<class charT, class traits>
82 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
83
84template<class charT, class traits>
85 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
86
87template<class traits>
88 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
89
90// signed and unsigned
91
92template<class traits>
93 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
94
95template<class traits>
96 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
97
98// NTBS
99template<class charT, class traits>
100 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
101
102template<class charT, class traits>
103 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
104
105template<class traits>
106 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
107
108// signed and unsigned
109template<class traits>
110basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
111
112template<class traits>
113 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
114
115// swap:
116template <class charT, class traits>
117 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
118
119template <class charT, class traits>
120 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
121
122template <class charT, class traits>
123 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
124
125template <class charT, class traits>
126 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
127
128// rvalue stream insertion
129template <class charT, class traits, class T>
130 basic_ostream<charT, traits>&
131 operator<<(basic_ostream<charT, traits>&& os, const T& x);
132
133} // std
134
135*/
136
137#include <__config>
138#include <ios>
139#include <streambuf>
140#include <locale>
141#include <iterator>
142#include <bitset>
143
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000144#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000146#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
148_LIBCPP_BEGIN_NAMESPACE_STD
149
150template <class _CharT, class _Traits>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000151class _LIBCPP_TYPE_VIS_ONLY basic_ostream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152 : virtual public basic_ios<_CharT, _Traits>
153{
154public:
155 // types (inherited from basic_ios (27.5.4)):
156 typedef _CharT char_type;
157 typedef _Traits traits_type;
158 typedef typename traits_type::int_type int_type;
159 typedef typename traits_type::pos_type pos_type;
160 typedef typename traits_type::off_type off_type;
161
162 // 27.7.2.2 Constructor/destructor:
163 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
164 virtual ~basic_ostream();
165protected:
Howard Hinnant74279a52010-09-04 23:28:19 +0000166#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0dcdf022011-07-07 21:03:52 +0000167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168 basic_ostream(basic_ostream&& __rhs);
169#endif
170
171 // 27.7.2.3 Assign/swap
Marshall Clowe9ca0272013-08-14 15:15:28 +0000172#if _LIBCPP_STD_VER > 11
173 basic_ostream& operator=(const basic_ostream&) = delete;
174#endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000175#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0dcdf022011-07-07 21:03:52 +0000176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 basic_ostream& operator=(basic_ostream&& __rhs);
178#endif
179 void swap(basic_ostream& __rhs);
Marshall Clow27d29872014-09-16 15:27:01 +0000180
181#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
182 basic_ostream (basic_ostream& __rhs) = delete;
183 basic_ostream& operator=(basic_ostream& __rhs) = delete;
184#else
185private:
186 basic_ostream (basic_ostream& __rhs);
187 basic_ostream& operator=(basic_ostream& __rhs);
188#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189public:
190
191 // 27.7.2.4 Prefix/suffix:
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000192 class _LIBCPP_TYPE_VIS_ONLY sentry;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000193
194 // 27.7.2.6 Formatted output:
195 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
196 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
197 (*__pf)(basic_ios<char_type,traits_type>&));
198 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
199 basic_ostream& operator<<(bool __n);
200 basic_ostream& operator<<(short __n);
201 basic_ostream& operator<<(unsigned short __n);
202 basic_ostream& operator<<(int __n);
203 basic_ostream& operator<<(unsigned int __n);
204 basic_ostream& operator<<(long __n);
205 basic_ostream& operator<<(unsigned long __n);
206 basic_ostream& operator<<(long long __n);
207 basic_ostream& operator<<(unsigned long long __n);
208 basic_ostream& operator<<(float __f);
209 basic_ostream& operator<<(double __f);
210 basic_ostream& operator<<(long double __f);
211 basic_ostream& operator<<(const void* __p);
212 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
213
214 // 27.7.2.7 Unformatted output:
215 basic_ostream& put(char_type __c);
216 basic_ostream& write(const char_type* __s, streamsize __n);
217 basic_ostream& flush();
218
219 // 27.7.2.5 seeks:
220 pos_type tellp();
221 basic_ostream& seekp(pos_type __pos);
222 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
223
224protected:
225 _LIBCPP_ALWAYS_INLINE
226 basic_ostream() {} // extension, intentially does not initialize
227};
228
229template <class _CharT, class _Traits>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000230class _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231{
232 bool __ok_;
233 basic_ostream<_CharT, _Traits>& __os_;
234
235 sentry(const sentry&); // = delete;
236 sentry& operator=(const sentry&); // = delete;
237
238public:
239 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
240 ~sentry();
241
242 _LIBCPP_ALWAYS_INLINE
Howard Hinnant86a291f2012-02-21 21:46:43 +0000243 _LIBCPP_EXPLICIT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 operator bool() const {return __ok_;}
245};
246
247template <class _CharT, class _Traits>
248basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
249 : __ok_(false),
250 __os_(__os)
251{
252 if (__os.good())
253 {
254 if (__os.tie())
255 __os.tie()->flush();
256 __ok_ = true;
257 }
258}
259
260template <class _CharT, class _Traits>
261basic_ostream<_CharT, _Traits>::sentry::~sentry()
262{
263 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
264 && !uncaught_exception())
265 {
266#ifndef _LIBCPP_NO_EXCEPTIONS
267 try
268 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000269#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 if (__os_.rdbuf()->pubsync() == -1)
271 __os_.setstate(ios_base::badbit);
272#ifndef _LIBCPP_NO_EXCEPTIONS
273 }
274 catch (...)
275 {
276 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000277#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278 }
279}
280
281template <class _CharT, class _Traits>
282inline _LIBCPP_INLINE_VISIBILITY
283basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
284{
285 this->init(__sb);
286}
287
Howard Hinnant74279a52010-09-04 23:28:19 +0000288#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290template <class _CharT, class _Traits>
291inline _LIBCPP_INLINE_VISIBILITY
292basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
293{
294 this->move(__rhs);
295}
296
297template <class _CharT, class _Traits>
298inline _LIBCPP_INLINE_VISIBILITY
299basic_ostream<_CharT, _Traits>&
300basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
301{
302 swap(__rhs);
303 return *this;
304}
305
Howard Hinnant74279a52010-09-04 23:28:19 +0000306#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307
308template <class _CharT, class _Traits>
309basic_ostream<_CharT, _Traits>::~basic_ostream()
310{
311}
312
313template <class _CharT, class _Traits>
314inline _LIBCPP_INLINE_VISIBILITY
315void
316basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
317{
318 basic_ios<char_type, traits_type>::swap(__rhs);
319}
320
321template <class _CharT, class _Traits>
322inline _LIBCPP_INLINE_VISIBILITY
323basic_ostream<_CharT, _Traits>&
324basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
325{
326 return __pf(*this);
327}
328
329template <class _CharT, class _Traits>
330inline _LIBCPP_INLINE_VISIBILITY
331basic_ostream<_CharT, _Traits>&
332basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
333 (*__pf)(basic_ios<char_type,traits_type>&))
334{
335 __pf(*this);
336 return *this;
337}
338
339template <class _CharT, class _Traits>
340inline _LIBCPP_INLINE_VISIBILITY
341basic_ostream<_CharT, _Traits>&
342basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
343{
344 __pf(*this);
345 return *this;
346}
347
348template <class _CharT, class _Traits>
349basic_ostream<_CharT, _Traits>&
350basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
351{
352#ifndef _LIBCPP_NO_EXCEPTIONS
353 try
354 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000355#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 sentry __s(*this);
357 if (__s)
358 {
359 if (__sb)
360 {
361#ifndef _LIBCPP_NO_EXCEPTIONS
362 try
363 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000364#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc834c512011-11-29 18:15:50 +0000365 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
366 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
367 _Ip __i(__sb);
368 _Ip __eof;
369 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 size_t __c = 0;
371 for (; __i != __eof; ++__i, ++__o, ++__c)
372 {
373 *__o = *__i;
374 if (__o.failed())
375 break;
376 }
377 if (__c == 0)
378 this->setstate(ios_base::failbit);
379#ifndef _LIBCPP_NO_EXCEPTIONS
380 }
381 catch (...)
382 {
383 this->__set_failbit_and_consider_rethrow();
384 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000385#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 }
387 else
388 this->setstate(ios_base::badbit);
389 }
390#ifndef _LIBCPP_NO_EXCEPTIONS
391 }
392 catch (...)
393 {
394 this->__set_badbit_and_consider_rethrow();
395 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000396#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 return *this;
398}
399
400template <class _CharT, class _Traits>
401basic_ostream<_CharT, _Traits>&
402basic_ostream<_CharT, _Traits>::operator<<(bool __n)
403{
404#ifndef _LIBCPP_NO_EXCEPTIONS
405 try
406 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000407#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 sentry __s(*this);
409 if (__s)
410 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000411 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
412 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 if (__f.put(*this, *this, this->fill(), __n).failed())
414 this->setstate(ios_base::badbit | ios_base::failbit);
415 }
416#ifndef _LIBCPP_NO_EXCEPTIONS
417 }
418 catch (...)
419 {
420 this->__set_badbit_and_consider_rethrow();
421 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000422#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 return *this;
424}
425
426template <class _CharT, class _Traits>
427basic_ostream<_CharT, _Traits>&
428basic_ostream<_CharT, _Traits>::operator<<(short __n)
429{
430#ifndef _LIBCPP_NO_EXCEPTIONS
431 try
432 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000433#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 sentry __s(*this);
435 if (__s)
436 {
437 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000438 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
439 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440 if (__f.put(*this, *this, this->fill(),
441 __flags == ios_base::oct || __flags == ios_base::hex ?
442 static_cast<long>(static_cast<unsigned short>(__n)) :
443 static_cast<long>(__n)).failed())
444 this->setstate(ios_base::badbit | ios_base::failbit);
445 }
446#ifndef _LIBCPP_NO_EXCEPTIONS
447 }
448 catch (...)
449 {
450 this->__set_badbit_and_consider_rethrow();
451 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000452#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453 return *this;
454}
455
456template <class _CharT, class _Traits>
457basic_ostream<_CharT, _Traits>&
458basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
459{
460#ifndef _LIBCPP_NO_EXCEPTIONS
461 try
462 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000463#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 sentry __s(*this);
465 if (__s)
466 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000467 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
468 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
470 this->setstate(ios_base::badbit | ios_base::failbit);
471 }
472#ifndef _LIBCPP_NO_EXCEPTIONS
473 }
474 catch (...)
475 {
476 this->__set_badbit_and_consider_rethrow();
477 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000478#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479 return *this;
480}
481
482template <class _CharT, class _Traits>
483basic_ostream<_CharT, _Traits>&
484basic_ostream<_CharT, _Traits>::operator<<(int __n)
485{
486#ifndef _LIBCPP_NO_EXCEPTIONS
487 try
488 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000489#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 sentry __s(*this);
491 if (__s)
492 {
493 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000494 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
495 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 if (__f.put(*this, *this, this->fill(),
497 __flags == ios_base::oct || __flags == ios_base::hex ?
498 static_cast<long>(static_cast<unsigned int>(__n)) :
499 static_cast<long>(__n)).failed())
500 this->setstate(ios_base::badbit | ios_base::failbit);
501 }
502#ifndef _LIBCPP_NO_EXCEPTIONS
503 }
504 catch (...)
505 {
506 this->__set_badbit_and_consider_rethrow();
507 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000508#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 return *this;
510}
511
512template <class _CharT, class _Traits>
513basic_ostream<_CharT, _Traits>&
514basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
515{
516#ifndef _LIBCPP_NO_EXCEPTIONS
517 try
518 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000519#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 sentry __s(*this);
521 if (__s)
522 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000523 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
524 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
526 this->setstate(ios_base::badbit | ios_base::failbit);
527 }
528#ifndef _LIBCPP_NO_EXCEPTIONS
529 }
530 catch (...)
531 {
532 this->__set_badbit_and_consider_rethrow();
533 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000534#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535 return *this;
536}
537
538template <class _CharT, class _Traits>
539basic_ostream<_CharT, _Traits>&
540basic_ostream<_CharT, _Traits>::operator<<(long __n)
541{
542#ifndef _LIBCPP_NO_EXCEPTIONS
543 try
544 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000545#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 sentry __s(*this);
547 if (__s)
548 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000549 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
550 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551 if (__f.put(*this, *this, this->fill(), __n).failed())
552 this->setstate(ios_base::badbit | ios_base::failbit);
553 }
554#ifndef _LIBCPP_NO_EXCEPTIONS
555 }
556 catch (...)
557 {
558 this->__set_badbit_and_consider_rethrow();
559 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000560#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561 return *this;
562}
563
564template <class _CharT, class _Traits>
565basic_ostream<_CharT, _Traits>&
566basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
567{
568#ifndef _LIBCPP_NO_EXCEPTIONS
569 try
570 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000571#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572 sentry __s(*this);
573 if (__s)
574 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000575 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
576 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 if (__f.put(*this, *this, this->fill(), __n).failed())
578 this->setstate(ios_base::badbit | ios_base::failbit);
579 }
580#ifndef _LIBCPP_NO_EXCEPTIONS
581 }
582 catch (...)
583 {
584 this->__set_badbit_and_consider_rethrow();
585 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000586#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587 return *this;
588}
589
590template <class _CharT, class _Traits>
591basic_ostream<_CharT, _Traits>&
592basic_ostream<_CharT, _Traits>::operator<<(long long __n)
593{
594#ifndef _LIBCPP_NO_EXCEPTIONS
595 try
596 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000597#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 sentry __s(*this);
599 if (__s)
600 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000601 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
602 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 if (__f.put(*this, *this, this->fill(), __n).failed())
604 this->setstate(ios_base::badbit | ios_base::failbit);
605 }
606#ifndef _LIBCPP_NO_EXCEPTIONS
607 }
608 catch (...)
609 {
610 this->__set_badbit_and_consider_rethrow();
611 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000612#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 return *this;
614}
615
616template <class _CharT, class _Traits>
617basic_ostream<_CharT, _Traits>&
618basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
619{
620#ifndef _LIBCPP_NO_EXCEPTIONS
621 try
622 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000623#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624 sentry __s(*this);
625 if (__s)
626 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000627 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
628 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629 if (__f.put(*this, *this, this->fill(), __n).failed())
630 this->setstate(ios_base::badbit | ios_base::failbit);
631 }
632#ifndef _LIBCPP_NO_EXCEPTIONS
633 }
634 catch (...)
635 {
636 this->__set_badbit_and_consider_rethrow();
637 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000638#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639 return *this;
640}
641
642template <class _CharT, class _Traits>
643basic_ostream<_CharT, _Traits>&
644basic_ostream<_CharT, _Traits>::operator<<(float __n)
645{
646#ifndef _LIBCPP_NO_EXCEPTIONS
647 try
648 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000649#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 sentry __s(*this);
651 if (__s)
652 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000653 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
654 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
656 this->setstate(ios_base::badbit | ios_base::failbit);
657 }
658#ifndef _LIBCPP_NO_EXCEPTIONS
659 }
660 catch (...)
661 {
662 this->__set_badbit_and_consider_rethrow();
663 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000664#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665 return *this;
666}
667
668template <class _CharT, class _Traits>
669basic_ostream<_CharT, _Traits>&
670basic_ostream<_CharT, _Traits>::operator<<(double __n)
671{
672#ifndef _LIBCPP_NO_EXCEPTIONS
673 try
674 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000675#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676 sentry __s(*this);
677 if (__s)
678 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000679 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
680 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681 if (__f.put(*this, *this, this->fill(), __n).failed())
682 this->setstate(ios_base::badbit | ios_base::failbit);
683 }
684#ifndef _LIBCPP_NO_EXCEPTIONS
685 }
686 catch (...)
687 {
688 this->__set_badbit_and_consider_rethrow();
689 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000690#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691 return *this;
692}
693
694template <class _CharT, class _Traits>
695basic_ostream<_CharT, _Traits>&
696basic_ostream<_CharT, _Traits>::operator<<(long double __n)
697{
698#ifndef _LIBCPP_NO_EXCEPTIONS
699 try
700 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000701#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 sentry __s(*this);
703 if (__s)
704 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000705 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
706 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707 if (__f.put(*this, *this, this->fill(), __n).failed())
708 this->setstate(ios_base::badbit | ios_base::failbit);
709 }
710#ifndef _LIBCPP_NO_EXCEPTIONS
711 }
712 catch (...)
713 {
714 this->__set_badbit_and_consider_rethrow();
715 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000716#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717 return *this;
718}
719
720template <class _CharT, class _Traits>
721basic_ostream<_CharT, _Traits>&
722basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
723{
724#ifndef _LIBCPP_NO_EXCEPTIONS
725 try
726 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000727#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728 sentry __s(*this);
729 if (__s)
730 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000731 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
732 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 if (__f.put(*this, *this, this->fill(), __n).failed())
734 this->setstate(ios_base::badbit | ios_base::failbit);
735 }
736#ifndef _LIBCPP_NO_EXCEPTIONS
737 }
738 catch (...)
739 {
740 this->__set_badbit_and_consider_rethrow();
741 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000742#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743 return *this;
744}
745
746template<class _CharT, class _Traits>
747basic_ostream<_CharT, _Traits>&
Marshall Clow00995642013-12-10 19:25:49 +0000748__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
749 const _CharT* __str, size_t __len)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750{
751#ifndef _LIBCPP_NO_EXCEPTIONS
752 try
753 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000754#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
756 if (__s)
757 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000758 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
759 if (__pad_and_output(_Ip(__os),
Marshall Clow00995642013-12-10 19:25:49 +0000760 __str,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow00995642013-12-10 19:25:49 +0000762 __str + __len :
763 __str,
764 __str + __len,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 __os,
766 __os.fill()).failed())
767 __os.setstate(ios_base::badbit | ios_base::failbit);
768 }
769#ifndef _LIBCPP_NO_EXCEPTIONS
770 }
771 catch (...)
772 {
773 __os.__set_badbit_and_consider_rethrow();
774 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000775#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 return __os;
777}
778
Marshall Clow00995642013-12-10 19:25:49 +0000779
780template<class _CharT, class _Traits>
781basic_ostream<_CharT, _Traits>&
782operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
783{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000784 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow00995642013-12-10 19:25:49 +0000785}
786
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787template<class _CharT, class _Traits>
788basic_ostream<_CharT, _Traits>&
789operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
790{
791#ifndef _LIBCPP_NO_EXCEPTIONS
792 try
793 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000794#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
796 if (__s)
797 {
798 _CharT __c = __os.widen(__cn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000799 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
800 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 &__c,
802 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
803 &__c + 1 :
804 &__c,
805 &__c + 1,
806 __os,
807 __os.fill()).failed())
808 __os.setstate(ios_base::badbit | ios_base::failbit);
809 }
810#ifndef _LIBCPP_NO_EXCEPTIONS
811 }
812 catch (...)
813 {
814 __os.__set_badbit_and_consider_rethrow();
815 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000816#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817 return __os;
818}
819
820template<class _Traits>
821basic_ostream<char, _Traits>&
822operator<<(basic_ostream<char, _Traits>& __os, char __c)
823{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000824 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825}
826
827template<class _Traits>
828basic_ostream<char, _Traits>&
829operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
830{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000831 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832}
833
834template<class _Traits>
835basic_ostream<char, _Traits>&
836operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
837{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000838 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839}
840
841template<class _CharT, class _Traits>
842basic_ostream<_CharT, _Traits>&
843operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
844{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000845 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846}
847
848template<class _CharT, class _Traits>
849basic_ostream<_CharT, _Traits>&
850operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
851{
852#ifndef _LIBCPP_NO_EXCEPTIONS
853 try
854 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000855#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
857 if (__s)
858 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000859 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 size_t __len = char_traits<char>::length(__strn);
861 const int __bs = 100;
862 _CharT __wbb[__bs];
863 _CharT* __wb = __wbb;
864 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
865 if (__len > __bs)
866 {
867 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
868 if (__wb == 0)
869 __throw_bad_alloc();
870 __h.reset(__wb);
871 }
872 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
873 *__p = __os.widen(*__strn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000874 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 __wb,
876 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
877 __wb + __len :
878 __wb,
879 __wb + __len,
880 __os,
881 __os.fill()).failed())
882 __os.setstate(ios_base::badbit | ios_base::failbit);
883 }
884#ifndef _LIBCPP_NO_EXCEPTIONS
885 }
886 catch (...)
887 {
888 __os.__set_badbit_and_consider_rethrow();
889 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000890#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 return __os;
892}
893
894template<class _Traits>
895basic_ostream<char, _Traits>&
896operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
897{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000898 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899}
900
901template<class _Traits>
902basic_ostream<char, _Traits>&
903operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
904{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000905 const char *__s = (const char *) __str;
906 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907}
908
909template<class _Traits>
910basic_ostream<char, _Traits>&
911operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
912{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000913 const char *__s = (const char *) __str;
914 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915}
916
917template <class _CharT, class _Traits>
918basic_ostream<_CharT, _Traits>&
919basic_ostream<_CharT, _Traits>::put(char_type __c)
920{
921#ifndef _LIBCPP_NO_EXCEPTIONS
922 try
923 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000924#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 sentry __s(*this);
926 if (__s)
927 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000928 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
929 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930 *__o = __c;
931 if (__o.failed())
932 this->setstate(ios_base::badbit);
933 }
934#ifndef _LIBCPP_NO_EXCEPTIONS
935 }
936 catch (...)
937 {
938 this->__set_badbit_and_consider_rethrow();
939 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000940#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941 return *this;
942}
943
944template <class _CharT, class _Traits>
945basic_ostream<_CharT, _Traits>&
946basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
947{
948#ifndef _LIBCPP_NO_EXCEPTIONS
949 try
950 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000951#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 sentry __sen(*this);
953 if (__sen && __n)
954 {
Howard Hinnant79cef932013-01-15 17:22:03 +0000955 if (this->rdbuf()->sputn(__s, __n) != __n)
956 this->setstate(ios_base::badbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000957 }
958#ifndef _LIBCPP_NO_EXCEPTIONS
959 }
960 catch (...)
961 {
962 this->__set_badbit_and_consider_rethrow();
963 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000964#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965 return *this;
966}
967
968template <class _CharT, class _Traits>
969basic_ostream<_CharT, _Traits>&
970basic_ostream<_CharT, _Traits>::flush()
971{
972#ifndef _LIBCPP_NO_EXCEPTIONS
973 try
974 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000975#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976 if (this->rdbuf())
977 {
978 sentry __s(*this);
979 if (__s)
980 {
981 if (this->rdbuf()->pubsync() == -1)
982 this->setstate(ios_base::badbit);
983 }
984 }
985#ifndef _LIBCPP_NO_EXCEPTIONS
986 }
987 catch (...)
988 {
989 this->__set_badbit_and_consider_rethrow();
990 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000991#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 return *this;
993}
994
995template <class _CharT, class _Traits>
996inline _LIBCPP_INLINE_VISIBILITY
997typename basic_ostream<_CharT, _Traits>::pos_type
998basic_ostream<_CharT, _Traits>::tellp()
999{
1000 if (this->fail())
1001 return pos_type(-1);
1002 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1003}
1004
1005template <class _CharT, class _Traits>
1006inline _LIBCPP_INLINE_VISIBILITY
1007basic_ostream<_CharT, _Traits>&
1008basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1009{
Marshall Clow29c4daa2013-10-31 22:20:45 +00001010 sentry __s(*this);
1011 if (__s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012 {
1013 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1014 this->setstate(ios_base::failbit);
1015 }
1016 return *this;
1017}
1018
1019template <class _CharT, class _Traits>
1020inline _LIBCPP_INLINE_VISIBILITY
1021basic_ostream<_CharT, _Traits>&
1022basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1023{
Marshall Clow29c4daa2013-10-31 22:20:45 +00001024 sentry __s(*this);
1025 if (__s)
1026 {
1027 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
1028 this->setstate(ios_base::failbit);
1029 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 return *this;
1031}
1032
1033template <class _CharT, class _Traits>
1034inline _LIBCPP_INLINE_VISIBILITY
1035basic_ostream<_CharT, _Traits>&
1036endl(basic_ostream<_CharT, _Traits>& __os)
1037{
1038 __os.put(__os.widen('\n'));
1039 __os.flush();
1040 return __os;
1041}
1042
1043template <class _CharT, class _Traits>
1044inline _LIBCPP_INLINE_VISIBILITY
1045basic_ostream<_CharT, _Traits>&
1046ends(basic_ostream<_CharT, _Traits>& __os)
1047{
1048 __os.put(_CharT());
1049 return __os;
1050}
1051
1052template <class _CharT, class _Traits>
1053inline _LIBCPP_INLINE_VISIBILITY
1054basic_ostream<_CharT, _Traits>&
1055flush(basic_ostream<_CharT, _Traits>& __os)
1056{
1057 __os.flush();
1058 return __os;
1059}
1060
Howard Hinnant74279a52010-09-04 23:28:19 +00001061#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062
1063template <class _Stream, class _Tp>
1064inline _LIBCPP_INLINE_VISIBILITY
1065typename enable_if
1066<
1067 !is_lvalue_reference<_Stream>::value &&
1068 is_base_of<ios_base, _Stream>::value,
Howard Hinnantc8697b62012-01-12 23:37:51 +00001069 _Stream&&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070>::type
1071operator<<(_Stream&& __os, const _Tp& __x)
1072{
1073 __os << __x;
Howard Hinnantc8697b62012-01-12 23:37:51 +00001074 return _VSTD::move(__os);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075}
1076
Howard Hinnant74279a52010-09-04 23:28:19 +00001077#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078
1079template<class _CharT, class _Traits, class _Allocator>
1080basic_ostream<_CharT, _Traits>&
1081operator<<(basic_ostream<_CharT, _Traits>& __os,
1082 const basic_string<_CharT, _Traits, _Allocator>& __str)
1083{
Marshall Clow4bc2be22014-02-16 01:57:26 +00001084 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085}
1086
1087template <class _CharT, class _Traits>
1088inline _LIBCPP_INLINE_VISIBILITY
1089basic_ostream<_CharT, _Traits>&
1090operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1091{
1092 return __os << __ec.category().name() << ':' << __ec.value();
1093}
1094
Howard Hinnantc834c512011-11-29 18:15:50 +00001095template<class _CharT, class _Traits, class _Yp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096inline _LIBCPP_INLINE_VISIBILITY
1097basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001098operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099{
1100 return __os << __p.get();
1101}
1102
1103template <class _CharT, class _Traits, size_t _Size>
1104basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001105operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106{
1107 return __os << __x.template to_string<_CharT, _Traits>
1108 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1109 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1110}
1111
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001112_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>)
1113_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114
1115_LIBCPP_END_NAMESPACE_STD
1116
1117#endif // _LIBCPP_OSTREAM