blob: efeaee253eb9791c1d35b611c346f187d57b7e9b [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- ostream -----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_OSTREAM
11#define _LIBCPP_OSTREAM
12
13/*
14 ostream synopsis
15
16template <class charT, class traits = char_traits<charT> >
17class basic_ostream
18 : virtual public basic_ios<charT,traits>
19{
20public:
21 // types (inherited from basic_ios (27.5.4)):
22 typedef charT char_type;
23 typedef traits traits_type;
24 typedef typename traits_type::int_type int_type;
25 typedef typename traits_type::pos_type pos_type;
26 typedef typename traits_type::off_type off_type;
27
28 // 27.7.2.2 Constructor/destructor:
29 explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
30 basic_ostream(basic_ostream&& rhs);
31 virtual ~basic_ostream();
32
33 // 27.7.2.3 Assign/swap
Marshall Clowe9ca0272013-08-14 15:15:28 +000034 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000035 basic_ostream& operator=(basic_ostream&& rhs);
36 void swap(basic_ostream& rhs);
37
38 // 27.7.2.4 Prefix/suffix:
39 class sentry;
40
41 // 27.7.2.6 Formatted output:
42 basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
43 basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
44 basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
45 basic_ostream& operator<<(bool n);
46 basic_ostream& operator<<(short n);
47 basic_ostream& operator<<(unsigned short n);
48 basic_ostream& operator<<(int n);
49 basic_ostream& operator<<(unsigned int n);
50 basic_ostream& operator<<(long n);
51 basic_ostream& operator<<(unsigned long n);
52 basic_ostream& operator<<(long long n);
53 basic_ostream& operator<<(unsigned long long n);
54 basic_ostream& operator<<(float f);
55 basic_ostream& operator<<(double f);
56 basic_ostream& operator<<(long double f);
57 basic_ostream& operator<<(const void* p);
58 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
Marshall Clow706862d2019-07-01 16:20:25 +000059 basic_ostream& operator<<(nullptr_t);
Howard Hinnantc51e1022010-05-11 19:42:16 +000060
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
Louis Dionned9f73b12020-09-23 08:49:00 -0400129template <class Stream, class T>
130 Stream&& operator<<(Stream&& os, const T& x);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131
132} // std
133
134*/
135
136#include <__config>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137#include <bitset>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400138#include <ios>
139#include <iterator>
140#include <locale>
141#include <streambuf>
Marshall Clow8732fed2018-12-11 04:35:44 +0000142#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000144#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000146#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
148_LIBCPP_BEGIN_NAMESPACE_STD
149
150template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000151class _LIBCPP_TEMPLATE_VIS basic_ostream
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152 : virtual public basic_ios<_CharT, _Traits>
153{
154public:
155 // types (inherited from basic_ios (27.5.4)):
156 typedef _CharT char_type;
157 typedef _Traits traits_type;
158 typedef typename traits_type::int_type int_type;
159 typedef typename traits_type::pos_type pos_type;
160 typedef typename traits_type::off_type off_type;
161
162 // 27.7.2.2 Constructor/destructor:
Louis Dionneb4d05d72018-10-16 19:26:23 +0000163 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000164 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
165 { this->init(__sb); }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 virtual ~basic_ostream();
167protected:
Eric Fiselier815ed732016-09-16 00:00:48 +0000168 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169 basic_ostream(basic_ostream&& __rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170
171 // 27.7.2.3 Assign/swap
Eric Fiselier815ed732016-09-16 00:00:48 +0000172 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173 basic_ostream& operator=(basic_ostream&& __rhs);
Arthur O'Dwyer8dcd2982021-06-15 12:47:05 -0400174
Louis Dionneb4d05d72018-10-16 19:26:23 +0000175 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000176 void swap(basic_ostream& __rhs)
177 { basic_ios<char_type, traits_type>::swap(__rhs); }
Marshall Clow27d29872014-09-16 15:27:01 +0000178
Marshall Clow242d9c12014-09-16 15:33:53 +0000179 basic_ostream (const basic_ostream& __rhs) = delete;
180 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181
Arthur O'Dwyer8dcd2982021-06-15 12:47:05 -0400182public:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000183 // 27.7.2.4 Prefix/suffix:
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000184 class _LIBCPP_TEMPLATE_VIS sentry;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185
186 // 27.7.2.6 Formatted output:
Louis Dionneb4d05d72018-10-16 19:26:23 +0000187 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000188 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
189 { return __pf(*this); }
190
Louis Dionneb4d05d72018-10-16 19:26:23 +0000191 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
Eric Fiselier815ed732016-09-16 00:00:48 +0000193 (*__pf)(basic_ios<char_type,traits_type>&))
194 { __pf(*this); return *this; }
195
Louis Dionneb4d05d72018-10-16 19:26:23 +0000196 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Eric Fiselier815ed732016-09-16 00:00:48 +0000197 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
198 { __pf(*this); return *this; }
199
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200 basic_ostream& operator<<(bool __n);
201 basic_ostream& operator<<(short __n);
202 basic_ostream& operator<<(unsigned short __n);
203 basic_ostream& operator<<(int __n);
204 basic_ostream& operator<<(unsigned int __n);
205 basic_ostream& operator<<(long __n);
206 basic_ostream& operator<<(unsigned long __n);
207 basic_ostream& operator<<(long long __n);
208 basic_ostream& operator<<(unsigned long long __n);
209 basic_ostream& operator<<(float __f);
210 basic_ostream& operator<<(double __f);
211 basic_ostream& operator<<(long double __f);
212 basic_ostream& operator<<(const void* __p);
213 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
214
Marshall Clow706862d2019-07-01 16:20:25 +0000215 _LIBCPP_INLINE_VISIBILITY
216 basic_ostream& operator<<(nullptr_t)
217 { return *this << "nullptr"; }
218
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 // 27.7.2.7 Unformatted output:
220 basic_ostream& put(char_type __c);
221 basic_ostream& write(const char_type* __s, streamsize __n);
222 basic_ostream& flush();
223
224 // 27.7.2.5 seeks:
Louis Dionneb4d05d72018-10-16 19:26:23 +0000225 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226 pos_type tellp();
Louis Dionneb4d05d72018-10-16 19:26:23 +0000227 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228 basic_ostream& seekp(pos_type __pos);
Louis Dionneb4d05d72018-10-16 19:26:23 +0000229 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
231
232protected:
Louis Dionne16fe2952018-07-11 23:14:33 +0000233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234 basic_ostream() {} // extension, intentially does not initialize
235};
236
237template <class _CharT, class _Traits>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000238class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239{
240 bool __ok_;
241 basic_ostream<_CharT, _Traits>& __os_;
242
243 sentry(const sentry&); // = delete;
244 sentry& operator=(const sentry&); // = delete;
245
246public:
247 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
248 ~sentry();
249
Louis Dionne16fe2952018-07-11 23:14:33 +0000250 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer6c9c9a72021-06-15 12:57:54 -0400251 explicit operator bool() const {return __ok_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252};
253
254template <class _CharT, class _Traits>
255basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
256 : __ok_(false),
257 __os_(__os)
258{
259 if (__os.good())
260 {
261 if (__os.tie())
262 __os.tie()->flush();
263 __ok_ = true;
264 }
265}
266
267template <class _CharT, class _Traits>
268basic_ostream<_CharT, _Traits>::sentry::~sentry()
269{
270 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
271 && !uncaught_exception())
272 {
273#ifndef _LIBCPP_NO_EXCEPTIONS
274 try
275 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400276#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277 if (__os_.rdbuf()->pubsync() == -1)
278 __os_.setstate(ios_base::badbit);
279#ifndef _LIBCPP_NO_EXCEPTIONS
280 }
281 catch (...)
282 {
283 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400284#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285 }
286}
287
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
290{
291 this->move(__rhs);
292}
293
294template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295basic_ostream<_CharT, _Traits>&
296basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
297{
298 swap(__rhs);
299 return *this;
300}
301
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302template <class _CharT, class _Traits>
303basic_ostream<_CharT, _Traits>::~basic_ostream()
304{
305}
306
307template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308basic_ostream<_CharT, _Traits>&
309basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
310{
311#ifndef _LIBCPP_NO_EXCEPTIONS
312 try
313 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400314#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 sentry __s(*this);
316 if (__s)
317 {
318 if (__sb)
319 {
320#ifndef _LIBCPP_NO_EXCEPTIONS
321 try
322 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400323#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc834c512011-11-29 18:15:50 +0000324 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
325 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
326 _Ip __i(__sb);
327 _Ip __eof;
328 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 size_t __c = 0;
330 for (; __i != __eof; ++__i, ++__o, ++__c)
331 {
332 *__o = *__i;
333 if (__o.failed())
334 break;
335 }
336 if (__c == 0)
337 this->setstate(ios_base::failbit);
338#ifndef _LIBCPP_NO_EXCEPTIONS
339 }
340 catch (...)
341 {
342 this->__set_failbit_and_consider_rethrow();
343 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400344#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345 }
346 else
347 this->setstate(ios_base::badbit);
348 }
349#ifndef _LIBCPP_NO_EXCEPTIONS
350 }
351 catch (...)
352 {
353 this->__set_badbit_and_consider_rethrow();
354 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400355#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 return *this;
357}
358
359template <class _CharT, class _Traits>
360basic_ostream<_CharT, _Traits>&
361basic_ostream<_CharT, _Traits>::operator<<(bool __n)
362{
363#ifndef _LIBCPP_NO_EXCEPTIONS
364 try
365 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400366#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 sentry __s(*this);
368 if (__s)
369 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000370 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
371 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372 if (__f.put(*this, *this, this->fill(), __n).failed())
373 this->setstate(ios_base::badbit | ios_base::failbit);
374 }
375#ifndef _LIBCPP_NO_EXCEPTIONS
376 }
377 catch (...)
378 {
379 this->__set_badbit_and_consider_rethrow();
380 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400381#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 return *this;
383}
384
385template <class _CharT, class _Traits>
386basic_ostream<_CharT, _Traits>&
387basic_ostream<_CharT, _Traits>::operator<<(short __n)
388{
389#ifndef _LIBCPP_NO_EXCEPTIONS
390 try
391 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400392#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 sentry __s(*this);
394 if (__s)
395 {
396 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000397 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
398 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 if (__f.put(*this, *this, this->fill(),
400 __flags == ios_base::oct || __flags == ios_base::hex ?
401 static_cast<long>(static_cast<unsigned short>(__n)) :
402 static_cast<long>(__n)).failed())
403 this->setstate(ios_base::badbit | ios_base::failbit);
404 }
405#ifndef _LIBCPP_NO_EXCEPTIONS
406 }
407 catch (...)
408 {
409 this->__set_badbit_and_consider_rethrow();
410 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400411#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 return *this;
413}
414
415template <class _CharT, class _Traits>
416basic_ostream<_CharT, _Traits>&
417basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
418{
419#ifndef _LIBCPP_NO_EXCEPTIONS
420 try
421 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400422#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423 sentry __s(*this);
424 if (__s)
425 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000426 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
427 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
429 this->setstate(ios_base::badbit | ios_base::failbit);
430 }
431#ifndef _LIBCPP_NO_EXCEPTIONS
432 }
433 catch (...)
434 {
435 this->__set_badbit_and_consider_rethrow();
436 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400437#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438 return *this;
439}
440
441template <class _CharT, class _Traits>
442basic_ostream<_CharT, _Traits>&
443basic_ostream<_CharT, _Traits>::operator<<(int __n)
444{
445#ifndef _LIBCPP_NO_EXCEPTIONS
446 try
447 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400448#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 sentry __s(*this);
450 if (__s)
451 {
452 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
Howard Hinnantc834c512011-11-29 18:15:50 +0000453 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
454 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455 if (__f.put(*this, *this, this->fill(),
456 __flags == ios_base::oct || __flags == ios_base::hex ?
457 static_cast<long>(static_cast<unsigned int>(__n)) :
458 static_cast<long>(__n)).failed())
459 this->setstate(ios_base::badbit | ios_base::failbit);
460 }
461#ifndef _LIBCPP_NO_EXCEPTIONS
462 }
463 catch (...)
464 {
465 this->__set_badbit_and_consider_rethrow();
466 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400467#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 return *this;
469}
470
471template <class _CharT, class _Traits>
472basic_ostream<_CharT, _Traits>&
473basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
474{
475#ifndef _LIBCPP_NO_EXCEPTIONS
476 try
477 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400478#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479 sentry __s(*this);
480 if (__s)
481 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000482 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
483 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
485 this->setstate(ios_base::badbit | ios_base::failbit);
486 }
487#ifndef _LIBCPP_NO_EXCEPTIONS
488 }
489 catch (...)
490 {
491 this->__set_badbit_and_consider_rethrow();
492 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400493#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494 return *this;
495}
496
497template <class _CharT, class _Traits>
498basic_ostream<_CharT, _Traits>&
499basic_ostream<_CharT, _Traits>::operator<<(long __n)
500{
501#ifndef _LIBCPP_NO_EXCEPTIONS
502 try
503 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400504#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 sentry __s(*this);
506 if (__s)
507 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000508 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
509 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 if (__f.put(*this, *this, this->fill(), __n).failed())
511 this->setstate(ios_base::badbit | ios_base::failbit);
512 }
513#ifndef _LIBCPP_NO_EXCEPTIONS
514 }
515 catch (...)
516 {
517 this->__set_badbit_and_consider_rethrow();
518 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400519#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 return *this;
521}
522
523template <class _CharT, class _Traits>
524basic_ostream<_CharT, _Traits>&
525basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
526{
527#ifndef _LIBCPP_NO_EXCEPTIONS
528 try
529 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400530#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531 sentry __s(*this);
532 if (__s)
533 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000534 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
535 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536 if (__f.put(*this, *this, this->fill(), __n).failed())
537 this->setstate(ios_base::badbit | ios_base::failbit);
538 }
539#ifndef _LIBCPP_NO_EXCEPTIONS
540 }
541 catch (...)
542 {
543 this->__set_badbit_and_consider_rethrow();
544 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400545#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 return *this;
547}
548
549template <class _CharT, class _Traits>
550basic_ostream<_CharT, _Traits>&
551basic_ostream<_CharT, _Traits>::operator<<(long long __n)
552{
553#ifndef _LIBCPP_NO_EXCEPTIONS
554 try
555 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400556#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 sentry __s(*this);
558 if (__s)
559 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000560 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
561 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 if (__f.put(*this, *this, this->fill(), __n).failed())
563 this->setstate(ios_base::badbit | ios_base::failbit);
564 }
565#ifndef _LIBCPP_NO_EXCEPTIONS
566 }
567 catch (...)
568 {
569 this->__set_badbit_and_consider_rethrow();
570 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400571#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572 return *this;
573}
574
575template <class _CharT, class _Traits>
576basic_ostream<_CharT, _Traits>&
577basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
578{
579#ifndef _LIBCPP_NO_EXCEPTIONS
580 try
581 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400582#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 sentry __s(*this);
584 if (__s)
585 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000586 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
587 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 if (__f.put(*this, *this, this->fill(), __n).failed())
589 this->setstate(ios_base::badbit | ios_base::failbit);
590 }
591#ifndef _LIBCPP_NO_EXCEPTIONS
592 }
593 catch (...)
594 {
595 this->__set_badbit_and_consider_rethrow();
596 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400597#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 return *this;
599}
600
601template <class _CharT, class _Traits>
602basic_ostream<_CharT, _Traits>&
603basic_ostream<_CharT, _Traits>::operator<<(float __n)
604{
605#ifndef _LIBCPP_NO_EXCEPTIONS
606 try
607 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400608#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609 sentry __s(*this);
610 if (__s)
611 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000612 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
613 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
615 this->setstate(ios_base::badbit | ios_base::failbit);
616 }
617#ifndef _LIBCPP_NO_EXCEPTIONS
618 }
619 catch (...)
620 {
621 this->__set_badbit_and_consider_rethrow();
622 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400623#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624 return *this;
625}
626
627template <class _CharT, class _Traits>
628basic_ostream<_CharT, _Traits>&
629basic_ostream<_CharT, _Traits>::operator<<(double __n)
630{
631#ifndef _LIBCPP_NO_EXCEPTIONS
632 try
633 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400634#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635 sentry __s(*this);
636 if (__s)
637 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000638 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
639 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640 if (__f.put(*this, *this, this->fill(), __n).failed())
641 this->setstate(ios_base::badbit | ios_base::failbit);
642 }
643#ifndef _LIBCPP_NO_EXCEPTIONS
644 }
645 catch (...)
646 {
647 this->__set_badbit_and_consider_rethrow();
648 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400649#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 return *this;
651}
652
653template <class _CharT, class _Traits>
654basic_ostream<_CharT, _Traits>&
655basic_ostream<_CharT, _Traits>::operator<<(long double __n)
656{
657#ifndef _LIBCPP_NO_EXCEPTIONS
658 try
659 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400660#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 sentry __s(*this);
662 if (__s)
663 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000664 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
665 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 if (__f.put(*this, *this, this->fill(), __n).failed())
667 this->setstate(ios_base::badbit | ios_base::failbit);
668 }
669#ifndef _LIBCPP_NO_EXCEPTIONS
670 }
671 catch (...)
672 {
673 this->__set_badbit_and_consider_rethrow();
674 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400675#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676 return *this;
677}
678
679template <class _CharT, class _Traits>
680basic_ostream<_CharT, _Traits>&
681basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
682{
683#ifndef _LIBCPP_NO_EXCEPTIONS
684 try
685 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400686#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687 sentry __s(*this);
688 if (__s)
689 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000690 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
691 const _Fp& __f = use_facet<_Fp>(this->getloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 if (__f.put(*this, *this, this->fill(), __n).failed())
693 this->setstate(ios_base::badbit | ios_base::failbit);
694 }
695#ifndef _LIBCPP_NO_EXCEPTIONS
696 }
697 catch (...)
698 {
699 this->__set_badbit_and_consider_rethrow();
700 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400701#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 return *this;
703}
704
705template<class _CharT, class _Traits>
706basic_ostream<_CharT, _Traits>&
Marshall Clow00995642013-12-10 19:25:49 +0000707__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
708 const _CharT* __str, size_t __len)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709{
710#ifndef _LIBCPP_NO_EXCEPTIONS
711 try
712 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400713#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
715 if (__s)
716 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000717 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
718 if (__pad_and_output(_Ip(__os),
Marshall Clow00995642013-12-10 19:25:49 +0000719 __str,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
Marshall Clow00995642013-12-10 19:25:49 +0000721 __str + __len :
722 __str,
723 __str + __len,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 __os,
725 __os.fill()).failed())
726 __os.setstate(ios_base::badbit | ios_base::failbit);
727 }
728#ifndef _LIBCPP_NO_EXCEPTIONS
729 }
730 catch (...)
731 {
732 __os.__set_badbit_and_consider_rethrow();
733 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400734#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 return __os;
736}
737
Volodymyr Sapsai4c14a922018-09-19 23:31:34 +0000738
Marshall Clow00995642013-12-10 19:25:49 +0000739template<class _CharT, class _Traits>
740basic_ostream<_CharT, _Traits>&
741operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
742{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000743 return _VSTD::__put_character_sequence(__os, &__c, 1);
Marshall Clow00995642013-12-10 19:25:49 +0000744}
745
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746template<class _CharT, class _Traits>
747basic_ostream<_CharT, _Traits>&
748operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
749{
750#ifndef _LIBCPP_NO_EXCEPTIONS
751 try
752 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400753#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
755 if (__s)
756 {
757 _CharT __c = __os.widen(__cn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000758 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
759 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 &__c,
761 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
762 &__c + 1 :
763 &__c,
764 &__c + 1,
765 __os,
766 __os.fill()).failed())
767 __os.setstate(ios_base::badbit | ios_base::failbit);
768 }
769#ifndef _LIBCPP_NO_EXCEPTIONS
770 }
771 catch (...)
772 {
773 __os.__set_badbit_and_consider_rethrow();
774 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400775#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 return __os;
777}
778
779template<class _Traits>
780basic_ostream<char, _Traits>&
781operator<<(basic_ostream<char, _Traits>& __os, char __c)
782{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000783 return _VSTD::__put_character_sequence(__os, &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784}
785
786template<class _Traits>
787basic_ostream<char, _Traits>&
788operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
789{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000790 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791}
792
793template<class _Traits>
794basic_ostream<char, _Traits>&
795operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
796{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000797 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798}
799
800template<class _CharT, class _Traits>
801basic_ostream<_CharT, _Traits>&
802operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
803{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000804 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805}
806
807template<class _CharT, class _Traits>
808basic_ostream<_CharT, _Traits>&
809operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
810{
811#ifndef _LIBCPP_NO_EXCEPTIONS
812 try
813 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400814#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
816 if (__s)
817 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000818 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 size_t __len = char_traits<char>::length(__strn);
820 const int __bs = 100;
821 _CharT __wbb[__bs];
822 _CharT* __wb = __wbb;
823 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
824 if (__len > __bs)
825 {
826 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
827 if (__wb == 0)
828 __throw_bad_alloc();
829 __h.reset(__wb);
830 }
831 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
832 *__p = __os.widen(*__strn);
Howard Hinnantc834c512011-11-29 18:15:50 +0000833 if (__pad_and_output(_Ip(__os),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 __wb,
835 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
836 __wb + __len :
837 __wb,
838 __wb + __len,
839 __os,
840 __os.fill()).failed())
841 __os.setstate(ios_base::badbit | ios_base::failbit);
842 }
843#ifndef _LIBCPP_NO_EXCEPTIONS
844 }
845 catch (...)
846 {
847 __os.__set_badbit_and_consider_rethrow();
848 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400849#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 return __os;
851}
852
853template<class _Traits>
854basic_ostream<char, _Traits>&
855operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
856{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000857 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858}
859
860template<class _Traits>
861basic_ostream<char, _Traits>&
862operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
863{
Marshall Clow4bc2be22014-02-16 01:57:26 +0000864 const char *__s = (const char *) __str;
865 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866}
867
868template<class _Traits>
869basic_ostream<char, _Traits>&
870operator<<(basic_ostream<char, _Traits>& __os, const unsigned 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 _CharT, class _Traits>
877basic_ostream<_CharT, _Traits>&
878basic_ostream<_CharT, _Traits>::put(char_type __c)
879{
880#ifndef _LIBCPP_NO_EXCEPTIONS
881 try
882 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400883#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 sentry __s(*this);
885 if (__s)
886 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000887 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
888 _Op __o(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 *__o = __c;
890 if (__o.failed())
891 this->setstate(ios_base::badbit);
892 }
893#ifndef _LIBCPP_NO_EXCEPTIONS
894 }
895 catch (...)
896 {
897 this->__set_badbit_and_consider_rethrow();
898 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400899#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900 return *this;
901}
902
903template <class _CharT, class _Traits>
904basic_ostream<_CharT, _Traits>&
905basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
906{
907#ifndef _LIBCPP_NO_EXCEPTIONS
908 try
909 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400910#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 sentry __sen(*this);
912 if (__sen && __n)
913 {
Howard Hinnant79cef932013-01-15 17:22:03 +0000914 if (this->rdbuf()->sputn(__s, __n) != __n)
915 this->setstate(ios_base::badbit);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 }
917#ifndef _LIBCPP_NO_EXCEPTIONS
918 }
919 catch (...)
920 {
921 this->__set_badbit_and_consider_rethrow();
922 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400923#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924 return *this;
925}
926
927template <class _CharT, class _Traits>
928basic_ostream<_CharT, _Traits>&
929basic_ostream<_CharT, _Traits>::flush()
930{
931#ifndef _LIBCPP_NO_EXCEPTIONS
932 try
933 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400934#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935 if (this->rdbuf())
936 {
937 sentry __s(*this);
938 if (__s)
939 {
940 if (this->rdbuf()->pubsync() == -1)
941 this->setstate(ios_base::badbit);
942 }
943 }
944#ifndef _LIBCPP_NO_EXCEPTIONS
945 }
946 catch (...)
947 {
948 this->__set_badbit_and_consider_rethrow();
949 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400950#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951 return *this;
952}
953
954template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955typename basic_ostream<_CharT, _Traits>::pos_type
956basic_ostream<_CharT, _Traits>::tellp()
957{
958 if (this->fail())
959 return pos_type(-1);
960 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
961}
962
963template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964basic_ostream<_CharT, _Traits>&
965basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
966{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000967 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000968 if (!this->fail())
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969 {
970 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
971 this->setstate(ios_base::failbit);
972 }
973 return *this;
974}
975
976template <class _CharT, class _Traits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977basic_ostream<_CharT, _Traits>&
978basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
979{
Marshall Clow29c4daa2013-10-31 22:20:45 +0000980 sentry __s(*this);
Marshall Clow8aa079a2015-06-22 15:01:21 +0000981 if (!this->fail())
Marshall Clow29c4daa2013-10-31 22:20:45 +0000982 {
983 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
984 this->setstate(ios_base::failbit);
985 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 return *this;
987}
988
989template <class _CharT, class _Traits>
Louis Dionnee29136f2020-07-13 11:53:48 -0400990inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991basic_ostream<_CharT, _Traits>&
992endl(basic_ostream<_CharT, _Traits>& __os)
993{
994 __os.put(__os.widen('\n'));
995 __os.flush();
996 return __os;
997}
998
999template <class _CharT, class _Traits>
Louis Dionnee29136f2020-07-13 11:53:48 -04001000inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001basic_ostream<_CharT, _Traits>&
1002ends(basic_ostream<_CharT, _Traits>& __os)
1003{
1004 __os.put(_CharT());
1005 return __os;
1006}
1007
1008template <class _CharT, class _Traits>
Louis Dionnee29136f2020-07-13 11:53:48 -04001009inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010basic_ostream<_CharT, _Traits>&
1011flush(basic_ostream<_CharT, _Traits>& __os)
1012{
1013 __os.flush();
1014 return __os;
1015}
1016
Louis Dionned9f73b12020-09-23 08:49:00 -04001017template <class _Stream, class _Tp, class = void>
1018struct __is_ostreamable : false_type { };
1019
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020template <class _Stream, class _Tp>
Louis Dionned9f73b12020-09-23 08:49:00 -04001021struct __is_ostreamable<_Stream, _Tp, decltype(
Arthur O'Dwyer3285c342021-05-10 13:04:16 -04001022 declval<_Stream>() << declval<_Tp>(), void()
Louis Dionned9f73b12020-09-23 08:49:00 -04001023)> : true_type { };
1024
1025template <class _Stream, class _Tp, class = typename enable_if<
1026 _And<is_base_of<ios_base, _Stream>,
Arthur O'Dwyer46d358c2021-06-15 12:57:05 -04001027 __is_ostreamable<_Stream&, const _Tp&> >::value
Louis Dionned9f73b12020-09-23 08:49:00 -04001028>::type>
1029_LIBCPP_INLINE_VISIBILITY
1030_Stream&& operator<<(_Stream&& __os, const _Tp& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031{
1032 __os << __x;
Howard Hinnantc8697b62012-01-12 23:37:51 +00001033 return _VSTD::move(__os);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034}
1035
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036template<class _CharT, class _Traits, class _Allocator>
1037basic_ostream<_CharT, _Traits>&
1038operator<<(basic_ostream<_CharT, _Traits>& __os,
1039 const basic_string<_CharT, _Traits, _Allocator>& __str)
1040{
Marshall Clow4bc2be22014-02-16 01:57:26 +00001041 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042}
1043
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001044template<class _CharT, class _Traits>
1045basic_ostream<_CharT, _Traits>&
1046operator<<(basic_ostream<_CharT, _Traits>& __os,
Eric Fiselier14116922019-09-25 18:56:54 +00001047 basic_string_view<_CharT, _Traits> __sv)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001048{
1049 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1050}
1051
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052template <class _CharT, class _Traits>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001053inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054basic_ostream<_CharT, _Traits>&
1055operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1056{
1057 return __os << __ec.category().name() << ':' << __ec.value();
1058}
1059
Howard Hinnantc834c512011-11-29 18:15:50 +00001060template<class _CharT, class _Traits, class _Yp>
Evgeniy Stepanovb9254262016-01-08 19:21:02 +00001061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001063operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064{
1065 return __os << __p.get();
1066}
1067
Marshall Clowe52a3242017-11-27 15:51:36 +00001068template<class _CharT, class _Traits, class _Yp, class _Dp>
1069inline _LIBCPP_INLINE_VISIBILITY
1070typename enable_if
1071<
Marshall Cloweea0a1d2018-03-22 18:27:28 +00001072 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 +00001073 basic_ostream<_CharT, _Traits>&
1074>::type
1075operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1076{
1077 return __os << __p.get();
1078}
1079
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080template <class _CharT, class _Traits, size_t _Size>
1081basic_ostream<_CharT, _Traits>&
Howard Hinnantfa65ab62011-04-05 14:55:28 +00001082operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083{
1084 return __os << __x.template to_string<_CharT, _Traits>
1085 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1086 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1087}
1088
Eric Fiselier1b57fa82016-09-15 22:27:07 +00001089_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1090_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091
1092_LIBCPP_END_NAMESPACE_STD
1093
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001094#endif // _LIBCPP_OSTREAM