blob: c29157077b489c1593bcd8122c81a238a4f30d56 [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);
Marshall Clowa873cff2018-09-19 18:29:57 +000059 basic_ostream<charT, traits>& operator<<(nullptr_t); // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
61
62 // 27.7.2.7 Unformatted output:
63 basic_ostream& put(char_type c);
64 basic_ostream& write(const char_type* s, streamsize n);
65 basic_ostream& flush();
66
67 // 27.7.2.5 seeks:
68 pos_type tellp();
69 basic_ostream& seekp(pos_type);
70 basic_ostream& seekp(off_type, ios_base::seekdir);
Marshall Clow27d29872014-09-16 15:27:01 +000071protected:
72 basic_ostream(const basic_ostream& rhs) = delete;
73 basic_ostream(basic_ostream&& rhs);
74 // 27.7.3.3 Assign/swap
75 basic_ostream& operator=(basic_ostream& rhs) = delete;
76 basic_ostream& operator=(const basic_ostream&& rhs);
77 void swap(basic_ostream& rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +000078};
79
80// 27.7.2.6.4 character inserters
81
82template<class charT, class traits>
83 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
84
85template<class charT, class traits>
86 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
87
88template<class traits>
89 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
90
91// signed and unsigned
92
93template<class traits>
94 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
95
96template<class traits>
97 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
98
99// NTBS
100template<class charT, class traits>
101 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
102
103template<class charT, class traits>
104 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
105
106template<class traits>
107 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
108
109// signed and unsigned
110template<class traits>
111basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
112
113template<class traits>
114 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
115
116// swap:
117template <class charT, class traits>
118 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
119
120template <class charT, class traits>
121 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
122
123template <class charT, class traits>
124 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
125
126template <class charT, class traits>
127 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
128
129// rvalue stream insertion
130template <class charT, class traits, class T>
131 basic_ostream<charT, traits>&
132 operator<<(basic_ostream<charT, traits>&& os, const T& x);
133
134} // std
135
136*/
137
138#include <__config>
139#include <ios>
140#include <streambuf>
141#include <locale>
142#include <iterator>
143#include <bitset>
144
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:
Eric Fiselier815ed732016-09-16 00:00:48 +0000164 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
165 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
Eric Fiselier815ed732016-09-16 00:00:48 +0000177 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
178 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:
Eric Fiselier815ed732016-09-16 00:00:48 +0000194 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
195 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
196 { return __pf(*this); }
197
198 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
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
203 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
204 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);
Marshall Clowa873cff2018-09-19 18:29:57 +0000220 basic_ostream& operator<<(nullptr_t);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 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:
Louis Dionne16fe2952018-07-11 23:14:33 +0000237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238 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
Louis Dionne16fe2952018-07-11 23:14:33 +0000254 _LIBCPP_INLINE_VISIBILITY
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
Eric Fiselier78ccf772017-04-18 23:38:41 +0000293#ifndef _LIBCPP_CXX03_LANG
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
Eric Fiselier78ccf772017-04-18 23:38:41 +0000309#endif // _LIBCPP_CXX03_LANG
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
Marshall Clowa873cff2018-09-19 18:29:57 +0000714template <class _CharT, class _Traits>
715basic_ostream<_CharT, _Traits>&
716basic_ostream<_CharT, _Traits>::operator<<(nullptr_t)
717{
718 return *this << "(nullptr)";
719}
720
721
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722template<class _CharT, class _Traits>
723basic_ostream<_CharT, _Traits>&
Marshall Clow00995642013-12-10 19:25:49 +0000724__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
725 const _CharT* __str, size_t __len)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726{
727#ifndef _LIBCPP_NO_EXCEPTIONS
728 try
729 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000730#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
732 if (__s)
733 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000734 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
735 if (__pad_and_output(_Ip(__os),
Marshall Clow00995642013-12-10 19:25:49 +0000736 __str,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow00995642013-12-10 19:25:49 +0000738 __str + __len :
739 __str,
740 __str + __len,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 __os,
742 __os.fill()).failed())
743 __os.setstate(ios_base::badbit | ios_base::failbit);
744 }
745#ifndef _LIBCPP_NO_EXCEPTIONS
746 }
747 catch (...)
748 {
749 __os.__set_badbit_and_consider_rethrow();
750 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000751#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752 return __os;
753}
754
Marshall Clow00995642013-12-10 19:25:49 +0000755template<class _CharT, class _Traits>
756basic_ostream<_CharT, _Traits>&
757operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
758{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000759 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow00995642013-12-10 19:25:49 +0000760}
761
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762template<class _CharT, class _Traits>
763basic_ostream<_CharT, _Traits>&
764operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
765{
766#ifndef _LIBCPP_NO_EXCEPTIONS
767 try
768 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000769#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
771 if (__s)
772 {
773 _CharT __c = __os.widen(__cn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000774 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
775 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 &__c,
777 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
778 &__c + 1 :
779 &__c,
780 &__c + 1,
781 __os,
782 __os.fill()).failed())
783 __os.setstate(ios_base::badbit | ios_base::failbit);
784 }
785#ifndef _LIBCPP_NO_EXCEPTIONS
786 }
787 catch (...)
788 {
789 __os.__set_badbit_and_consider_rethrow();
790 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000791#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792 return __os;
793}
794
795template<class _Traits>
796basic_ostream<char, _Traits>&
797operator<<(basic_ostream<char, _Traits>& __os, char __c)
798{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000799 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800}
801
802template<class _Traits>
803basic_ostream<char, _Traits>&
804operator<<(basic_ostream<char, _Traits>& __os, signed 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 _Traits>
810basic_ostream<char, _Traits>&
811operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
812{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000813 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
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 _CharT* __str)
819{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000820 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821}
822
823template<class _CharT, class _Traits>
824basic_ostream<_CharT, _Traits>&
825operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
826{
827#ifndef _LIBCPP_NO_EXCEPTIONS
828 try
829 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000830#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
832 if (__s)
833 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000834 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 size_t __len = char_traits<char>::length(__strn);
836 const int __bs = 100;
837 _CharT __wbb[__bs];
838 _CharT* __wb = __wbb;
839 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
840 if (__len > __bs)
841 {
842 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
843 if (__wb == 0)
844 __throw_bad_alloc();
845 __h.reset(__wb);
846 }
847 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
848 *__p = __os.widen(*__strn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000849 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 __wb,
851 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
852 __wb + __len :
853 __wb,
854 __wb + __len,
855 __os,
856 __os.fill()).failed())
857 __os.setstate(ios_base::badbit | ios_base::failbit);
858 }
859#ifndef _LIBCPP_NO_EXCEPTIONS
860 }
861 catch (...)
862 {
863 __os.__set_badbit_and_consider_rethrow();
864 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000865#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 return __os;
867}
868
869template<class _Traits>
870basic_ostream<char, _Traits>&
871operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
872{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000873 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874}
875
876template<class _Traits>
877basic_ostream<char, _Traits>&
878operator<<(basic_ostream<char, _Traits>& __os, const signed 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 _Traits>
885basic_ostream<char, _Traits>&
886operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
887{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000888 const char *__s = (const char *) __str;
889 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890}
891
892template <class _CharT, class _Traits>
893basic_ostream<_CharT, _Traits>&
894basic_ostream<_CharT, _Traits>::put(char_type __c)
895{
896#ifndef _LIBCPP_NO_EXCEPTIONS
897 try
898 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000899#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 sentry __s(*this);
901 if (__s)
902 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000903 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
904 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 *__o = __c;
906 if (__o.failed())
907 this->setstate(ios_base::badbit);
908 }
909#ifndef _LIBCPP_NO_EXCEPTIONS
910 }
911 catch (...)
912 {
913 this->__set_badbit_and_consider_rethrow();
914 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000915#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 return *this;
917}
918
919template <class _CharT, class _Traits>
920basic_ostream<_CharT, _Traits>&
921basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
922{
923#ifndef _LIBCPP_NO_EXCEPTIONS
924 try
925 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000926#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927 sentry __sen(*this);
928 if (__sen && __n)
929 {
Howard Hinnant79cef932013-01-15 17:22:03 +0000930 if (this->rdbuf()->sputn(__s, __n) != __n)
931 this->setstate(ios_base::badbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 }
933#ifndef _LIBCPP_NO_EXCEPTIONS
934 }
935 catch (...)
936 {
937 this->__set_badbit_and_consider_rethrow();
938 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000939#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 return *this;
941}
942
943template <class _CharT, class _Traits>
944basic_ostream<_CharT, _Traits>&
945basic_ostream<_CharT, _Traits>::flush()
946{
947#ifndef _LIBCPP_NO_EXCEPTIONS
948 try
949 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000950#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951 if (this->rdbuf())
952 {
953 sentry __s(*this);
954 if (__s)
955 {
956 if (this->rdbuf()->pubsync() == -1)
957 this->setstate(ios_base::badbit);
958 }
959 }
960#ifndef _LIBCPP_NO_EXCEPTIONS
961 }
962 catch (...)
963 {
964 this->__set_badbit_and_consider_rethrow();
965 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000966#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000967 return *this;
968}
969
970template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971typename basic_ostream<_CharT, _Traits>::pos_type
972basic_ostream<_CharT, _Traits>::tellp()
973{
974 if (this->fail())
975 return pos_type(-1);
976 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
977}
978
979template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980basic_ostream<_CharT, _Traits>&
981basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
982{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000983 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000984 if (!this->fail())
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985 {
986 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
987 this->setstate(ios_base::failbit);
988 }
989 return *this;
990}
991
992template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993basic_ostream<_CharT, _Traits>&
994basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
995{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000996 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000997 if (!this->fail())
Marshall Clow29c4daa2013-10-31 22:20:45 +0000998 {
999 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
1000 this->setstate(ios_base::failbit);
1001 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 return *this;
1003}
1004
1005template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001006inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007basic_ostream<_CharT, _Traits>&
1008endl(basic_ostream<_CharT, _Traits>& __os)
1009{
1010 __os.put(__os.widen('\n'));
1011 __os.flush();
1012 return __os;
1013}
1014
1015template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017basic_ostream<_CharT, _Traits>&
1018ends(basic_ostream<_CharT, _Traits>& __os)
1019{
1020 __os.put(_CharT());
1021 return __os;
1022}
1023
1024template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026basic_ostream<_CharT, _Traits>&
1027flush(basic_ostream<_CharT, _Traits>& __os)
1028{
1029 __os.flush();
1030 return __os;
1031}
1032
Eric Fiselier78ccf772017-04-18 23:38:41 +00001033#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034
1035template <class _Stream, class _Tp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001036inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037typename enable_if
1038<
1039 !is_lvalue_reference<_Stream>::value &&
1040 is_base_of<ios_base, _Stream>::value,
Howard Hinnantc8697b62012-01-12 23:37:51 +00001041 _Stream&&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042>::type
1043operator<<(_Stream&& __os, const _Tp& __x)
1044{
1045 __os << __x;
Howard Hinnantc8697b62012-01-12 23:37:51 +00001046 return _VSTD::move(__os);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047}
1048
Eric Fiselier78ccf772017-04-18 23:38:41 +00001049#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050
1051template<class _CharT, class _Traits, class _Allocator>
1052basic_ostream<_CharT, _Traits>&
1053operator<<(basic_ostream<_CharT, _Traits>& __os,
1054 const basic_string<_CharT, _Traits, _Allocator>& __str)
1055{
Marshall Clow4bc2be22014-02-16 01:57:26 +00001056 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057}
1058
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001059template<class _CharT, class _Traits>
1060basic_ostream<_CharT, _Traits>&
1061operator<<(basic_ostream<_CharT, _Traits>& __os,
1062 const basic_string_view<_CharT, _Traits> __sv)
1063{
1064 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1065}
1066
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069basic_ostream<_CharT, _Traits>&
1070operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1071{
1072 return __os << __ec.category().name() << ':' << __ec.value();
1073}
1074
Howard Hinnantc834c512011-11-29 18:15:50 +00001075template<class _CharT, class _Traits, class _Yp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001076inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001078operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079{
1080 return __os << __p.get();
1081}
1082
Marshall Clowe52a3242017-11-27 15:51:36 +00001083template<class _CharT, class _Traits, class _Yp, class _Dp>
1084inline _LIBCPP_INLINE_VISIBILITY
1085typename enable_if
1086<
Marshall Cloweea0a1d2018-03-22 18:27:28 +00001087 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 +00001088 basic_ostream<_CharT, _Traits>&
1089>::type
1090operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1091{
1092 return __os << __p.get();
1093}
1094
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095template <class _CharT, class _Traits, size_t _Size>
1096basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001097operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098{
1099 return __os << __x.template to_string<_CharT, _Traits>
1100 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1101 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1102}
1103
Mehdi Amini228053d2017-05-04 17:08:54 +00001104#ifndef _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
Eric Fiselier1b57fa82016-09-15 22:27:07 +00001105_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1106_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
Mehdi Amini228053d2017-05-04 17:08:54 +00001107#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108
1109_LIBCPP_END_NAMESPACE_STD
1110
1111#endif // _LIBCPP_OSTREAM