blob: be35f2e16e70e02d643d3e89f69f04f38da10c49 [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>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000151class _LIBCPP_TEMPLATE_VIS 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:
Eric Fiselier815ed732016-09-16 00:00:48 +0000163 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
164 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
165 { this->init(__sb); }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 virtual ~basic_ostream();
167protected:
Howard Hinnant74279a52010-09-04 23:28:19 +0000168#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselier815ed732016-09-16 00:00:48 +0000169 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170 basic_ostream(basic_ostream&& __rhs);
171#endif
172
173 // 27.7.2.3 Assign/swap
Howard Hinnant74279a52010-09-04 23:28:19 +0000174#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Eric Fiselier815ed732016-09-16 00:00:48 +0000175 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176 basic_ostream& operator=(basic_ostream&& __rhs);
177#endif
Eric Fiselier815ed732016-09-16 00:00:48 +0000178 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
179 void swap(basic_ostream& __rhs)
180 { basic_ios<char_type, traits_type>::swap(__rhs); }
Marshall Clow27d29872014-09-16 15:27:01 +0000181
182#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
Marshall Clow242d9c12014-09-16 15:33:53 +0000183 basic_ostream (const basic_ostream& __rhs) = delete;
184 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
Marshall Clow27d29872014-09-16 15:27:01 +0000185#else
Marshall Clowd37f25c2014-09-17 01:58:15 +0000186 basic_ostream (const basic_ostream& __rhs); // not defined
187 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
Marshall Clow27d29872014-09-16 15:27:01 +0000188#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189public:
190
191 // 27.7.2.4 Prefix/suffix:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000192 class _LIBCPP_TEMPLATE_VIS sentry;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000193
194 // 27.7.2.6 Formatted output:
Eric Fiselier815ed732016-09-16 00:00:48 +0000195 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
196 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
197 { return __pf(*this); }
198
199 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
Eric Fiselier815ed732016-09-16 00:00:48 +0000201 (*__pf)(basic_ios<char_type,traits_type>&))
202 { __pf(*this); return *this; }
203
204 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
205 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
206 { __pf(*this); return *this; }
207
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 basic_ostream& operator<<(bool __n);
209 basic_ostream& operator<<(short __n);
210 basic_ostream& operator<<(unsigned short __n);
211 basic_ostream& operator<<(int __n);
212 basic_ostream& operator<<(unsigned int __n);
213 basic_ostream& operator<<(long __n);
214 basic_ostream& operator<<(unsigned long __n);
215 basic_ostream& operator<<(long long __n);
216 basic_ostream& operator<<(unsigned long long __n);
217 basic_ostream& operator<<(float __f);
218 basic_ostream& operator<<(double __f);
219 basic_ostream& operator<<(long double __f);
220 basic_ostream& operator<<(const void* __p);
221 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
222
223 // 27.7.2.7 Unformatted output:
224 basic_ostream& put(char_type __c);
225 basic_ostream& write(const char_type* __s, streamsize __n);
226 basic_ostream& flush();
227
228 // 27.7.2.5 seeks:
Eric Fiselier815ed732016-09-16 00:00:48 +0000229 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230 pos_type tellp();
Eric Fiselier815ed732016-09-16 00:00:48 +0000231 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232 basic_ostream& seekp(pos_type __pos);
Eric Fiselier815ed732016-09-16 00:00:48 +0000233 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
235
236protected:
237 _LIBCPP_ALWAYS_INLINE
238 basic_ostream() {} // extension, intentially does not initialize
239};
240
241template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000242class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243{
244 bool __ok_;
245 basic_ostream<_CharT, _Traits>& __os_;
246
247 sentry(const sentry&); // = delete;
248 sentry& operator=(const sentry&); // = delete;
249
250public:
251 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
252 ~sentry();
253
254 _LIBCPP_ALWAYS_INLINE
Howard Hinnant86a291f2012-02-21 21:46:43 +0000255 _LIBCPP_EXPLICIT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 operator bool() const {return __ok_;}
257};
258
259template <class _CharT, class _Traits>
260basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
261 : __ok_(false),
262 __os_(__os)
263{
264 if (__os.good())
265 {
266 if (__os.tie())
267 __os.tie()->flush();
268 __ok_ = true;
269 }
270}
271
272template <class _CharT, class _Traits>
273basic_ostream<_CharT, _Traits>::sentry::~sentry()
274{
275 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
276 && !uncaught_exception())
277 {
278#ifndef _LIBCPP_NO_EXCEPTIONS
279 try
280 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000281#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 if (__os_.rdbuf()->pubsync() == -1)
283 __os_.setstate(ios_base::badbit);
284#ifndef _LIBCPP_NO_EXCEPTIONS
285 }
286 catch (...)
287 {
288 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000289#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290 }
291}
292
Howard Hinnant74279a52010-09-04 23:28:19 +0000293#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294
295template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
297{
298 this->move(__rhs);
299}
300
301template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302basic_ostream<_CharT, _Traits>&
303basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
304{
305 swap(__rhs);
306 return *this;
307}
308
Howard Hinnant74279a52010-09-04 23:28:19 +0000309#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310
311template <class _CharT, class _Traits>
312basic_ostream<_CharT, _Traits>::~basic_ostream()
313{
314}
315
316template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317basic_ostream<_CharT, _Traits>&
318basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
319{
320#ifndef _LIBCPP_NO_EXCEPTIONS
321 try
322 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000323#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 sentry __s(*this);
325 if (__s)
326 {
327 if (__sb)
328 {
329#ifndef _LIBCPP_NO_EXCEPTIONS
330 try
331 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000332#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc834c512011-11-29 18:15:50 +0000333 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
334 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
335 _Ip __i(__sb);
336 _Ip __eof;
337 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 size_t __c = 0;
339 for (; __i != __eof; ++__i, ++__o, ++__c)
340 {
341 *__o = *__i;
342 if (__o.failed())
343 break;
344 }
345 if (__c == 0)
346 this->setstate(ios_base::failbit);
347#ifndef _LIBCPP_NO_EXCEPTIONS
348 }
349 catch (...)
350 {
351 this->__set_failbit_and_consider_rethrow();
352 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000353#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 }
355 else
356 this->setstate(ios_base::badbit);
357 }
358#ifndef _LIBCPP_NO_EXCEPTIONS
359 }
360 catch (...)
361 {
362 this->__set_badbit_and_consider_rethrow();
363 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000364#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365 return *this;
366}
367
368template <class _CharT, class _Traits>
369basic_ostream<_CharT, _Traits>&
370basic_ostream<_CharT, _Traits>::operator<<(bool __n)
371{
372#ifndef _LIBCPP_NO_EXCEPTIONS
373 try
374 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000375#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 sentry __s(*this);
377 if (__s)
378 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000379 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
380 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381 if (__f.put(*this, *this, this->fill(), __n).failed())
382 this->setstate(ios_base::badbit | ios_base::failbit);
383 }
384#ifndef _LIBCPP_NO_EXCEPTIONS
385 }
386 catch (...)
387 {
388 this->__set_badbit_and_consider_rethrow();
389 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000390#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391 return *this;
392}
393
394template <class _CharT, class _Traits>
395basic_ostream<_CharT, _Traits>&
396basic_ostream<_CharT, _Traits>::operator<<(short __n)
397{
398#ifndef _LIBCPP_NO_EXCEPTIONS
399 try
400 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000401#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 sentry __s(*this);
403 if (__s)
404 {
405 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000406 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
407 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 if (__f.put(*this, *this, this->fill(),
409 __flags == ios_base::oct || __flags == ios_base::hex ?
410 static_cast<long>(static_cast<unsigned short>(__n)) :
411 static_cast<long>(__n)).failed())
412 this->setstate(ios_base::badbit | ios_base::failbit);
413 }
414#ifndef _LIBCPP_NO_EXCEPTIONS
415 }
416 catch (...)
417 {
418 this->__set_badbit_and_consider_rethrow();
419 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000420#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 return *this;
422}
423
424template <class _CharT, class _Traits>
425basic_ostream<_CharT, _Traits>&
426basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
427{
428#ifndef _LIBCPP_NO_EXCEPTIONS
429 try
430 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000431#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 sentry __s(*this);
433 if (__s)
434 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000435 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
436 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
438 this->setstate(ios_base::badbit | ios_base::failbit);
439 }
440#ifndef _LIBCPP_NO_EXCEPTIONS
441 }
442 catch (...)
443 {
444 this->__set_badbit_and_consider_rethrow();
445 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000446#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447 return *this;
448}
449
450template <class _CharT, class _Traits>
451basic_ostream<_CharT, _Traits>&
452basic_ostream<_CharT, _Traits>::operator<<(int __n)
453{
454#ifndef _LIBCPP_NO_EXCEPTIONS
455 try
456 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000457#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 sentry __s(*this);
459 if (__s)
460 {
461 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000462 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
463 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 if (__f.put(*this, *this, this->fill(),
465 __flags == ios_base::oct || __flags == ios_base::hex ?
466 static_cast<long>(static_cast<unsigned int>(__n)) :
467 static_cast<long>(__n)).failed())
468 this->setstate(ios_base::badbit | ios_base::failbit);
469 }
470#ifndef _LIBCPP_NO_EXCEPTIONS
471 }
472 catch (...)
473 {
474 this->__set_badbit_and_consider_rethrow();
475 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000476#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477 return *this;
478}
479
480template <class _CharT, class _Traits>
481basic_ostream<_CharT, _Traits>&
482basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
483{
484#ifndef _LIBCPP_NO_EXCEPTIONS
485 try
486 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000487#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 sentry __s(*this);
489 if (__s)
490 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000491 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
492 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
494 this->setstate(ios_base::badbit | ios_base::failbit);
495 }
496#ifndef _LIBCPP_NO_EXCEPTIONS
497 }
498 catch (...)
499 {
500 this->__set_badbit_and_consider_rethrow();
501 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000502#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 return *this;
504}
505
506template <class _CharT, class _Traits>
507basic_ostream<_CharT, _Traits>&
508basic_ostream<_CharT, _Traits>::operator<<(long __n)
509{
510#ifndef _LIBCPP_NO_EXCEPTIONS
511 try
512 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000513#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 sentry __s(*this);
515 if (__s)
516 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000517 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
518 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 if (__f.put(*this, *this, this->fill(), __n).failed())
520 this->setstate(ios_base::badbit | ios_base::failbit);
521 }
522#ifndef _LIBCPP_NO_EXCEPTIONS
523 }
524 catch (...)
525 {
526 this->__set_badbit_and_consider_rethrow();
527 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000528#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529 return *this;
530}
531
532template <class _CharT, class _Traits>
533basic_ostream<_CharT, _Traits>&
534basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
535{
536#ifndef _LIBCPP_NO_EXCEPTIONS
537 try
538 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000539#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540 sentry __s(*this);
541 if (__s)
542 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000543 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
544 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545 if (__f.put(*this, *this, this->fill(), __n).failed())
546 this->setstate(ios_base::badbit | ios_base::failbit);
547 }
548#ifndef _LIBCPP_NO_EXCEPTIONS
549 }
550 catch (...)
551 {
552 this->__set_badbit_and_consider_rethrow();
553 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000554#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 return *this;
556}
557
558template <class _CharT, class _Traits>
559basic_ostream<_CharT, _Traits>&
560basic_ostream<_CharT, _Traits>::operator<<(long long __n)
561{
562#ifndef _LIBCPP_NO_EXCEPTIONS
563 try
564 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000565#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566 sentry __s(*this);
567 if (__s)
568 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000569 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
570 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571 if (__f.put(*this, *this, this->fill(), __n).failed())
572 this->setstate(ios_base::badbit | ios_base::failbit);
573 }
574#ifndef _LIBCPP_NO_EXCEPTIONS
575 }
576 catch (...)
577 {
578 this->__set_badbit_and_consider_rethrow();
579 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000580#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581 return *this;
582}
583
584template <class _CharT, class _Traits>
585basic_ostream<_CharT, _Traits>&
586basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
587{
588#ifndef _LIBCPP_NO_EXCEPTIONS
589 try
590 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000591#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 sentry __s(*this);
593 if (__s)
594 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000595 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
596 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597 if (__f.put(*this, *this, this->fill(), __n).failed())
598 this->setstate(ios_base::badbit | ios_base::failbit);
599 }
600#ifndef _LIBCPP_NO_EXCEPTIONS
601 }
602 catch (...)
603 {
604 this->__set_badbit_and_consider_rethrow();
605 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000606#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607 return *this;
608}
609
610template <class _CharT, class _Traits>
611basic_ostream<_CharT, _Traits>&
612basic_ostream<_CharT, _Traits>::operator<<(float __n)
613{
614#ifndef _LIBCPP_NO_EXCEPTIONS
615 try
616 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000617#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 sentry __s(*this);
619 if (__s)
620 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000621 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
622 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
624 this->setstate(ios_base::badbit | ios_base::failbit);
625 }
626#ifndef _LIBCPP_NO_EXCEPTIONS
627 }
628 catch (...)
629 {
630 this->__set_badbit_and_consider_rethrow();
631 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000632#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633 return *this;
634}
635
636template <class _CharT, class _Traits>
637basic_ostream<_CharT, _Traits>&
638basic_ostream<_CharT, _Traits>::operator<<(double __n)
639{
640#ifndef _LIBCPP_NO_EXCEPTIONS
641 try
642 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000643#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 sentry __s(*this);
645 if (__s)
646 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000647 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
648 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649 if (__f.put(*this, *this, this->fill(), __n).failed())
650 this->setstate(ios_base::badbit | ios_base::failbit);
651 }
652#ifndef _LIBCPP_NO_EXCEPTIONS
653 }
654 catch (...)
655 {
656 this->__set_badbit_and_consider_rethrow();
657 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000658#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659 return *this;
660}
661
662template <class _CharT, class _Traits>
663basic_ostream<_CharT, _Traits>&
664basic_ostream<_CharT, _Traits>::operator<<(long double __n)
665{
666#ifndef _LIBCPP_NO_EXCEPTIONS
667 try
668 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000669#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 sentry __s(*this);
671 if (__s)
672 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000673 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
674 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 if (__f.put(*this, *this, this->fill(), __n).failed())
676 this->setstate(ios_base::badbit | ios_base::failbit);
677 }
678#ifndef _LIBCPP_NO_EXCEPTIONS
679 }
680 catch (...)
681 {
682 this->__set_badbit_and_consider_rethrow();
683 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000684#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685 return *this;
686}
687
688template <class _CharT, class _Traits>
689basic_ostream<_CharT, _Traits>&
690basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
691{
692#ifndef _LIBCPP_NO_EXCEPTIONS
693 try
694 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000695#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696 sentry __s(*this);
697 if (__s)
698 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000699 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
700 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 if (__f.put(*this, *this, this->fill(), __n).failed())
702 this->setstate(ios_base::badbit | ios_base::failbit);
703 }
704#ifndef _LIBCPP_NO_EXCEPTIONS
705 }
706 catch (...)
707 {
708 this->__set_badbit_and_consider_rethrow();
709 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000710#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711 return *this;
712}
713
714template<class _CharT, class _Traits>
715basic_ostream<_CharT, _Traits>&
Marshall Clow00995642013-12-10 19:25:49 +0000716__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
717 const _CharT* __str, size_t __len)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718{
719#ifndef _LIBCPP_NO_EXCEPTIONS
720 try
721 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000722#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
724 if (__s)
725 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000726 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
727 if (__pad_and_output(_Ip(__os),
Marshall Clow00995642013-12-10 19:25:49 +0000728 __str,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow00995642013-12-10 19:25:49 +0000730 __str + __len :
731 __str,
732 __str + __len,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 __os,
734 __os.fill()).failed())
735 __os.setstate(ios_base::badbit | ios_base::failbit);
736 }
737#ifndef _LIBCPP_NO_EXCEPTIONS
738 }
739 catch (...)
740 {
741 __os.__set_badbit_and_consider_rethrow();
742 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000743#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744 return __os;
745}
746
Marshall Clow00995642013-12-10 19:25:49 +0000747
748template<class _CharT, class _Traits>
749basic_ostream<_CharT, _Traits>&
750operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
751{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000752 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow00995642013-12-10 19:25:49 +0000753}
754
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755template<class _CharT, class _Traits>
756basic_ostream<_CharT, _Traits>&
757operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
758{
759#ifndef _LIBCPP_NO_EXCEPTIONS
760 try
761 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000762#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
764 if (__s)
765 {
766 _CharT __c = __os.widen(__cn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000767 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
768 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 &__c,
770 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
771 &__c + 1 :
772 &__c,
773 &__c + 1,
774 __os,
775 __os.fill()).failed())
776 __os.setstate(ios_base::badbit | ios_base::failbit);
777 }
778#ifndef _LIBCPP_NO_EXCEPTIONS
779 }
780 catch (...)
781 {
782 __os.__set_badbit_and_consider_rethrow();
783 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000784#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 return __os;
786}
787
788template<class _Traits>
789basic_ostream<char, _Traits>&
790operator<<(basic_ostream<char, _Traits>& __os, char __c)
791{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000792 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793}
794
795template<class _Traits>
796basic_ostream<char, _Traits>&
797operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
798{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000799 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800}
801
802template<class _Traits>
803basic_ostream<char, _Traits>&
804operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
805{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000806 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807}
808
809template<class _CharT, class _Traits>
810basic_ostream<_CharT, _Traits>&
811operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
812{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000813 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814}
815
816template<class _CharT, class _Traits>
817basic_ostream<_CharT, _Traits>&
818operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
819{
820#ifndef _LIBCPP_NO_EXCEPTIONS
821 try
822 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000823#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
825 if (__s)
826 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000827 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828 size_t __len = char_traits<char>::length(__strn);
829 const int __bs = 100;
830 _CharT __wbb[__bs];
831 _CharT* __wb = __wbb;
832 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
833 if (__len > __bs)
834 {
835 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
836 if (__wb == 0)
837 __throw_bad_alloc();
838 __h.reset(__wb);
839 }
840 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
841 *__p = __os.widen(*__strn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000842 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843 __wb,
844 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
845 __wb + __len :
846 __wb,
847 __wb + __len,
848 __os,
849 __os.fill()).failed())
850 __os.setstate(ios_base::badbit | ios_base::failbit);
851 }
852#ifndef _LIBCPP_NO_EXCEPTIONS
853 }
854 catch (...)
855 {
856 __os.__set_badbit_and_consider_rethrow();
857 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000858#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 return __os;
860}
861
862template<class _Traits>
863basic_ostream<char, _Traits>&
864operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
865{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000866 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867}
868
869template<class _Traits>
870basic_ostream<char, _Traits>&
871operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
872{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000873 const char *__s = (const char *) __str;
874 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875}
876
877template<class _Traits>
878basic_ostream<char, _Traits>&
879operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
880{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000881 const char *__s = (const char *) __str;
882 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883}
884
885template <class _CharT, class _Traits>
886basic_ostream<_CharT, _Traits>&
887basic_ostream<_CharT, _Traits>::put(char_type __c)
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 sentry __s(*this);
894 if (__s)
895 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000896 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
897 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898 *__o = __c;
899 if (__o.failed())
900 this->setstate(ios_base::badbit);
901 }
902#ifndef _LIBCPP_NO_EXCEPTIONS
903 }
904 catch (...)
905 {
906 this->__set_badbit_and_consider_rethrow();
907 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000908#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 return *this;
910}
911
912template <class _CharT, class _Traits>
913basic_ostream<_CharT, _Traits>&
914basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
915{
916#ifndef _LIBCPP_NO_EXCEPTIONS
917 try
918 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000919#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 sentry __sen(*this);
921 if (__sen && __n)
922 {
Howard Hinnant79cef932013-01-15 17:22:03 +0000923 if (this->rdbuf()->sputn(__s, __n) != __n)
924 this->setstate(ios_base::badbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 }
926#ifndef _LIBCPP_NO_EXCEPTIONS
927 }
928 catch (...)
929 {
930 this->__set_badbit_and_consider_rethrow();
931 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000932#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 return *this;
934}
935
936template <class _CharT, class _Traits>
937basic_ostream<_CharT, _Traits>&
938basic_ostream<_CharT, _Traits>::flush()
939{
940#ifndef _LIBCPP_NO_EXCEPTIONS
941 try
942 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000943#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944 if (this->rdbuf())
945 {
946 sentry __s(*this);
947 if (__s)
948 {
949 if (this->rdbuf()->pubsync() == -1)
950 this->setstate(ios_base::badbit);
951 }
952 }
953#ifndef _LIBCPP_NO_EXCEPTIONS
954 }
955 catch (...)
956 {
957 this->__set_badbit_and_consider_rethrow();
958 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000959#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960 return *this;
961}
962
963template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964typename basic_ostream<_CharT, _Traits>::pos_type
965basic_ostream<_CharT, _Traits>::tellp()
966{
967 if (this->fail())
968 return pos_type(-1);
969 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
970}
971
972template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973basic_ostream<_CharT, _Traits>&
974basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
975{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000976 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000977 if (!this->fail())
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 {
979 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
980 this->setstate(ios_base::failbit);
981 }
982 return *this;
983}
984
985template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986basic_ostream<_CharT, _Traits>&
987basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
988{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000989 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000990 if (!this->fail())
Marshall Clow29c4daa2013-10-31 22:20:45 +0000991 {
992 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
993 this->setstate(ios_base::failbit);
994 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 return *this;
996}
997
998template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000999inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000basic_ostream<_CharT, _Traits>&
1001endl(basic_ostream<_CharT, _Traits>& __os)
1002{
1003 __os.put(__os.widen('\n'));
1004 __os.flush();
1005 return __os;
1006}
1007
1008template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001009inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010basic_ostream<_CharT, _Traits>&
1011ends(basic_ostream<_CharT, _Traits>& __os)
1012{
1013 __os.put(_CharT());
1014 return __os;
1015}
1016
1017template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001018inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019basic_ostream<_CharT, _Traits>&
1020flush(basic_ostream<_CharT, _Traits>& __os)
1021{
1022 __os.flush();
1023 return __os;
1024}
1025
Howard Hinnant74279a52010-09-04 23:28:19 +00001026#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027
1028template <class _Stream, class _Tp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001029inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030typename enable_if
1031<
1032 !is_lvalue_reference<_Stream>::value &&
1033 is_base_of<ios_base, _Stream>::value,
Howard Hinnantc8697b62012-01-12 23:37:51 +00001034 _Stream&&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035>::type
1036operator<<(_Stream&& __os, const _Tp& __x)
1037{
1038 __os << __x;
Howard Hinnantc8697b62012-01-12 23:37:51 +00001039 return _VSTD::move(__os);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040}
1041
Howard Hinnant74279a52010-09-04 23:28:19 +00001042#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043
1044template<class _CharT, class _Traits, class _Allocator>
1045basic_ostream<_CharT, _Traits>&
1046operator<<(basic_ostream<_CharT, _Traits>& __os,
1047 const basic_string<_CharT, _Traits, _Allocator>& __str)
1048{
Marshall Clow4bc2be22014-02-16 01:57:26 +00001049 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050}
1051
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001052template<class _CharT, class _Traits>
1053basic_ostream<_CharT, _Traits>&
1054operator<<(basic_ostream<_CharT, _Traits>& __os,
1055 const basic_string_view<_CharT, _Traits> __sv)
1056{
1057 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1058}
1059
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062basic_ostream<_CharT, _Traits>&
1063operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1064{
1065 return __os << __ec.category().name() << ':' << __ec.value();
1066}
1067
Howard Hinnantc834c512011-11-29 18:15:50 +00001068template<class _CharT, class _Traits, class _Yp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001071operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072{
1073 return __os << __p.get();
1074}
1075
1076template <class _CharT, class _Traits, size_t _Size>
1077basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001078operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079{
1080 return __os << __x.template to_string<_CharT, _Traits>
1081 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1082 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1083}
1084
Eric Fiselier1b57fa82016-09-15 22:27:07 +00001085_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1086_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087
1088_LIBCPP_END_NAMESPACE_STD
1089
1090#endif // _LIBCPP_OSTREAM