blob: ef34f71c10ad94b236135556a9c15898a88ba573 [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
Marshall Clow2df37002013-08-14 15:15:28 +000035 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
Howard Hinnantbc8d3f92010-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 Clow546eca82014-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 Hinnantbc8d3f92010-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 Hinnant08e17472011-10-17 20:05:10 +0000144#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000145#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000146#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000147
148_LIBCPP_BEGIN_NAMESPACE_STD
149
150template <class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000151class _LIBCPP_TEMPLATE_VIS basic_ostream
Howard Hinnantbc8d3f92010-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:
Louis Dionne3845a652018-10-16 19:26:23 +0000163 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier6dbed462016-09-16 00:00:48 +0000164 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
165 { this->init(__sb); }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000166 virtual ~basic_ostream();
167protected:
Eric Fiseliere915b5c2017-04-18 23:38:41 +0000168#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier6dbed462016-09-16 00:00:48 +0000169 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170 basic_ostream(basic_ostream&& __rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000171
172 // 27.7.2.3 Assign/swap
Eric Fiselier6dbed462016-09-16 00:00:48 +0000173 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000174 basic_ostream& operator=(basic_ostream&& __rhs);
175#endif
Louis Dionne3845a652018-10-16 19:26:23 +0000176 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier6dbed462016-09-16 00:00:48 +0000177 void swap(basic_ostream& __rhs)
178 { basic_ios<char_type, traits_type>::swap(__rhs); }
Marshall Clow546eca82014-09-16 15:27:01 +0000179
Eric Fiselier8eb066a2017-01-06 20:58:25 +0000180#ifndef _LIBCPP_CXX03_LANG
Marshall Clowd1fae172014-09-16 15:33:53 +0000181 basic_ostream (const basic_ostream& __rhs) = delete;
182 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
Marshall Clow546eca82014-09-16 15:27:01 +0000183#else
Marshall Clowbb9902e2014-09-17 01:58:15 +0000184 basic_ostream (const basic_ostream& __rhs); // not defined
185 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
Marshall Clow546eca82014-09-16 15:27:01 +0000186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187public:
188
189 // 27.7.2.4 Prefix/suffix:
Eric Fiselierc3589a82017-01-04 23:56:00 +0000190 class _LIBCPP_TEMPLATE_VIS sentry;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000191
192 // 27.7.2.6 Formatted output:
Louis Dionne3845a652018-10-16 19:26:23 +0000193 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier6dbed462016-09-16 00:00:48 +0000194 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
195 { return __pf(*this); }
196
Louis Dionne3845a652018-10-16 19:26:23 +0000197 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
Eric Fiselier6dbed462016-09-16 00:00:48 +0000199 (*__pf)(basic_ios<char_type,traits_type>&))
200 { __pf(*this); return *this; }
201
Louis Dionne3845a652018-10-16 19:26:23 +0000202 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier6dbed462016-09-16 00:00:48 +0000203 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
204 { __pf(*this); return *this; }
205
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000206 basic_ostream& operator<<(bool __n);
207 basic_ostream& operator<<(short __n);
208 basic_ostream& operator<<(unsigned short __n);
209 basic_ostream& operator<<(int __n);
210 basic_ostream& operator<<(unsigned int __n);
211 basic_ostream& operator<<(long __n);
212 basic_ostream& operator<<(unsigned long __n);
213 basic_ostream& operator<<(long long __n);
214 basic_ostream& operator<<(unsigned long long __n);
215 basic_ostream& operator<<(float __f);
216 basic_ostream& operator<<(double __f);
217 basic_ostream& operator<<(long double __f);
218 basic_ostream& operator<<(const void* __p);
219 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
220
221 // 27.7.2.7 Unformatted output:
222 basic_ostream& put(char_type __c);
223 basic_ostream& write(const char_type* __s, streamsize __n);
224 basic_ostream& flush();
225
226 // 27.7.2.5 seeks:
Louis Dionne3845a652018-10-16 19:26:23 +0000227 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228 pos_type tellp();
Louis Dionne3845a652018-10-16 19:26:23 +0000229 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230 basic_ostream& seekp(pos_type __pos);
Louis Dionne3845a652018-10-16 19:26:23 +0000231 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
233
234protected:
Louis Dionne54238052018-07-11 23:14:33 +0000235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236 basic_ostream() {} // extension, intentially does not initialize
237};
238
239template <class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000240class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241{
242 bool __ok_;
243 basic_ostream<_CharT, _Traits>& __os_;
244
245 sentry(const sentry&); // = delete;
246 sentry& operator=(const sentry&); // = delete;
247
248public:
249 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
250 ~sentry();
251
Louis Dionne54238052018-07-11 23:14:33 +0000252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +0000253 _LIBCPP_EXPLICIT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254 operator bool() const {return __ok_;}
255};
256
257template <class _CharT, class _Traits>
258basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
259 : __ok_(false),
260 __os_(__os)
261{
262 if (__os.good())
263 {
264 if (__os.tie())
265 __os.tie()->flush();
266 __ok_ = true;
267 }
268}
269
270template <class _CharT, class _Traits>
271basic_ostream<_CharT, _Traits>::sentry::~sentry()
272{
273 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
274 && !uncaught_exception())
275 {
276#ifndef _LIBCPP_NO_EXCEPTIONS
277 try
278 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000279#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280 if (__os_.rdbuf()->pubsync() == -1)
281 __os_.setstate(ios_base::badbit);
282#ifndef _LIBCPP_NO_EXCEPTIONS
283 }
284 catch (...)
285 {
286 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000287#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 }
289}
290
Eric Fiseliere915b5c2017-04-18 23:38:41 +0000291#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000292
293template <class _CharT, class _Traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
295{
296 this->move(__rhs);
297}
298
299template <class _CharT, class _Traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300basic_ostream<_CharT, _Traits>&
301basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
302{
303 swap(__rhs);
304 return *this;
305}
306
Eric Fiseliere915b5c2017-04-18 23:38:41 +0000307#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308
309template <class _CharT, class _Traits>
310basic_ostream<_CharT, _Traits>::~basic_ostream()
311{
312}
313
314template <class _CharT, class _Traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315basic_ostream<_CharT, _Traits>&
316basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
317{
318#ifndef _LIBCPP_NO_EXCEPTIONS
319 try
320 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000321#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322 sentry __s(*this);
323 if (__s)
324 {
325 if (__sb)
326 {
327#ifndef _LIBCPP_NO_EXCEPTIONS
328 try
329 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000330#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant99968442011-11-29 18:15:50 +0000331 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
332 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
333 _Ip __i(__sb);
334 _Ip __eof;
335 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336 size_t __c = 0;
337 for (; __i != __eof; ++__i, ++__o, ++__c)
338 {
339 *__o = *__i;
340 if (__o.failed())
341 break;
342 }
343 if (__c == 0)
344 this->setstate(ios_base::failbit);
345#ifndef _LIBCPP_NO_EXCEPTIONS
346 }
347 catch (...)
348 {
349 this->__set_failbit_and_consider_rethrow();
350 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000351#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352 }
353 else
354 this->setstate(ios_base::badbit);
355 }
356#ifndef _LIBCPP_NO_EXCEPTIONS
357 }
358 catch (...)
359 {
360 this->__set_badbit_and_consider_rethrow();
361 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000362#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363 return *this;
364}
365
366template <class _CharT, class _Traits>
367basic_ostream<_CharT, _Traits>&
368basic_ostream<_CharT, _Traits>::operator<<(bool __n)
369{
370#ifndef _LIBCPP_NO_EXCEPTIONS
371 try
372 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000373#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 sentry __s(*this);
375 if (__s)
376 {
Howard Hinnant99968442011-11-29 18:15:50 +0000377 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
378 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379 if (__f.put(*this, *this, this->fill(), __n).failed())
380 this->setstate(ios_base::badbit | ios_base::failbit);
381 }
382#ifndef _LIBCPP_NO_EXCEPTIONS
383 }
384 catch (...)
385 {
386 this->__set_badbit_and_consider_rethrow();
387 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000388#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389 return *this;
390}
391
392template <class _CharT, class _Traits>
393basic_ostream<_CharT, _Traits>&
394basic_ostream<_CharT, _Traits>::operator<<(short __n)
395{
396#ifndef _LIBCPP_NO_EXCEPTIONS
397 try
398 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000399#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 sentry __s(*this);
401 if (__s)
402 {
403 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnant99968442011-11-29 18:15:50 +0000404 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
405 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406 if (__f.put(*this, *this, this->fill(),
407 __flags == ios_base::oct || __flags == ios_base::hex ?
408 static_cast<long>(static_cast<unsigned short>(__n)) :
409 static_cast<long>(__n)).failed())
410 this->setstate(ios_base::badbit | ios_base::failbit);
411 }
412#ifndef _LIBCPP_NO_EXCEPTIONS
413 }
414 catch (...)
415 {
416 this->__set_badbit_and_consider_rethrow();
417 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000418#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 return *this;
420}
421
422template <class _CharT, class _Traits>
423basic_ostream<_CharT, _Traits>&
424basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
425{
426#ifndef _LIBCPP_NO_EXCEPTIONS
427 try
428 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000429#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 sentry __s(*this);
431 if (__s)
432 {
Howard Hinnant99968442011-11-29 18:15:50 +0000433 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
434 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
436 this->setstate(ios_base::badbit | ios_base::failbit);
437 }
438#ifndef _LIBCPP_NO_EXCEPTIONS
439 }
440 catch (...)
441 {
442 this->__set_badbit_and_consider_rethrow();
443 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000444#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445 return *this;
446}
447
448template <class _CharT, class _Traits>
449basic_ostream<_CharT, _Traits>&
450basic_ostream<_CharT, _Traits>::operator<<(int __n)
451{
452#ifndef _LIBCPP_NO_EXCEPTIONS
453 try
454 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000455#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000456 sentry __s(*this);
457 if (__s)
458 {
459 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnant99968442011-11-29 18:15:50 +0000460 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
461 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 if (__f.put(*this, *this, this->fill(),
463 __flags == ios_base::oct || __flags == ios_base::hex ?
464 static_cast<long>(static_cast<unsigned int>(__n)) :
465 static_cast<long>(__n)).failed())
466 this->setstate(ios_base::badbit | ios_base::failbit);
467 }
468#ifndef _LIBCPP_NO_EXCEPTIONS
469 }
470 catch (...)
471 {
472 this->__set_badbit_and_consider_rethrow();
473 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000474#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 return *this;
476}
477
478template <class _CharT, class _Traits>
479basic_ostream<_CharT, _Traits>&
480basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
481{
482#ifndef _LIBCPP_NO_EXCEPTIONS
483 try
484 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000485#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486 sentry __s(*this);
487 if (__s)
488 {
Howard Hinnant99968442011-11-29 18:15:50 +0000489 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
490 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
492 this->setstate(ios_base::badbit | ios_base::failbit);
493 }
494#ifndef _LIBCPP_NO_EXCEPTIONS
495 }
496 catch (...)
497 {
498 this->__set_badbit_and_consider_rethrow();
499 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000500#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 return *this;
502}
503
504template <class _CharT, class _Traits>
505basic_ostream<_CharT, _Traits>&
506basic_ostream<_CharT, _Traits>::operator<<(long __n)
507{
508#ifndef _LIBCPP_NO_EXCEPTIONS
509 try
510 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000511#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512 sentry __s(*this);
513 if (__s)
514 {
Howard Hinnant99968442011-11-29 18:15:50 +0000515 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
516 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517 if (__f.put(*this, *this, this->fill(), __n).failed())
518 this->setstate(ios_base::badbit | ios_base::failbit);
519 }
520#ifndef _LIBCPP_NO_EXCEPTIONS
521 }
522 catch (...)
523 {
524 this->__set_badbit_and_consider_rethrow();
525 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000526#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 return *this;
528}
529
530template <class _CharT, class _Traits>
531basic_ostream<_CharT, _Traits>&
532basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
533{
534#ifndef _LIBCPP_NO_EXCEPTIONS
535 try
536 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000537#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 sentry __s(*this);
539 if (__s)
540 {
Howard Hinnant99968442011-11-29 18:15:50 +0000541 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
542 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543 if (__f.put(*this, *this, this->fill(), __n).failed())
544 this->setstate(ios_base::badbit | ios_base::failbit);
545 }
546#ifndef _LIBCPP_NO_EXCEPTIONS
547 }
548 catch (...)
549 {
550 this->__set_badbit_and_consider_rethrow();
551 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000552#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 return *this;
554}
555
556template <class _CharT, class _Traits>
557basic_ostream<_CharT, _Traits>&
558basic_ostream<_CharT, _Traits>::operator<<(long long __n)
559{
560#ifndef _LIBCPP_NO_EXCEPTIONS
561 try
562 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000563#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 sentry __s(*this);
565 if (__s)
566 {
Howard Hinnant99968442011-11-29 18:15:50 +0000567 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
568 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569 if (__f.put(*this, *this, this->fill(), __n).failed())
570 this->setstate(ios_base::badbit | ios_base::failbit);
571 }
572#ifndef _LIBCPP_NO_EXCEPTIONS
573 }
574 catch (...)
575 {
576 this->__set_badbit_and_consider_rethrow();
577 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000578#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 return *this;
580}
581
582template <class _CharT, class _Traits>
583basic_ostream<_CharT, _Traits>&
584basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
585{
586#ifndef _LIBCPP_NO_EXCEPTIONS
587 try
588 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000589#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590 sentry __s(*this);
591 if (__s)
592 {
Howard Hinnant99968442011-11-29 18:15:50 +0000593 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
594 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 if (__f.put(*this, *this, this->fill(), __n).failed())
596 this->setstate(ios_base::badbit | ios_base::failbit);
597 }
598#ifndef _LIBCPP_NO_EXCEPTIONS
599 }
600 catch (...)
601 {
602 this->__set_badbit_and_consider_rethrow();
603 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000604#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 return *this;
606}
607
608template <class _CharT, class _Traits>
609basic_ostream<_CharT, _Traits>&
610basic_ostream<_CharT, _Traits>::operator<<(float __n)
611{
612#ifndef _LIBCPP_NO_EXCEPTIONS
613 try
614 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000615#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616 sentry __s(*this);
617 if (__s)
618 {
Howard Hinnant99968442011-11-29 18:15:50 +0000619 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
620 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
622 this->setstate(ios_base::badbit | ios_base::failbit);
623 }
624#ifndef _LIBCPP_NO_EXCEPTIONS
625 }
626 catch (...)
627 {
628 this->__set_badbit_and_consider_rethrow();
629 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000630#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 return *this;
632}
633
634template <class _CharT, class _Traits>
635basic_ostream<_CharT, _Traits>&
636basic_ostream<_CharT, _Traits>::operator<<(double __n)
637{
638#ifndef _LIBCPP_NO_EXCEPTIONS
639 try
640 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000641#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642 sentry __s(*this);
643 if (__s)
644 {
Howard Hinnant99968442011-11-29 18:15:50 +0000645 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
646 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647 if (__f.put(*this, *this, this->fill(), __n).failed())
648 this->setstate(ios_base::badbit | ios_base::failbit);
649 }
650#ifndef _LIBCPP_NO_EXCEPTIONS
651 }
652 catch (...)
653 {
654 this->__set_badbit_and_consider_rethrow();
655 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000656#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 return *this;
658}
659
660template <class _CharT, class _Traits>
661basic_ostream<_CharT, _Traits>&
662basic_ostream<_CharT, _Traits>::operator<<(long double __n)
663{
664#ifndef _LIBCPP_NO_EXCEPTIONS
665 try
666 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000667#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 sentry __s(*this);
669 if (__s)
670 {
Howard Hinnant99968442011-11-29 18:15:50 +0000671 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
672 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673 if (__f.put(*this, *this, this->fill(), __n).failed())
674 this->setstate(ios_base::badbit | ios_base::failbit);
675 }
676#ifndef _LIBCPP_NO_EXCEPTIONS
677 }
678 catch (...)
679 {
680 this->__set_badbit_and_consider_rethrow();
681 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000682#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683 return *this;
684}
685
686template <class _CharT, class _Traits>
687basic_ostream<_CharT, _Traits>&
688basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
689{
690#ifndef _LIBCPP_NO_EXCEPTIONS
691 try
692 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000693#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694 sentry __s(*this);
695 if (__s)
696 {
Howard Hinnant99968442011-11-29 18:15:50 +0000697 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
698 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 if (__f.put(*this, *this, this->fill(), __n).failed())
700 this->setstate(ios_base::badbit | ios_base::failbit);
701 }
702#ifndef _LIBCPP_NO_EXCEPTIONS
703 }
704 catch (...)
705 {
706 this->__set_badbit_and_consider_rethrow();
707 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000708#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709 return *this;
710}
711
712template<class _CharT, class _Traits>
713basic_ostream<_CharT, _Traits>&
Marshall Clow73b46a72013-12-10 19:25:49 +0000714__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
715 const _CharT* __str, size_t __len)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716{
717#ifndef _LIBCPP_NO_EXCEPTIONS
718 try
719 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000720#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
722 if (__s)
723 {
Howard Hinnant99968442011-11-29 18:15:50 +0000724 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
725 if (__pad_and_output(_Ip(__os),
Marshall Clow73b46a72013-12-10 19:25:49 +0000726 __str,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow73b46a72013-12-10 19:25:49 +0000728 __str + __len :
729 __str,
730 __str + __len,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731 __os,
732 __os.fill()).failed())
733 __os.setstate(ios_base::badbit | ios_base::failbit);
734 }
735#ifndef _LIBCPP_NO_EXCEPTIONS
736 }
737 catch (...)
738 {
739 __os.__set_badbit_and_consider_rethrow();
740 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000741#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 return __os;
743}
744
Volodymyr Sapsaie59d0982018-09-19 23:31:34 +0000745
Marshall Clow73b46a72013-12-10 19:25:49 +0000746template<class _CharT, class _Traits>
747basic_ostream<_CharT, _Traits>&
748operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
749{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000750 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow73b46a72013-12-10 19:25:49 +0000751}
752
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753template<class _CharT, class _Traits>
754basic_ostream<_CharT, _Traits>&
755operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
756{
757#ifndef _LIBCPP_NO_EXCEPTIONS
758 try
759 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000760#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
762 if (__s)
763 {
764 _CharT __c = __os.widen(__cn);
Howard Hinnant99968442011-11-29 18:15:50 +0000765 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
766 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767 &__c,
768 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
769 &__c + 1 :
770 &__c,
771 &__c + 1,
772 __os,
773 __os.fill()).failed())
774 __os.setstate(ios_base::badbit | ios_base::failbit);
775 }
776#ifndef _LIBCPP_NO_EXCEPTIONS
777 }
778 catch (...)
779 {
780 __os.__set_badbit_and_consider_rethrow();
781 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000782#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783 return __os;
784}
785
786template<class _Traits>
787basic_ostream<char, _Traits>&
788operator<<(basic_ostream<char, _Traits>& __os, char __c)
789{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000790 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791}
792
793template<class _Traits>
794basic_ostream<char, _Traits>&
795operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
796{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000797 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798}
799
800template<class _Traits>
801basic_ostream<char, _Traits>&
802operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
803{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000804 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805}
806
807template<class _CharT, class _Traits>
808basic_ostream<_CharT, _Traits>&
809operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
810{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000811 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812}
813
814template<class _CharT, class _Traits>
815basic_ostream<_CharT, _Traits>&
816operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
817{
818#ifndef _LIBCPP_NO_EXCEPTIONS
819 try
820 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000821#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
823 if (__s)
824 {
Howard Hinnant99968442011-11-29 18:15:50 +0000825 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 size_t __len = char_traits<char>::length(__strn);
827 const int __bs = 100;
828 _CharT __wbb[__bs];
829 _CharT* __wb = __wbb;
830 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
831 if (__len > __bs)
832 {
833 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
834 if (__wb == 0)
835 __throw_bad_alloc();
836 __h.reset(__wb);
837 }
838 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
839 *__p = __os.widen(*__strn);
Howard Hinnant99968442011-11-29 18:15:50 +0000840 if (__pad_and_output(_Ip(__os),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 __wb,
842 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
843 __wb + __len :
844 __wb,
845 __wb + __len,
846 __os,
847 __os.fill()).failed())
848 __os.setstate(ios_base::badbit | ios_base::failbit);
849 }
850#ifndef _LIBCPP_NO_EXCEPTIONS
851 }
852 catch (...)
853 {
854 __os.__set_badbit_and_consider_rethrow();
855 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000856#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 return __os;
858}
859
860template<class _Traits>
861basic_ostream<char, _Traits>&
862operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
863{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000864 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865}
866
867template<class _Traits>
868basic_ostream<char, _Traits>&
869operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
870{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000871 const char *__s = (const char *) __str;
872 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873}
874
875template<class _Traits>
876basic_ostream<char, _Traits>&
877operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
878{
Marshall Clow8eb5acc2014-02-16 01:57:26 +0000879 const char *__s = (const char *) __str;
880 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881}
882
883template <class _CharT, class _Traits>
884basic_ostream<_CharT, _Traits>&
885basic_ostream<_CharT, _Traits>::put(char_type __c)
886{
887#ifndef _LIBCPP_NO_EXCEPTIONS
888 try
889 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000890#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 sentry __s(*this);
892 if (__s)
893 {
Howard Hinnant99968442011-11-29 18:15:50 +0000894 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
895 _Op __o(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 *__o = __c;
897 if (__o.failed())
898 this->setstate(ios_base::badbit);
899 }
900#ifndef _LIBCPP_NO_EXCEPTIONS
901 }
902 catch (...)
903 {
904 this->__set_badbit_and_consider_rethrow();
905 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000906#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907 return *this;
908}
909
910template <class _CharT, class _Traits>
911basic_ostream<_CharT, _Traits>&
912basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
913{
914#ifndef _LIBCPP_NO_EXCEPTIONS
915 try
916 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000917#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 sentry __sen(*this);
919 if (__sen && __n)
920 {
Howard Hinnant0b939632013-01-15 17:22:03 +0000921 if (this->rdbuf()->sputn(__s, __n) != __n)
922 this->setstate(ios_base::badbit);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923 }
924#ifndef _LIBCPP_NO_EXCEPTIONS
925 }
926 catch (...)
927 {
928 this->__set_badbit_and_consider_rethrow();
929 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000930#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931 return *this;
932}
933
934template <class _CharT, class _Traits>
935basic_ostream<_CharT, _Traits>&
936basic_ostream<_CharT, _Traits>::flush()
937{
938#ifndef _LIBCPP_NO_EXCEPTIONS
939 try
940 {
Howard Hinnant324bb032010-08-22 00:02:43 +0000941#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 if (this->rdbuf())
943 {
944 sentry __s(*this);
945 if (__s)
946 {
947 if (this->rdbuf()->pubsync() == -1)
948 this->setstate(ios_base::badbit);
949 }
950 }
951#ifndef _LIBCPP_NO_EXCEPTIONS
952 }
953 catch (...)
954 {
955 this->__set_badbit_and_consider_rethrow();
956 }
Howard Hinnant324bb032010-08-22 00:02:43 +0000957#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 return *this;
959}
960
961template <class _CharT, class _Traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962typename basic_ostream<_CharT, _Traits>::pos_type
963basic_ostream<_CharT, _Traits>::tellp()
964{
965 if (this->fail())
966 return pos_type(-1);
967 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
968}
969
970template <class _CharT, class _Traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971basic_ostream<_CharT, _Traits>&
972basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
973{
Marshall Clow76a86702013-10-31 22:20:45 +0000974 sentry __s(*this);
Marshall Clow1224e892015-06-22 15:01:21 +0000975 if (!this->fail())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 {
977 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
978 this->setstate(ios_base::failbit);
979 }
980 return *this;
981}
982
983template <class _CharT, class _Traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984basic_ostream<_CharT, _Traits>&
985basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
986{
Marshall Clow76a86702013-10-31 22:20:45 +0000987 sentry __s(*this);
Marshall Clow1224e892015-06-22 15:01:21 +0000988 if (!this->fail())
Marshall Clow76a86702013-10-31 22:20:45 +0000989 {
990 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
991 this->setstate(ios_base::failbit);
992 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993 return *this;
994}
995
996template <class _CharT, class _Traits>
Evgeniy Stepanov4c7ee802016-01-08 19:21:02 +0000997inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998basic_ostream<_CharT, _Traits>&
999endl(basic_ostream<_CharT, _Traits>& __os)
1000{
1001 __os.put(__os.widen('\n'));
1002 __os.flush();
1003 return __os;
1004}
1005
1006template <class _CharT, class _Traits>
Evgeniy Stepanov4c7ee802016-01-08 19:21:02 +00001007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008basic_ostream<_CharT, _Traits>&
1009ends(basic_ostream<_CharT, _Traits>& __os)
1010{
1011 __os.put(_CharT());
1012 return __os;
1013}
1014
1015template <class _CharT, class _Traits>
Evgeniy Stepanov4c7ee802016-01-08 19:21:02 +00001016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001017basic_ostream<_CharT, _Traits>&
1018flush(basic_ostream<_CharT, _Traits>& __os)
1019{
1020 __os.flush();
1021 return __os;
1022}
1023
Eric Fiseliere915b5c2017-04-18 23:38:41 +00001024#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025
1026template <class _Stream, class _Tp>
Evgeniy Stepanov4c7ee802016-01-08 19:21:02 +00001027inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028typename enable_if
1029<
1030 !is_lvalue_reference<_Stream>::value &&
1031 is_base_of<ios_base, _Stream>::value,
Howard Hinnante1a7b042012-01-12 23:37:51 +00001032 _Stream&&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033>::type
1034operator<<(_Stream&& __os, const _Tp& __x)
1035{
1036 __os << __x;
Howard Hinnante1a7b042012-01-12 23:37:51 +00001037 return _VSTD::move(__os);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038}
1039
Eric Fiseliere915b5c2017-04-18 23:38:41 +00001040#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041
1042template<class _CharT, class _Traits, class _Allocator>
1043basic_ostream<_CharT, _Traits>&
1044operator<<(basic_ostream<_CharT, _Traits>& __os,
1045 const basic_string<_CharT, _Traits, _Allocator>& __str)
1046{
Marshall Clow8eb5acc2014-02-16 01:57:26 +00001047 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048}
1049
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001050template<class _CharT, class _Traits>
1051basic_ostream<_CharT, _Traits>&
1052operator<<(basic_ostream<_CharT, _Traits>& __os,
1053 const basic_string_view<_CharT, _Traits> __sv)
1054{
1055 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1056}
1057
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058template <class _CharT, class _Traits>
Evgeniy Stepanov4c7ee802016-01-08 19:21:02 +00001059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060basic_ostream<_CharT, _Traits>&
1061operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1062{
1063 return __os << __ec.category().name() << ':' << __ec.value();
1064}
1065
Howard Hinnant99968442011-11-29 18:15:50 +00001066template<class _CharT, class _Traits, class _Yp>
Evgeniy Stepanov4c7ee802016-01-08 19:21:02 +00001067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00001069operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070{
1071 return __os << __p.get();
1072}
1073
Marshall Clowb2502942017-11-27 15:51:36 +00001074template<class _CharT, class _Traits, class _Yp, class _Dp>
1075inline _LIBCPP_INLINE_VISIBILITY
1076typename enable_if
1077<
Marshall Clowe9e128b2018-03-22 18:27:28 +00001078 is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value,
Marshall Clowb2502942017-11-27 15:51:36 +00001079 basic_ostream<_CharT, _Traits>&
1080>::type
1081operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1082{
1083 return __os << __p.get();
1084}
1085
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086template <class _CharT, class _Traits, size_t _Size>
1087basic_ostream<_CharT, _Traits>&
Howard Hinnanta02851e2011-04-05 14:55:28 +00001088operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089{
1090 return __os << __x.template to_string<_CharT, _Traits>
1091 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1092 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1093}
1094
Mehdi Amini907c1192017-05-04 17:08:54 +00001095#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
Eric Fiselier833d6442016-09-15 22:27:07 +00001096_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1097_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
Mehdi Amini907c1192017-05-04 17:08:54 +00001098#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099
1100_LIBCPP_END_NAMESPACE_STD
1101
1102#endif // _LIBCPP_OSTREAM