2 //===-------------------------- ostream -----------------------------------===//
4 // 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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_OSTREAM
11 #define _LIBCPP_OSTREAM
16 template <class charT, class traits = char_traits<charT> >
18 : virtual public basic_ios<charT,traits>
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;
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();
33 // 27.7.2.3 Assign/swap
34 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
35 basic_ostream& operator=(basic_ostream&& rhs);
36 void swap(basic_ostream& rhs);
38 // 27.7.2.4 Prefix/suffix:
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);
59 basic_ostream& operator<<(nullptr_t);
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();
68 basic_ostream& seekp(pos_type);
69 basic_ostream& seekp(off_type, ios_base::seekdir);
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);
79 // 27.7.2.6.4 character inserters
81 template<class charT, class traits>
82 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
84 template<class charT, class traits>
85 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
87 template<class traits>
88 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
90 // signed and unsigned
92 template<class traits>
93 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
95 template<class traits>
96 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
99 template<class charT, class traits>
100 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
102 template<class charT, class traits>
103 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
105 template<class traits>
106 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
108 // signed and unsigned
109 template<class traits>
110 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
112 template<class traits>
113 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
116 template <class charT, class traits>
117 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
119 template <class charT, class traits>
120 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
122 template <class charT, class traits>
123 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
125 template <class charT, class traits>
126 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
128 // rvalue stream insertion
129 template <class Stream, class T>
130 Stream&& operator<<(Stream&& os, const T& x);
144 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
145 #pragma GCC system_header
148 _LIBCPP_BEGIN_NAMESPACE_STD
150 template <class _CharT, class _Traits>
151 class _LIBCPP_TEMPLATE_VIS basic_ostream
152 : virtual public basic_ios<_CharT, _Traits>
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;
162 // 27.7.2.2 Constructor/destructor:
163 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
164 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
165 { this->init(__sb); }
166 virtual ~basic_ostream();
168 inline _LIBCPP_INLINE_VISIBILITY
169 basic_ostream(basic_ostream&& __rhs);
171 // 27.7.2.3 Assign/swap
172 inline _LIBCPP_INLINE_VISIBILITY
173 basic_ostream& operator=(basic_ostream&& __rhs);
175 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
176 void swap(basic_ostream& __rhs)
177 { basic_ios<char_type, traits_type>::swap(__rhs); }
179 basic_ostream (const basic_ostream& __rhs) = delete;
180 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
183 // 27.7.2.4 Prefix/suffix:
184 class _LIBCPP_TEMPLATE_VIS sentry;
186 // 27.7.2.6 Formatted output:
187 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
188 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
189 { return __pf(*this); }
191 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
192 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
193 (*__pf)(basic_ios<char_type,traits_type>&))
194 { __pf(*this); return *this; }
196 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
197 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
198 { __pf(*this); return *this; }
200 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);
215 _LIBCPP_INLINE_VISIBILITY
216 basic_ostream& operator<<(nullptr_t)
217 { return *this << "nullptr"; }
219 // 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();
225 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
227 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
228 basic_ostream& seekp(pos_type __pos);
229 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
230 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
233 _LIBCPP_INLINE_VISIBILITY
234 basic_ostream() {} // extension, intentially does not initialize
237 template <class _CharT, class _Traits>
238 class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
241 basic_ostream<_CharT, _Traits>& __os_;
243 sentry(const sentry&); // = delete;
244 sentry& operator=(const sentry&); // = delete;
247 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
250 _LIBCPP_INLINE_VISIBILITY
251 explicit operator bool() const {return __ok_;}
254 template <class _CharT, class _Traits>
255 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
267 template <class _CharT, class _Traits>
268 basic_ostream<_CharT, _Traits>::sentry::~sentry()
270 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
271 && !uncaught_exception())
273 #ifndef _LIBCPP_NO_EXCEPTIONS
276 #endif // _LIBCPP_NO_EXCEPTIONS
277 if (__os_.rdbuf()->pubsync() == -1)
278 __os_.setstate(ios_base::badbit);
279 #ifndef _LIBCPP_NO_EXCEPTIONS
284 #endif // _LIBCPP_NO_EXCEPTIONS
288 template <class _CharT, class _Traits>
289 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
294 template <class _CharT, class _Traits>
295 basic_ostream<_CharT, _Traits>&
296 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
302 template <class _CharT, class _Traits>
303 basic_ostream<_CharT, _Traits>::~basic_ostream()
307 template <class _CharT, class _Traits>
308 basic_ostream<_CharT, _Traits>&
309 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
311 #ifndef _LIBCPP_NO_EXCEPTIONS
314 #endif // _LIBCPP_NO_EXCEPTIONS
320 #ifndef _LIBCPP_NO_EXCEPTIONS
323 #endif // _LIBCPP_NO_EXCEPTIONS
324 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
325 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
330 for (; __i != __eof; ++__i, ++__o, ++__c)
337 this->setstate(ios_base::failbit);
338 #ifndef _LIBCPP_NO_EXCEPTIONS
342 this->__set_failbit_and_consider_rethrow();
344 #endif // _LIBCPP_NO_EXCEPTIONS
347 this->setstate(ios_base::badbit);
349 #ifndef _LIBCPP_NO_EXCEPTIONS
353 this->__set_badbit_and_consider_rethrow();
355 #endif // _LIBCPP_NO_EXCEPTIONS
359 template <class _CharT, class _Traits>
360 basic_ostream<_CharT, _Traits>&
361 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
363 #ifndef _LIBCPP_NO_EXCEPTIONS
366 #endif // _LIBCPP_NO_EXCEPTIONS
370 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
371 const _Fp& __f = use_facet<_Fp>(this->getloc());
372 if (__f.put(*this, *this, this->fill(), __n).failed())
373 this->setstate(ios_base::badbit | ios_base::failbit);
375 #ifndef _LIBCPP_NO_EXCEPTIONS
379 this->__set_badbit_and_consider_rethrow();
381 #endif // _LIBCPP_NO_EXCEPTIONS
385 template <class _CharT, class _Traits>
386 basic_ostream<_CharT, _Traits>&
387 basic_ostream<_CharT, _Traits>::operator<<(short __n)
389 #ifndef _LIBCPP_NO_EXCEPTIONS
392 #endif // _LIBCPP_NO_EXCEPTIONS
396 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
397 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
398 const _Fp& __f = use_facet<_Fp>(this->getloc());
399 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);
405 #ifndef _LIBCPP_NO_EXCEPTIONS
409 this->__set_badbit_and_consider_rethrow();
411 #endif // _LIBCPP_NO_EXCEPTIONS
415 template <class _CharT, class _Traits>
416 basic_ostream<_CharT, _Traits>&
417 basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
419 #ifndef _LIBCPP_NO_EXCEPTIONS
422 #endif // _LIBCPP_NO_EXCEPTIONS
426 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
427 const _Fp& __f = use_facet<_Fp>(this->getloc());
428 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
429 this->setstate(ios_base::badbit | ios_base::failbit);
431 #ifndef _LIBCPP_NO_EXCEPTIONS
435 this->__set_badbit_and_consider_rethrow();
437 #endif // _LIBCPP_NO_EXCEPTIONS
441 template <class _CharT, class _Traits>
442 basic_ostream<_CharT, _Traits>&
443 basic_ostream<_CharT, _Traits>::operator<<(int __n)
445 #ifndef _LIBCPP_NO_EXCEPTIONS
448 #endif // _LIBCPP_NO_EXCEPTIONS
452 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
453 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
454 const _Fp& __f = use_facet<_Fp>(this->getloc());
455 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);
461 #ifndef _LIBCPP_NO_EXCEPTIONS
465 this->__set_badbit_and_consider_rethrow();
467 #endif // _LIBCPP_NO_EXCEPTIONS
471 template <class _CharT, class _Traits>
472 basic_ostream<_CharT, _Traits>&
473 basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
475 #ifndef _LIBCPP_NO_EXCEPTIONS
478 #endif // _LIBCPP_NO_EXCEPTIONS
482 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
483 const _Fp& __f = use_facet<_Fp>(this->getloc());
484 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
485 this->setstate(ios_base::badbit | ios_base::failbit);
487 #ifndef _LIBCPP_NO_EXCEPTIONS
491 this->__set_badbit_and_consider_rethrow();
493 #endif // _LIBCPP_NO_EXCEPTIONS
497 template <class _CharT, class _Traits>
498 basic_ostream<_CharT, _Traits>&
499 basic_ostream<_CharT, _Traits>::operator<<(long __n)
501 #ifndef _LIBCPP_NO_EXCEPTIONS
504 #endif // _LIBCPP_NO_EXCEPTIONS
508 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
509 const _Fp& __f = use_facet<_Fp>(this->getloc());
510 if (__f.put(*this, *this, this->fill(), __n).failed())
511 this->setstate(ios_base::badbit | ios_base::failbit);
513 #ifndef _LIBCPP_NO_EXCEPTIONS
517 this->__set_badbit_and_consider_rethrow();
519 #endif // _LIBCPP_NO_EXCEPTIONS
523 template <class _CharT, class _Traits>
524 basic_ostream<_CharT, _Traits>&
525 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
527 #ifndef _LIBCPP_NO_EXCEPTIONS
530 #endif // _LIBCPP_NO_EXCEPTIONS
534 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
535 const _Fp& __f = use_facet<_Fp>(this->getloc());
536 if (__f.put(*this, *this, this->fill(), __n).failed())
537 this->setstate(ios_base::badbit | ios_base::failbit);
539 #ifndef _LIBCPP_NO_EXCEPTIONS
543 this->__set_badbit_and_consider_rethrow();
545 #endif // _LIBCPP_NO_EXCEPTIONS
549 template <class _CharT, class _Traits>
550 basic_ostream<_CharT, _Traits>&
551 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
553 #ifndef _LIBCPP_NO_EXCEPTIONS
556 #endif // _LIBCPP_NO_EXCEPTIONS
560 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
561 const _Fp& __f = use_facet<_Fp>(this->getloc());
562 if (__f.put(*this, *this, this->fill(), __n).failed())
563 this->setstate(ios_base::badbit | ios_base::failbit);
565 #ifndef _LIBCPP_NO_EXCEPTIONS
569 this->__set_badbit_and_consider_rethrow();
571 #endif // _LIBCPP_NO_EXCEPTIONS
575 template <class _CharT, class _Traits>
576 basic_ostream<_CharT, _Traits>&
577 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
579 #ifndef _LIBCPP_NO_EXCEPTIONS
582 #endif // _LIBCPP_NO_EXCEPTIONS
586 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
587 const _Fp& __f = use_facet<_Fp>(this->getloc());
588 if (__f.put(*this, *this, this->fill(), __n).failed())
589 this->setstate(ios_base::badbit | ios_base::failbit);
591 #ifndef _LIBCPP_NO_EXCEPTIONS
595 this->__set_badbit_and_consider_rethrow();
597 #endif // _LIBCPP_NO_EXCEPTIONS
601 template <class _CharT, class _Traits>
602 basic_ostream<_CharT, _Traits>&
603 basic_ostream<_CharT, _Traits>::operator<<(float __n)
605 #ifndef _LIBCPP_NO_EXCEPTIONS
608 #endif // _LIBCPP_NO_EXCEPTIONS
612 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
613 const _Fp& __f = use_facet<_Fp>(this->getloc());
614 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
615 this->setstate(ios_base::badbit | ios_base::failbit);
617 #ifndef _LIBCPP_NO_EXCEPTIONS
621 this->__set_badbit_and_consider_rethrow();
623 #endif // _LIBCPP_NO_EXCEPTIONS
627 template <class _CharT, class _Traits>
628 basic_ostream<_CharT, _Traits>&
629 basic_ostream<_CharT, _Traits>::operator<<(double __n)
631 #ifndef _LIBCPP_NO_EXCEPTIONS
634 #endif // _LIBCPP_NO_EXCEPTIONS
638 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
639 const _Fp& __f = use_facet<_Fp>(this->getloc());
640 if (__f.put(*this, *this, this->fill(), __n).failed())
641 this->setstate(ios_base::badbit | ios_base::failbit);
643 #ifndef _LIBCPP_NO_EXCEPTIONS
647 this->__set_badbit_and_consider_rethrow();
649 #endif // _LIBCPP_NO_EXCEPTIONS
653 template <class _CharT, class _Traits>
654 basic_ostream<_CharT, _Traits>&
655 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
657 #ifndef _LIBCPP_NO_EXCEPTIONS
660 #endif // _LIBCPP_NO_EXCEPTIONS
664 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
665 const _Fp& __f = use_facet<_Fp>(this->getloc());
666 if (__f.put(*this, *this, this->fill(), __n).failed())
667 this->setstate(ios_base::badbit | ios_base::failbit);
669 #ifndef _LIBCPP_NO_EXCEPTIONS
673 this->__set_badbit_and_consider_rethrow();
675 #endif // _LIBCPP_NO_EXCEPTIONS
679 template <class _CharT, class _Traits>
680 basic_ostream<_CharT, _Traits>&
681 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
683 #ifndef _LIBCPP_NO_EXCEPTIONS
686 #endif // _LIBCPP_NO_EXCEPTIONS
690 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
691 const _Fp& __f = use_facet<_Fp>(this->getloc());
692 if (__f.put(*this, *this, this->fill(), __n).failed())
693 this->setstate(ios_base::badbit | ios_base::failbit);
695 #ifndef _LIBCPP_NO_EXCEPTIONS
699 this->__set_badbit_and_consider_rethrow();
701 #endif // _LIBCPP_NO_EXCEPTIONS
705 template<class _CharT, class _Traits>
706 basic_ostream<_CharT, _Traits>&
707 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
708 const _CharT* __str, size_t __len)
710 #ifndef _LIBCPP_NO_EXCEPTIONS
713 #endif // _LIBCPP_NO_EXCEPTIONS
714 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
717 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
718 if (__pad_and_output(_Ip(__os),
720 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
725 __os.fill()).failed())
726 __os.setstate(ios_base::badbit | ios_base::failbit);
728 #ifndef _LIBCPP_NO_EXCEPTIONS
732 __os.__set_badbit_and_consider_rethrow();
734 #endif // _LIBCPP_NO_EXCEPTIONS
739 template<class _CharT, class _Traits>
740 basic_ostream<_CharT, _Traits>&
741 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
743 return _VSTD::__put_character_sequence(__os, &__c, 1);
746 template<class _CharT, class _Traits>
747 basic_ostream<_CharT, _Traits>&
748 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
750 #ifndef _LIBCPP_NO_EXCEPTIONS
753 #endif // _LIBCPP_NO_EXCEPTIONS
754 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
757 _CharT __c = __os.widen(__cn);
758 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
759 if (__pad_and_output(_Ip(__os),
761 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
766 __os.fill()).failed())
767 __os.setstate(ios_base::badbit | ios_base::failbit);
769 #ifndef _LIBCPP_NO_EXCEPTIONS
773 __os.__set_badbit_and_consider_rethrow();
775 #endif // _LIBCPP_NO_EXCEPTIONS
779 template<class _Traits>
780 basic_ostream<char, _Traits>&
781 operator<<(basic_ostream<char, _Traits>& __os, char __c)
783 return _VSTD::__put_character_sequence(__os, &__c, 1);
786 template<class _Traits>
787 basic_ostream<char, _Traits>&
788 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
790 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
793 template<class _Traits>
794 basic_ostream<char, _Traits>&
795 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
797 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
800 template<class _CharT, class _Traits>
801 basic_ostream<_CharT, _Traits>&
802 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
804 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
807 template<class _CharT, class _Traits>
808 basic_ostream<_CharT, _Traits>&
809 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
811 #ifndef _LIBCPP_NO_EXCEPTIONS
814 #endif // _LIBCPP_NO_EXCEPTIONS
815 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
818 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
819 size_t __len = char_traits<char>::length(__strn);
820 const int __bs = 100;
822 _CharT* __wb = __wbb;
823 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
826 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
831 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
832 *__p = __os.widen(*__strn);
833 if (__pad_and_output(_Ip(__os),
835 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
840 __os.fill()).failed())
841 __os.setstate(ios_base::badbit | ios_base::failbit);
843 #ifndef _LIBCPP_NO_EXCEPTIONS
847 __os.__set_badbit_and_consider_rethrow();
849 #endif // _LIBCPP_NO_EXCEPTIONS
853 template<class _Traits>
854 basic_ostream<char, _Traits>&
855 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
857 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
860 template<class _Traits>
861 basic_ostream<char, _Traits>&
862 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
864 const char *__s = (const char *) __str;
865 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
868 template<class _Traits>
869 basic_ostream<char, _Traits>&
870 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
872 const char *__s = (const char *) __str;
873 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
876 template <class _CharT, class _Traits>
877 basic_ostream<_CharT, _Traits>&
878 basic_ostream<_CharT, _Traits>::put(char_type __c)
880 #ifndef _LIBCPP_NO_EXCEPTIONS
883 #endif // _LIBCPP_NO_EXCEPTIONS
887 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
891 this->setstate(ios_base::badbit);
893 #ifndef _LIBCPP_NO_EXCEPTIONS
897 this->__set_badbit_and_consider_rethrow();
899 #endif // _LIBCPP_NO_EXCEPTIONS
903 template <class _CharT, class _Traits>
904 basic_ostream<_CharT, _Traits>&
905 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
907 #ifndef _LIBCPP_NO_EXCEPTIONS
910 #endif // _LIBCPP_NO_EXCEPTIONS
914 if (this->rdbuf()->sputn(__s, __n) != __n)
915 this->setstate(ios_base::badbit);
917 #ifndef _LIBCPP_NO_EXCEPTIONS
921 this->__set_badbit_and_consider_rethrow();
923 #endif // _LIBCPP_NO_EXCEPTIONS
927 template <class _CharT, class _Traits>
928 basic_ostream<_CharT, _Traits>&
929 basic_ostream<_CharT, _Traits>::flush()
931 #ifndef _LIBCPP_NO_EXCEPTIONS
934 #endif // _LIBCPP_NO_EXCEPTIONS
940 if (this->rdbuf()->pubsync() == -1)
941 this->setstate(ios_base::badbit);
944 #ifndef _LIBCPP_NO_EXCEPTIONS
948 this->__set_badbit_and_consider_rethrow();
950 #endif // _LIBCPP_NO_EXCEPTIONS
954 template <class _CharT, class _Traits>
955 typename basic_ostream<_CharT, _Traits>::pos_type
956 basic_ostream<_CharT, _Traits>::tellp()
960 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
963 template <class _CharT, class _Traits>
964 basic_ostream<_CharT, _Traits>&
965 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
970 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
971 this->setstate(ios_base::failbit);
976 template <class _CharT, class _Traits>
977 basic_ostream<_CharT, _Traits>&
978 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
983 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
984 this->setstate(ios_base::failbit);
989 template <class _CharT, class _Traits>
991 basic_ostream<_CharT, _Traits>&
992 endl(basic_ostream<_CharT, _Traits>& __os)
994 __os.put(__os.widen('\n'));
999 template <class _CharT, class _Traits>
1001 basic_ostream<_CharT, _Traits>&
1002 ends(basic_ostream<_CharT, _Traits>& __os)
1008 template <class _CharT, class _Traits>
1010 basic_ostream<_CharT, _Traits>&
1011 flush(basic_ostream<_CharT, _Traits>& __os)
1017 template <class _Stream, class _Tp, class = void>
1018 struct __is_ostreamable : false_type { };
1020 template <class _Stream, class _Tp>
1021 struct __is_ostreamable<_Stream, _Tp, decltype(
1022 declval<_Stream>() << declval<_Tp>(), void()
1025 template <class _Stream, class _Tp, class = typename enable_if<
1026 _And<is_base_of<ios_base, _Stream>,
1027 __is_ostreamable<_Stream&, const _Tp&> >::value
1029 _LIBCPP_INLINE_VISIBILITY
1030 _Stream&& operator<<(_Stream&& __os, const _Tp& __x)
1033 return _VSTD::move(__os);
1036 template<class _CharT, class _Traits, class _Allocator>
1037 basic_ostream<_CharT, _Traits>&
1038 operator<<(basic_ostream<_CharT, _Traits>& __os,
1039 const basic_string<_CharT, _Traits, _Allocator>& __str)
1041 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
1044 template<class _CharT, class _Traits>
1045 basic_ostream<_CharT, _Traits>&
1046 operator<<(basic_ostream<_CharT, _Traits>& __os,
1047 basic_string_view<_CharT, _Traits> __sv)
1049 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1052 template <class _CharT, class _Traits>
1053 inline _LIBCPP_INLINE_VISIBILITY
1054 basic_ostream<_CharT, _Traits>&
1055 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1057 return __os << __ec.category().name() << ':' << __ec.value();
1060 template<class _CharT, class _Traits, class _Yp>
1061 inline _LIBCPP_INLINE_VISIBILITY
1062 basic_ostream<_CharT, _Traits>&
1063 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1065 return __os << __p.get();
1068 template<class _CharT, class _Traits, class _Yp, class _Dp>
1069 inline _LIBCPP_INLINE_VISIBILITY
1072 is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value,
1073 basic_ostream<_CharT, _Traits>&
1075 operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1077 return __os << __p.get();
1080 template <class _CharT, class _Traits, size_t _Size>
1081 basic_ostream<_CharT, _Traits>&
1082 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
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'));
1089 _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>)
1092 _LIBCPP_END_NAMESPACE_STD
1094 #endif // _LIBCPP_OSTREAM