blob: d700a369b34aabb5929499fb0241f83093dd17b6 [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>
Marshall Clow8732fed2018-12-11 04:35:44 +0000143#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000145#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000147#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148
149_LIBCPP_BEGIN_NAMESPACE_STD
150
151template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000152class _LIBCPP_TEMPLATE_VIS basic_ostream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 : virtual public basic_ios<_CharT, _Traits>
154{
155public:
156 // types (inherited from basic_ios (27.5.4)):
157 typedef _CharT char_type;
158 typedef _Traits traits_type;
159 typedef typename traits_type::int_type int_type;
160 typedef typename traits_type::pos_type pos_type;
161 typedef typename traits_type::off_type off_type;
162
163 // 27.7.2.2 Constructor/destructor:
Louis Dionneb4d05d72018-10-16 19:26:23 +0000164 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000165 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
166 { this->init(__sb); }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167 virtual ~basic_ostream();
168protected:
Eric Fiselier78ccf772017-04-18 23:38:41 +0000169#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier815ed732016-09-16 00:00:48 +0000170 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171 basic_ostream(basic_ostream&& __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172
173 // 27.7.2.3 Assign/swap
Eric Fiselier815ed732016-09-16 00:00:48 +0000174 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175 basic_ostream& operator=(basic_ostream&& __rhs);
176#endif
Louis Dionneb4d05d72018-10-16 19:26:23 +0000177 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000178 void swap(basic_ostream& __rhs)
179 { basic_ios<char_type, traits_type>::swap(__rhs); }
Marshall Clow27d29872014-09-16 15:27:01 +0000180
Eric Fiselier2d8515f2017-01-06 20:58:25 +0000181#ifndef _LIBCPP_CXX03_LANG
Marshall Clow242d9c12014-09-16 15:33:53 +0000182 basic_ostream (const basic_ostream& __rhs) = delete;
183 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
Marshall Clow27d29872014-09-16 15:27:01 +0000184#else
Marshall Clowd37f25c2014-09-17 01:58:15 +0000185 basic_ostream (const basic_ostream& __rhs); // not defined
186 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
Marshall Clow27d29872014-09-16 15:27:01 +0000187#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188public:
189
190 // 27.7.2.4 Prefix/suffix:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000191 class _LIBCPP_TEMPLATE_VIS sentry;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192
193 // 27.7.2.6 Formatted output:
Louis Dionneb4d05d72018-10-16 19:26:23 +0000194 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000195 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
196 { return __pf(*this); }
197
Louis Dionneb4d05d72018-10-16 19:26:23 +0000198 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
Eric Fiselier815ed732016-09-16 00:00:48 +0000200 (*__pf)(basic_ios<char_type,traits_type>&))
201 { __pf(*this); return *this; }
202
Louis Dionneb4d05d72018-10-16 19:26:23 +0000203 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000204 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
205 { __pf(*this); return *this; }
206
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207 basic_ostream& operator<<(bool __n);
208 basic_ostream& operator<<(short __n);
209 basic_ostream& operator<<(unsigned short __n);
210 basic_ostream& operator<<(int __n);
211 basic_ostream& operator<<(unsigned int __n);
212 basic_ostream& operator<<(long __n);
213 basic_ostream& operator<<(unsigned long __n);
214 basic_ostream& operator<<(long long __n);
215 basic_ostream& operator<<(unsigned long long __n);
216 basic_ostream& operator<<(float __f);
217 basic_ostream& operator<<(double __f);
218 basic_ostream& operator<<(long double __f);
219 basic_ostream& operator<<(const void* __p);
220 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
221
222 // 27.7.2.7 Unformatted output:
223 basic_ostream& put(char_type __c);
224 basic_ostream& write(const char_type* __s, streamsize __n);
225 basic_ostream& flush();
226
227 // 27.7.2.5 seeks:
Louis Dionneb4d05d72018-10-16 19:26:23 +0000228 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229 pos_type tellp();
Louis Dionneb4d05d72018-10-16 19:26:23 +0000230 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000231 basic_ostream& seekp(pos_type __pos);
Louis Dionneb4d05d72018-10-16 19:26:23 +0000232 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
234
235protected:
Louis Dionne16fe2952018-07-11 23:14:33 +0000236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 basic_ostream() {} // extension, intentially does not initialize
238};
239
240template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000241class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242{
243 bool __ok_;
244 basic_ostream<_CharT, _Traits>& __os_;
245
246 sentry(const sentry&); // = delete;
247 sentry& operator=(const sentry&); // = delete;
248
249public:
250 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
251 ~sentry();
252
Louis Dionne16fe2952018-07-11 23:14:33 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +0000254 _LIBCPP_EXPLICIT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 operator bool() const {return __ok_;}
256};
257
258template <class _CharT, class _Traits>
259basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
260 : __ok_(false),
261 __os_(__os)
262{
263 if (__os.good())
264 {
265 if (__os.tie())
266 __os.tie()->flush();
267 __ok_ = true;
268 }
269}
270
271template <class _CharT, class _Traits>
272basic_ostream<_CharT, _Traits>::sentry::~sentry()
273{
274 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
275 && !uncaught_exception())
276 {
277#ifndef _LIBCPP_NO_EXCEPTIONS
278 try
279 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000280#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 if (__os_.rdbuf()->pubsync() == -1)
282 __os_.setstate(ios_base::badbit);
283#ifndef _LIBCPP_NO_EXCEPTIONS
284 }
285 catch (...)
286 {
287 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000288#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 }
290}
291
Eric Fiselier78ccf772017-04-18 23:38:41 +0000292#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293
294template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
296{
297 this->move(__rhs);
298}
299
300template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301basic_ostream<_CharT, _Traits>&
302basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
303{
304 swap(__rhs);
305 return *this;
306}
307
Eric Fiselier78ccf772017-04-18 23:38:41 +0000308#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309
310template <class _CharT, class _Traits>
311basic_ostream<_CharT, _Traits>::~basic_ostream()
312{
313}
314
315template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316basic_ostream<_CharT, _Traits>&
317basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
318{
319#ifndef _LIBCPP_NO_EXCEPTIONS
320 try
321 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000322#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 sentry __s(*this);
324 if (__s)
325 {
326 if (__sb)
327 {
328#ifndef _LIBCPP_NO_EXCEPTIONS
329 try
330 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000331#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc834c512011-11-29 18:15:50 +0000332 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
333 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
334 _Ip __i(__sb);
335 _Ip __eof;
336 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337 size_t __c = 0;
338 for (; __i != __eof; ++__i, ++__o, ++__c)
339 {
340 *__o = *__i;
341 if (__o.failed())
342 break;
343 }
344 if (__c == 0)
345 this->setstate(ios_base::failbit);
346#ifndef _LIBCPP_NO_EXCEPTIONS
347 }
348 catch (...)
349 {
350 this->__set_failbit_and_consider_rethrow();
351 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000352#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353 }
354 else
355 this->setstate(ios_base::badbit);
356 }
357#ifndef _LIBCPP_NO_EXCEPTIONS
358 }
359 catch (...)
360 {
361 this->__set_badbit_and_consider_rethrow();
362 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000363#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 return *this;
365}
366
367template <class _CharT, class _Traits>
368basic_ostream<_CharT, _Traits>&
369basic_ostream<_CharT, _Traits>::operator<<(bool __n)
370{
371#ifndef _LIBCPP_NO_EXCEPTIONS
372 try
373 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000374#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 sentry __s(*this);
376 if (__s)
377 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000378 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
379 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380 if (__f.put(*this, *this, this->fill(), __n).failed())
381 this->setstate(ios_base::badbit | ios_base::failbit);
382 }
383#ifndef _LIBCPP_NO_EXCEPTIONS
384 }
385 catch (...)
386 {
387 this->__set_badbit_and_consider_rethrow();
388 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000389#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 return *this;
391}
392
393template <class _CharT, class _Traits>
394basic_ostream<_CharT, _Traits>&
395basic_ostream<_CharT, _Traits>::operator<<(short __n)
396{
397#ifndef _LIBCPP_NO_EXCEPTIONS
398 try
399 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000400#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 sentry __s(*this);
402 if (__s)
403 {
404 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000405 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
406 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 if (__f.put(*this, *this, this->fill(),
408 __flags == ios_base::oct || __flags == ios_base::hex ?
409 static_cast<long>(static_cast<unsigned short>(__n)) :
410 static_cast<long>(__n)).failed())
411 this->setstate(ios_base::badbit | ios_base::failbit);
412 }
413#ifndef _LIBCPP_NO_EXCEPTIONS
414 }
415 catch (...)
416 {
417 this->__set_badbit_and_consider_rethrow();
418 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000419#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 return *this;
421}
422
423template <class _CharT, class _Traits>
424basic_ostream<_CharT, _Traits>&
425basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
426{
427#ifndef _LIBCPP_NO_EXCEPTIONS
428 try
429 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000430#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431 sentry __s(*this);
432 if (__s)
433 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000434 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
435 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
437 this->setstate(ios_base::badbit | ios_base::failbit);
438 }
439#ifndef _LIBCPP_NO_EXCEPTIONS
440 }
441 catch (...)
442 {
443 this->__set_badbit_and_consider_rethrow();
444 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000445#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 return *this;
447}
448
449template <class _CharT, class _Traits>
450basic_ostream<_CharT, _Traits>&
451basic_ostream<_CharT, _Traits>::operator<<(int __n)
452{
453#ifndef _LIBCPP_NO_EXCEPTIONS
454 try
455 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000456#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457 sentry __s(*this);
458 if (__s)
459 {
460 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000461 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
462 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463 if (__f.put(*this, *this, this->fill(),
464 __flags == ios_base::oct || __flags == ios_base::hex ?
465 static_cast<long>(static_cast<unsigned int>(__n)) :
466 static_cast<long>(__n)).failed())
467 this->setstate(ios_base::badbit | ios_base::failbit);
468 }
469#ifndef _LIBCPP_NO_EXCEPTIONS
470 }
471 catch (...)
472 {
473 this->__set_badbit_and_consider_rethrow();
474 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000475#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 return *this;
477}
478
479template <class _CharT, class _Traits>
480basic_ostream<_CharT, _Traits>&
481basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
482{
483#ifndef _LIBCPP_NO_EXCEPTIONS
484 try
485 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000486#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 sentry __s(*this);
488 if (__s)
489 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000490 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
491 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
493 this->setstate(ios_base::badbit | ios_base::failbit);
494 }
495#ifndef _LIBCPP_NO_EXCEPTIONS
496 }
497 catch (...)
498 {
499 this->__set_badbit_and_consider_rethrow();
500 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000501#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 return *this;
503}
504
505template <class _CharT, class _Traits>
506basic_ostream<_CharT, _Traits>&
507basic_ostream<_CharT, _Traits>::operator<<(long __n)
508{
509#ifndef _LIBCPP_NO_EXCEPTIONS
510 try
511 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000512#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 sentry __s(*this);
514 if (__s)
515 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000516 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
517 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 if (__f.put(*this, *this, this->fill(), __n).failed())
519 this->setstate(ios_base::badbit | ios_base::failbit);
520 }
521#ifndef _LIBCPP_NO_EXCEPTIONS
522 }
523 catch (...)
524 {
525 this->__set_badbit_and_consider_rethrow();
526 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000527#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 return *this;
529}
530
531template <class _CharT, class _Traits>
532basic_ostream<_CharT, _Traits>&
533basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
534{
535#ifndef _LIBCPP_NO_EXCEPTIONS
536 try
537 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000538#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539 sentry __s(*this);
540 if (__s)
541 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000542 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
543 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 if (__f.put(*this, *this, this->fill(), __n).failed())
545 this->setstate(ios_base::badbit | ios_base::failbit);
546 }
547#ifndef _LIBCPP_NO_EXCEPTIONS
548 }
549 catch (...)
550 {
551 this->__set_badbit_and_consider_rethrow();
552 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000553#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 return *this;
555}
556
557template <class _CharT, class _Traits>
558basic_ostream<_CharT, _Traits>&
559basic_ostream<_CharT, _Traits>::operator<<(long long __n)
560{
561#ifndef _LIBCPP_NO_EXCEPTIONS
562 try
563 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000564#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 sentry __s(*this);
566 if (__s)
567 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000568 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
569 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 if (__f.put(*this, *this, this->fill(), __n).failed())
571 this->setstate(ios_base::badbit | ios_base::failbit);
572 }
573#ifndef _LIBCPP_NO_EXCEPTIONS
574 }
575 catch (...)
576 {
577 this->__set_badbit_and_consider_rethrow();
578 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000579#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 return *this;
581}
582
583template <class _CharT, class _Traits>
584basic_ostream<_CharT, _Traits>&
585basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
586{
587#ifndef _LIBCPP_NO_EXCEPTIONS
588 try
589 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000590#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 sentry __s(*this);
592 if (__s)
593 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000594 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
595 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596 if (__f.put(*this, *this, this->fill(), __n).failed())
597 this->setstate(ios_base::badbit | ios_base::failbit);
598 }
599#ifndef _LIBCPP_NO_EXCEPTIONS
600 }
601 catch (...)
602 {
603 this->__set_badbit_and_consider_rethrow();
604 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000605#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 return *this;
607}
608
609template <class _CharT, class _Traits>
610basic_ostream<_CharT, _Traits>&
611basic_ostream<_CharT, _Traits>::operator<<(float __n)
612{
613#ifndef _LIBCPP_NO_EXCEPTIONS
614 try
615 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000616#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 sentry __s(*this);
618 if (__s)
619 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000620 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
621 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
623 this->setstate(ios_base::badbit | ios_base::failbit);
624 }
625#ifndef _LIBCPP_NO_EXCEPTIONS
626 }
627 catch (...)
628 {
629 this->__set_badbit_and_consider_rethrow();
630 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000631#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 return *this;
633}
634
635template <class _CharT, class _Traits>
636basic_ostream<_CharT, _Traits>&
637basic_ostream<_CharT, _Traits>::operator<<(double __n)
638{
639#ifndef _LIBCPP_NO_EXCEPTIONS
640 try
641 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000642#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 sentry __s(*this);
644 if (__s)
645 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000646 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
647 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 if (__f.put(*this, *this, this->fill(), __n).failed())
649 this->setstate(ios_base::badbit | ios_base::failbit);
650 }
651#ifndef _LIBCPP_NO_EXCEPTIONS
652 }
653 catch (...)
654 {
655 this->__set_badbit_and_consider_rethrow();
656 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000657#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 return *this;
659}
660
661template <class _CharT, class _Traits>
662basic_ostream<_CharT, _Traits>&
663basic_ostream<_CharT, _Traits>::operator<<(long double __n)
664{
665#ifndef _LIBCPP_NO_EXCEPTIONS
666 try
667 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000668#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 sentry __s(*this);
670 if (__s)
671 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000672 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
673 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 if (__f.put(*this, *this, this->fill(), __n).failed())
675 this->setstate(ios_base::badbit | ios_base::failbit);
676 }
677#ifndef _LIBCPP_NO_EXCEPTIONS
678 }
679 catch (...)
680 {
681 this->__set_badbit_and_consider_rethrow();
682 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000683#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684 return *this;
685}
686
687template <class _CharT, class _Traits>
688basic_ostream<_CharT, _Traits>&
689basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
690{
691#ifndef _LIBCPP_NO_EXCEPTIONS
692 try
693 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000694#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 sentry __s(*this);
696 if (__s)
697 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000698 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
699 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700 if (__f.put(*this, *this, this->fill(), __n).failed())
701 this->setstate(ios_base::badbit | ios_base::failbit);
702 }
703#ifndef _LIBCPP_NO_EXCEPTIONS
704 }
705 catch (...)
706 {
707 this->__set_badbit_and_consider_rethrow();
708 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000709#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710 return *this;
711}
712
713template<class _CharT, class _Traits>
714basic_ostream<_CharT, _Traits>&
Marshall Clow00995642013-12-10 19:25:49 +0000715__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
716 const _CharT* __str, size_t __len)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717{
718#ifndef _LIBCPP_NO_EXCEPTIONS
719 try
720 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000721#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
723 if (__s)
724 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000725 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
726 if (__pad_and_output(_Ip(__os),
Marshall Clow00995642013-12-10 19:25:49 +0000727 __str,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow00995642013-12-10 19:25:49 +0000729 __str + __len :
730 __str,
731 __str + __len,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 __os,
733 __os.fill()).failed())
734 __os.setstate(ios_base::badbit | ios_base::failbit);
735 }
736#ifndef _LIBCPP_NO_EXCEPTIONS
737 }
738 catch (...)
739 {
740 __os.__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 __os;
744}
745
Volodymyr Sapsai4c14a922018-09-19 23:31:34 +0000746
Marshall Clow00995642013-12-10 19:25:49 +0000747template<class _CharT, class _Traits>
748basic_ostream<_CharT, _Traits>&
749operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
750{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000751 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow00995642013-12-10 19:25:49 +0000752}
753
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754template<class _CharT, class _Traits>
755basic_ostream<_CharT, _Traits>&
756operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
757{
758#ifndef _LIBCPP_NO_EXCEPTIONS
759 try
760 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000761#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
763 if (__s)
764 {
765 _CharT __c = __os.widen(__cn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000766 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
767 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768 &__c,
769 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
770 &__c + 1 :
771 &__c,
772 &__c + 1,
773 __os,
774 __os.fill()).failed())
775 __os.setstate(ios_base::badbit | ios_base::failbit);
776 }
777#ifndef _LIBCPP_NO_EXCEPTIONS
778 }
779 catch (...)
780 {
781 __os.__set_badbit_and_consider_rethrow();
782 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000783#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784 return __os;
785}
786
787template<class _Traits>
788basic_ostream<char, _Traits>&
789operator<<(basic_ostream<char, _Traits>& __os, char __c)
790{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000791 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792}
793
794template<class _Traits>
795basic_ostream<char, _Traits>&
796operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
797{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000798 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799}
800
801template<class _Traits>
802basic_ostream<char, _Traits>&
803operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
804{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000805 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806}
807
808template<class _CharT, class _Traits>
809basic_ostream<_CharT, _Traits>&
810operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
811{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000812 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000813}
814
815template<class _CharT, class _Traits>
816basic_ostream<_CharT, _Traits>&
817operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
818{
819#ifndef _LIBCPP_NO_EXCEPTIONS
820 try
821 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000822#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
824 if (__s)
825 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000826 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827 size_t __len = char_traits<char>::length(__strn);
828 const int __bs = 100;
829 _CharT __wbb[__bs];
830 _CharT* __wb = __wbb;
831 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
832 if (__len > __bs)
833 {
834 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
835 if (__wb == 0)
836 __throw_bad_alloc();
837 __h.reset(__wb);
838 }
839 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
840 *__p = __os.widen(*__strn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000841 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842 __wb,
843 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
844 __wb + __len :
845 __wb,
846 __wb + __len,
847 __os,
848 __os.fill()).failed())
849 __os.setstate(ios_base::badbit | ios_base::failbit);
850 }
851#ifndef _LIBCPP_NO_EXCEPTIONS
852 }
853 catch (...)
854 {
855 __os.__set_badbit_and_consider_rethrow();
856 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000857#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858 return __os;
859}
860
861template<class _Traits>
862basic_ostream<char, _Traits>&
863operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
864{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000865 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866}
867
868template<class _Traits>
869basic_ostream<char, _Traits>&
870operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
871{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000872 const char *__s = (const char *) __str;
873 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874}
875
876template<class _Traits>
877basic_ostream<char, _Traits>&
878operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
879{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000880 const char *__s = (const char *) __str;
881 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882}
883
884template <class _CharT, class _Traits>
885basic_ostream<_CharT, _Traits>&
886basic_ostream<_CharT, _Traits>::put(char_type __c)
887{
888#ifndef _LIBCPP_NO_EXCEPTIONS
889 try
890 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000891#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892 sentry __s(*this);
893 if (__s)
894 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000895 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
896 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 *__o = __c;
898 if (__o.failed())
899 this->setstate(ios_base::badbit);
900 }
901#ifndef _LIBCPP_NO_EXCEPTIONS
902 }
903 catch (...)
904 {
905 this->__set_badbit_and_consider_rethrow();
906 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000907#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 return *this;
909}
910
911template <class _CharT, class _Traits>
912basic_ostream<_CharT, _Traits>&
913basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
914{
915#ifndef _LIBCPP_NO_EXCEPTIONS
916 try
917 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000918#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919 sentry __sen(*this);
920 if (__sen && __n)
921 {
Howard Hinnant79cef932013-01-15 17:22:03 +0000922 if (this->rdbuf()->sputn(__s, __n) != __n)
923 this->setstate(ios_base::badbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 }
925#ifndef _LIBCPP_NO_EXCEPTIONS
926 }
927 catch (...)
928 {
929 this->__set_badbit_and_consider_rethrow();
930 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000931#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 return *this;
933}
934
935template <class _CharT, class _Traits>
936basic_ostream<_CharT, _Traits>&
937basic_ostream<_CharT, _Traits>::flush()
938{
939#ifndef _LIBCPP_NO_EXCEPTIONS
940 try
941 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000942#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943 if (this->rdbuf())
944 {
945 sentry __s(*this);
946 if (__s)
947 {
948 if (this->rdbuf()->pubsync() == -1)
949 this->setstate(ios_base::badbit);
950 }
951 }
952#ifndef _LIBCPP_NO_EXCEPTIONS
953 }
954 catch (...)
955 {
956 this->__set_badbit_and_consider_rethrow();
957 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000958#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 return *this;
960}
961
962template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000963typename basic_ostream<_CharT, _Traits>::pos_type
964basic_ostream<_CharT, _Traits>::tellp()
965{
966 if (this->fail())
967 return pos_type(-1);
968 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
969}
970
971template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972basic_ostream<_CharT, _Traits>&
973basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
974{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000975 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000976 if (!this->fail())
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 {
978 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
979 this->setstate(ios_base::failbit);
980 }
981 return *this;
982}
983
984template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985basic_ostream<_CharT, _Traits>&
986basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
987{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000988 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000989 if (!this->fail())
Marshall Clow29c4daa2013-10-31 22:20:45 +0000990 {
991 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
992 this->setstate(ios_base::failbit);
993 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 return *this;
995}
996
997template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +0000998inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999basic_ostream<_CharT, _Traits>&
1000endl(basic_ostream<_CharT, _Traits>& __os)
1001{
1002 __os.put(__os.widen('\n'));
1003 __os.flush();
1004 return __os;
1005}
1006
1007template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001008inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009basic_ostream<_CharT, _Traits>&
1010ends(basic_ostream<_CharT, _Traits>& __os)
1011{
1012 __os.put(_CharT());
1013 return __os;
1014}
1015
1016template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001017inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018basic_ostream<_CharT, _Traits>&
1019flush(basic_ostream<_CharT, _Traits>& __os)
1020{
1021 __os.flush();
1022 return __os;
1023}
1024
Eric Fiselier78ccf772017-04-18 23:38:41 +00001025#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026
1027template <class _Stream, class _Tp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001028inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029typename enable_if
1030<
1031 !is_lvalue_reference<_Stream>::value &&
1032 is_base_of<ios_base, _Stream>::value,
Howard Hinnantc8697b62012-01-12 23:37:51 +00001033 _Stream&&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034>::type
1035operator<<(_Stream&& __os, const _Tp& __x)
1036{
1037 __os << __x;
Howard Hinnantc8697b62012-01-12 23:37:51 +00001038 return _VSTD::move(__os);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039}
1040
Eric Fiselier78ccf772017-04-18 23:38:41 +00001041#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042
1043template<class _CharT, class _Traits, class _Allocator>
1044basic_ostream<_CharT, _Traits>&
1045operator<<(basic_ostream<_CharT, _Traits>& __os,
1046 const basic_string<_CharT, _Traits, _Allocator>& __str)
1047{
Marshall Clow4bc2be22014-02-16 01:57:26 +00001048 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049}
1050
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001051template<class _CharT, class _Traits>
1052basic_ostream<_CharT, _Traits>&
1053operator<<(basic_ostream<_CharT, _Traits>& __os,
1054 const basic_string_view<_CharT, _Traits> __sv)
1055{
1056 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1057}
1058
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001060inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061basic_ostream<_CharT, _Traits>&
1062operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1063{
1064 return __os << __ec.category().name() << ':' << __ec.value();
1065}
1066
Howard Hinnantc834c512011-11-29 18:15:50 +00001067template<class _CharT, class _Traits, class _Yp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001070operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071{
1072 return __os << __p.get();
1073}
1074
Marshall Clowe52a3242017-11-27 15:51:36 +00001075template<class _CharT, class _Traits, class _Yp, class _Dp>
1076inline _LIBCPP_INLINE_VISIBILITY
1077typename enable_if
1078<
Marshall Cloweea0a1d2018-03-22 18:27:28 +00001079 is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value,
Marshall Clowe52a3242017-11-27 15:51:36 +00001080 basic_ostream<_CharT, _Traits>&
1081>::type
1082operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1083{
1084 return __os << __p.get();
1085}
1086
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087template <class _CharT, class _Traits, size_t _Size>
1088basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001089operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090{
1091 return __os << __x.template to_string<_CharT, _Traits>
1092 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1093 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1094}
1095
Louis Dionne207a9102018-12-06 00:24:58 +00001096#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
Eric Fiselier1b57fa82016-09-15 22:27:07 +00001097_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1098_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
Mehdi Amini228053d2017-05-04 17:08:54 +00001099#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100
1101_LIBCPP_END_NAMESPACE_STD
1102
1103#endif // _LIBCPP_OSTREAM