2 //===-------------------------- ostream -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_OSTREAM
12 #define _LIBCPP_OSTREAM
17 template <class charT, class traits = char_traits<charT> >
19 : virtual public basic_ios<charT,traits>
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;
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();
34 // 27.7.2.3 Assign/swap
35 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
36 basic_ostream& operator=(basic_ostream&& rhs);
37 void swap(basic_ostream& rhs);
39 // 27.7.2.4 Prefix/suffix:
42 // 27.7.2.6 Formatted output:
43 basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
44 basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
45 basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
46 basic_ostream& operator<<(bool n);
47 basic_ostream& operator<<(short n);
48 basic_ostream& operator<<(unsigned short n);
49 basic_ostream& operator<<(int n);
50 basic_ostream& operator<<(unsigned int n);
51 basic_ostream& operator<<(long n);
52 basic_ostream& operator<<(unsigned long n);
53 basic_ostream& operator<<(long long n);
54 basic_ostream& operator<<(unsigned long long n);
55 basic_ostream& operator<<(float f);
56 basic_ostream& operator<<(double f);
57 basic_ostream& operator<<(long double f);
58 basic_ostream& operator<<(const void* p);
59 basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
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);
72 // 27.7.2.6.4 character inserters
74 template<class charT, class traits>
75 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
77 template<class charT, class traits>
78 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
80 template<class traits>
81 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
83 // signed and unsigned
85 template<class traits>
86 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
88 template<class traits>
89 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
92 template<class charT, class traits>
93 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
95 template<class charT, class traits>
96 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
98 template<class traits>
99 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
101 // signed and unsigned
102 template<class traits>
103 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
105 template<class traits>
106 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
109 template <class charT, class traits>
110 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
112 template <class charT, class traits>
113 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
115 template <class charT, class traits>
116 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
118 template <class charT, class traits>
119 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
121 // rvalue stream insertion
122 template <class charT, class traits, class T>
123 basic_ostream<charT, traits>&
124 operator<<(basic_ostream<charT, traits>&& os, const T& x);
137 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138 #pragma GCC system_header
141 _LIBCPP_BEGIN_NAMESPACE_STD
143 template <class _CharT, class _Traits>
144 class _LIBCPP_TYPE_VIS_ONLY basic_ostream
145 : virtual public basic_ios<_CharT, _Traits>
148 // types (inherited from basic_ios (27.5.4)):
149 typedef _CharT char_type;
150 typedef _Traits traits_type;
151 typedef typename traits_type::int_type int_type;
152 typedef typename traits_type::pos_type pos_type;
153 typedef typename traits_type::off_type off_type;
155 // 27.7.2.2 Constructor/destructor:
156 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
157 virtual ~basic_ostream();
159 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
160 _LIBCPP_INLINE_VISIBILITY
161 basic_ostream(basic_ostream&& __rhs);
164 // 27.7.2.3 Assign/swap
165 #if _LIBCPP_STD_VER > 11
166 basic_ostream& operator=(const basic_ostream&) = delete;
168 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
169 _LIBCPP_INLINE_VISIBILITY
170 basic_ostream& operator=(basic_ostream&& __rhs);
172 void swap(basic_ostream& __rhs);
175 // 27.7.2.4 Prefix/suffix:
176 class _LIBCPP_TYPE_VIS_ONLY sentry;
178 // 27.7.2.6 Formatted output:
179 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
180 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
181 (*__pf)(basic_ios<char_type,traits_type>&));
182 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
183 basic_ostream& operator<<(bool __n);
184 basic_ostream& operator<<(short __n);
185 basic_ostream& operator<<(unsigned short __n);
186 basic_ostream& operator<<(int __n);
187 basic_ostream& operator<<(unsigned int __n);
188 basic_ostream& operator<<(long __n);
189 basic_ostream& operator<<(unsigned long __n);
190 basic_ostream& operator<<(long long __n);
191 basic_ostream& operator<<(unsigned long long __n);
192 basic_ostream& operator<<(float __f);
193 basic_ostream& operator<<(double __f);
194 basic_ostream& operator<<(long double __f);
195 basic_ostream& operator<<(const void* __p);
196 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
198 // 27.7.2.7 Unformatted output:
199 basic_ostream& put(char_type __c);
200 basic_ostream& write(const char_type* __s, streamsize __n);
201 basic_ostream& flush();
205 basic_ostream& seekp(pos_type __pos);
206 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
209 _LIBCPP_ALWAYS_INLINE
210 basic_ostream() {} // extension, intentially does not initialize
213 template <class _CharT, class _Traits>
214 class _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry
217 basic_ostream<_CharT, _Traits>& __os_;
219 sentry(const sentry&); // = delete;
220 sentry& operator=(const sentry&); // = delete;
223 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
226 _LIBCPP_ALWAYS_INLINE
228 operator bool() const {return __ok_;}
231 template <class _CharT, class _Traits>
232 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
244 template <class _CharT, class _Traits>
245 basic_ostream<_CharT, _Traits>::sentry::~sentry()
247 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
248 && !uncaught_exception())
250 #ifndef _LIBCPP_NO_EXCEPTIONS
253 #endif // _LIBCPP_NO_EXCEPTIONS
254 if (__os_.rdbuf()->pubsync() == -1)
255 __os_.setstate(ios_base::badbit);
256 #ifndef _LIBCPP_NO_EXCEPTIONS
261 #endif // _LIBCPP_NO_EXCEPTIONS
265 template <class _CharT, class _Traits>
266 inline _LIBCPP_INLINE_VISIBILITY
267 basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
272 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
274 template <class _CharT, class _Traits>
275 inline _LIBCPP_INLINE_VISIBILITY
276 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
281 template <class _CharT, class _Traits>
282 inline _LIBCPP_INLINE_VISIBILITY
283 basic_ostream<_CharT, _Traits>&
284 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
290 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
292 template <class _CharT, class _Traits>
293 basic_ostream<_CharT, _Traits>::~basic_ostream()
297 template <class _CharT, class _Traits>
298 inline _LIBCPP_INLINE_VISIBILITY
300 basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
302 basic_ios<char_type, traits_type>::swap(__rhs);
305 template <class _CharT, class _Traits>
306 inline _LIBCPP_INLINE_VISIBILITY
307 basic_ostream<_CharT, _Traits>&
308 basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
313 template <class _CharT, class _Traits>
314 inline _LIBCPP_INLINE_VISIBILITY
315 basic_ostream<_CharT, _Traits>&
316 basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
317 (*__pf)(basic_ios<char_type,traits_type>&))
323 template <class _CharT, class _Traits>
324 inline _LIBCPP_INLINE_VISIBILITY
325 basic_ostream<_CharT, _Traits>&
326 basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
332 template <class _CharT, class _Traits>
333 basic_ostream<_CharT, _Traits>&
334 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
336 #ifndef _LIBCPP_NO_EXCEPTIONS
339 #endif // _LIBCPP_NO_EXCEPTIONS
345 #ifndef _LIBCPP_NO_EXCEPTIONS
348 #endif // _LIBCPP_NO_EXCEPTIONS
349 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
350 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
355 for (; __i != __eof; ++__i, ++__o, ++__c)
362 this->setstate(ios_base::failbit);
363 #ifndef _LIBCPP_NO_EXCEPTIONS
367 this->__set_failbit_and_consider_rethrow();
369 #endif // _LIBCPP_NO_EXCEPTIONS
372 this->setstate(ios_base::badbit);
374 #ifndef _LIBCPP_NO_EXCEPTIONS
378 this->__set_badbit_and_consider_rethrow();
380 #endif // _LIBCPP_NO_EXCEPTIONS
384 template <class _CharT, class _Traits>
385 basic_ostream<_CharT, _Traits>&
386 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
388 #ifndef _LIBCPP_NO_EXCEPTIONS
391 #endif // _LIBCPP_NO_EXCEPTIONS
395 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
396 const _Fp& __f = use_facet<_Fp>(this->getloc());
397 if (__f.put(*this, *this, this->fill(), __n).failed())
398 this->setstate(ios_base::badbit | ios_base::failbit);
400 #ifndef _LIBCPP_NO_EXCEPTIONS
404 this->__set_badbit_and_consider_rethrow();
406 #endif // _LIBCPP_NO_EXCEPTIONS
410 template <class _CharT, class _Traits>
411 basic_ostream<_CharT, _Traits>&
412 basic_ostream<_CharT, _Traits>::operator<<(short __n)
414 #ifndef _LIBCPP_NO_EXCEPTIONS
417 #endif // _LIBCPP_NO_EXCEPTIONS
421 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
422 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
423 const _Fp& __f = use_facet<_Fp>(this->getloc());
424 if (__f.put(*this, *this, this->fill(),
425 __flags == ios_base::oct || __flags == ios_base::hex ?
426 static_cast<long>(static_cast<unsigned short>(__n)) :
427 static_cast<long>(__n)).failed())
428 this->setstate(ios_base::badbit | ios_base::failbit);
430 #ifndef _LIBCPP_NO_EXCEPTIONS
434 this->__set_badbit_and_consider_rethrow();
436 #endif // _LIBCPP_NO_EXCEPTIONS
440 template <class _CharT, class _Traits>
441 basic_ostream<_CharT, _Traits>&
442 basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
444 #ifndef _LIBCPP_NO_EXCEPTIONS
447 #endif // _LIBCPP_NO_EXCEPTIONS
451 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
452 const _Fp& __f = use_facet<_Fp>(this->getloc());
453 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
454 this->setstate(ios_base::badbit | ios_base::failbit);
456 #ifndef _LIBCPP_NO_EXCEPTIONS
460 this->__set_badbit_and_consider_rethrow();
462 #endif // _LIBCPP_NO_EXCEPTIONS
466 template <class _CharT, class _Traits>
467 basic_ostream<_CharT, _Traits>&
468 basic_ostream<_CharT, _Traits>::operator<<(int __n)
470 #ifndef _LIBCPP_NO_EXCEPTIONS
473 #endif // _LIBCPP_NO_EXCEPTIONS
477 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
478 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
479 const _Fp& __f = use_facet<_Fp>(this->getloc());
480 if (__f.put(*this, *this, this->fill(),
481 __flags == ios_base::oct || __flags == ios_base::hex ?
482 static_cast<long>(static_cast<unsigned int>(__n)) :
483 static_cast<long>(__n)).failed())
484 this->setstate(ios_base::badbit | ios_base::failbit);
486 #ifndef _LIBCPP_NO_EXCEPTIONS
490 this->__set_badbit_and_consider_rethrow();
492 #endif // _LIBCPP_NO_EXCEPTIONS
496 template <class _CharT, class _Traits>
497 basic_ostream<_CharT, _Traits>&
498 basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
500 #ifndef _LIBCPP_NO_EXCEPTIONS
503 #endif // _LIBCPP_NO_EXCEPTIONS
507 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
508 const _Fp& __f = use_facet<_Fp>(this->getloc());
509 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
510 this->setstate(ios_base::badbit | ios_base::failbit);
512 #ifndef _LIBCPP_NO_EXCEPTIONS
516 this->__set_badbit_and_consider_rethrow();
518 #endif // _LIBCPP_NO_EXCEPTIONS
522 template <class _CharT, class _Traits>
523 basic_ostream<_CharT, _Traits>&
524 basic_ostream<_CharT, _Traits>::operator<<(long __n)
526 #ifndef _LIBCPP_NO_EXCEPTIONS
529 #endif // _LIBCPP_NO_EXCEPTIONS
533 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
534 const _Fp& __f = use_facet<_Fp>(this->getloc());
535 if (__f.put(*this, *this, this->fill(), __n).failed())
536 this->setstate(ios_base::badbit | ios_base::failbit);
538 #ifndef _LIBCPP_NO_EXCEPTIONS
542 this->__set_badbit_and_consider_rethrow();
544 #endif // _LIBCPP_NO_EXCEPTIONS
548 template <class _CharT, class _Traits>
549 basic_ostream<_CharT, _Traits>&
550 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
552 #ifndef _LIBCPP_NO_EXCEPTIONS
555 #endif // _LIBCPP_NO_EXCEPTIONS
559 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
560 const _Fp& __f = use_facet<_Fp>(this->getloc());
561 if (__f.put(*this, *this, this->fill(), __n).failed())
562 this->setstate(ios_base::badbit | ios_base::failbit);
564 #ifndef _LIBCPP_NO_EXCEPTIONS
568 this->__set_badbit_and_consider_rethrow();
570 #endif // _LIBCPP_NO_EXCEPTIONS
574 template <class _CharT, class _Traits>
575 basic_ostream<_CharT, _Traits>&
576 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
578 #ifndef _LIBCPP_NO_EXCEPTIONS
581 #endif // _LIBCPP_NO_EXCEPTIONS
585 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
586 const _Fp& __f = use_facet<_Fp>(this->getloc());
587 if (__f.put(*this, *this, this->fill(), __n).failed())
588 this->setstate(ios_base::badbit | ios_base::failbit);
590 #ifndef _LIBCPP_NO_EXCEPTIONS
594 this->__set_badbit_and_consider_rethrow();
596 #endif // _LIBCPP_NO_EXCEPTIONS
600 template <class _CharT, class _Traits>
601 basic_ostream<_CharT, _Traits>&
602 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
604 #ifndef _LIBCPP_NO_EXCEPTIONS
607 #endif // _LIBCPP_NO_EXCEPTIONS
611 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
612 const _Fp& __f = use_facet<_Fp>(this->getloc());
613 if (__f.put(*this, *this, this->fill(), __n).failed())
614 this->setstate(ios_base::badbit | ios_base::failbit);
616 #ifndef _LIBCPP_NO_EXCEPTIONS
620 this->__set_badbit_and_consider_rethrow();
622 #endif // _LIBCPP_NO_EXCEPTIONS
626 template <class _CharT, class _Traits>
627 basic_ostream<_CharT, _Traits>&
628 basic_ostream<_CharT, _Traits>::operator<<(float __n)
630 #ifndef _LIBCPP_NO_EXCEPTIONS
633 #endif // _LIBCPP_NO_EXCEPTIONS
637 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
638 const _Fp& __f = use_facet<_Fp>(this->getloc());
639 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
640 this->setstate(ios_base::badbit | ios_base::failbit);
642 #ifndef _LIBCPP_NO_EXCEPTIONS
646 this->__set_badbit_and_consider_rethrow();
648 #endif // _LIBCPP_NO_EXCEPTIONS
652 template <class _CharT, class _Traits>
653 basic_ostream<_CharT, _Traits>&
654 basic_ostream<_CharT, _Traits>::operator<<(double __n)
656 #ifndef _LIBCPP_NO_EXCEPTIONS
659 #endif // _LIBCPP_NO_EXCEPTIONS
663 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
664 const _Fp& __f = use_facet<_Fp>(this->getloc());
665 if (__f.put(*this, *this, this->fill(), __n).failed())
666 this->setstate(ios_base::badbit | ios_base::failbit);
668 #ifndef _LIBCPP_NO_EXCEPTIONS
672 this->__set_badbit_and_consider_rethrow();
674 #endif // _LIBCPP_NO_EXCEPTIONS
678 template <class _CharT, class _Traits>
679 basic_ostream<_CharT, _Traits>&
680 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
682 #ifndef _LIBCPP_NO_EXCEPTIONS
685 #endif // _LIBCPP_NO_EXCEPTIONS
689 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
690 const _Fp& __f = use_facet<_Fp>(this->getloc());
691 if (__f.put(*this, *this, this->fill(), __n).failed())
692 this->setstate(ios_base::badbit | ios_base::failbit);
694 #ifndef _LIBCPP_NO_EXCEPTIONS
698 this->__set_badbit_and_consider_rethrow();
700 #endif // _LIBCPP_NO_EXCEPTIONS
704 template <class _CharT, class _Traits>
705 basic_ostream<_CharT, _Traits>&
706 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
708 #ifndef _LIBCPP_NO_EXCEPTIONS
711 #endif // _LIBCPP_NO_EXCEPTIONS
715 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
716 const _Fp& __f = use_facet<_Fp>(this->getloc());
717 if (__f.put(*this, *this, this->fill(), __n).failed())
718 this->setstate(ios_base::badbit | ios_base::failbit);
720 #ifndef _LIBCPP_NO_EXCEPTIONS
724 this->__set_badbit_and_consider_rethrow();
726 #endif // _LIBCPP_NO_EXCEPTIONS
730 template<class _CharT, class _Traits>
731 basic_ostream<_CharT, _Traits>&
732 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
734 #ifndef _LIBCPP_NO_EXCEPTIONS
737 #endif // _LIBCPP_NO_EXCEPTIONS
738 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
741 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
742 if (__pad_and_output(_Ip(__os),
744 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
749 __os.fill()).failed())
750 __os.setstate(ios_base::badbit | ios_base::failbit);
752 #ifndef _LIBCPP_NO_EXCEPTIONS
756 __os.__set_badbit_and_consider_rethrow();
758 #endif // _LIBCPP_NO_EXCEPTIONS
762 template<class _CharT, class _Traits>
763 basic_ostream<_CharT, _Traits>&
764 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
766 #ifndef _LIBCPP_NO_EXCEPTIONS
769 #endif // _LIBCPP_NO_EXCEPTIONS
770 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
773 _CharT __c = __os.widen(__cn);
774 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
775 if (__pad_and_output(_Ip(__os),
777 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
782 __os.fill()).failed())
783 __os.setstate(ios_base::badbit | ios_base::failbit);
785 #ifndef _LIBCPP_NO_EXCEPTIONS
789 __os.__set_badbit_and_consider_rethrow();
791 #endif // _LIBCPP_NO_EXCEPTIONS
795 template<class _Traits>
796 basic_ostream<char, _Traits>&
797 operator<<(basic_ostream<char, _Traits>& __os, char __c)
799 #ifndef _LIBCPP_NO_EXCEPTIONS
802 #endif // _LIBCPP_NO_EXCEPTIONS
803 typename basic_ostream<char, _Traits>::sentry __s(__os);
806 typedef ostreambuf_iterator<char, _Traits> _Ip;
807 if (__pad_and_output(_Ip(__os),
809 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
814 __os.fill()).failed())
815 __os.setstate(ios_base::badbit | ios_base::failbit);
817 #ifndef _LIBCPP_NO_EXCEPTIONS
821 __os.__set_badbit_and_consider_rethrow();
823 #endif // _LIBCPP_NO_EXCEPTIONS
827 template<class _Traits>
828 basic_ostream<char, _Traits>&
829 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
831 #ifndef _LIBCPP_NO_EXCEPTIONS
834 #endif // _LIBCPP_NO_EXCEPTIONS
835 typename basic_ostream<char, _Traits>::sentry __s(__os);
838 typedef ostreambuf_iterator<char, _Traits> _Ip;
839 if (__pad_and_output(_Ip(__os),
841 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
846 __os.fill()).failed())
847 __os.setstate(ios_base::badbit | ios_base::failbit);
849 #ifndef _LIBCPP_NO_EXCEPTIONS
853 __os.__set_badbit_and_consider_rethrow();
855 #endif // _LIBCPP_NO_EXCEPTIONS
859 template<class _Traits>
860 basic_ostream<char, _Traits>&
861 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
863 #ifndef _LIBCPP_NO_EXCEPTIONS
866 #endif // _LIBCPP_NO_EXCEPTIONS
867 typename basic_ostream<char, _Traits>::sentry __s(__os);
870 typedef ostreambuf_iterator<char, _Traits> _Ip;
871 if (__pad_and_output(_Ip(__os),
873 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
878 __os.fill()).failed())
879 __os.setstate(ios_base::badbit | ios_base::failbit);
881 #ifndef _LIBCPP_NO_EXCEPTIONS
885 __os.__set_badbit_and_consider_rethrow();
887 #endif // _LIBCPP_NO_EXCEPTIONS
891 template<class _CharT, class _Traits>
892 basic_ostream<_CharT, _Traits>&
893 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
895 #ifndef _LIBCPP_NO_EXCEPTIONS
898 #endif // _LIBCPP_NO_EXCEPTIONS
899 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
902 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
903 size_t __len = _Traits::length(__str);
904 if (__pad_and_output(_Ip(__os),
906 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
911 __os.fill()).failed())
912 __os.setstate(ios_base::badbit | ios_base::failbit);
914 #ifndef _LIBCPP_NO_EXCEPTIONS
918 __os.__set_badbit_and_consider_rethrow();
920 #endif // _LIBCPP_NO_EXCEPTIONS
924 template<class _CharT, class _Traits>
925 basic_ostream<_CharT, _Traits>&
926 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
928 #ifndef _LIBCPP_NO_EXCEPTIONS
931 #endif // _LIBCPP_NO_EXCEPTIONS
932 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
935 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
936 size_t __len = char_traits<char>::length(__strn);
937 const int __bs = 100;
939 _CharT* __wb = __wbb;
940 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
943 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
948 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
949 *__p = __os.widen(*__strn);
950 if (__pad_and_output(_Ip(__os),
952 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
957 __os.fill()).failed())
958 __os.setstate(ios_base::badbit | ios_base::failbit);
960 #ifndef _LIBCPP_NO_EXCEPTIONS
964 __os.__set_badbit_and_consider_rethrow();
966 #endif // _LIBCPP_NO_EXCEPTIONS
970 template<class _Traits>
971 basic_ostream<char, _Traits>&
972 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
974 #ifndef _LIBCPP_NO_EXCEPTIONS
977 #endif // _LIBCPP_NO_EXCEPTIONS
978 typename basic_ostream<char, _Traits>::sentry __s(__os);
981 typedef ostreambuf_iterator<char, _Traits> _Ip;
982 size_t __len = _Traits::length(__str);
983 if (__pad_and_output(_Ip(__os),
985 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
990 __os.fill()).failed())
991 __os.setstate(ios_base::badbit | ios_base::failbit);
993 #ifndef _LIBCPP_NO_EXCEPTIONS
997 __os.__set_badbit_and_consider_rethrow();
999 #endif // _LIBCPP_NO_EXCEPTIONS
1003 template<class _Traits>
1004 basic_ostream<char, _Traits>&
1005 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
1007 #ifndef _LIBCPP_NO_EXCEPTIONS
1010 #endif // _LIBCPP_NO_EXCEPTIONS
1011 typename basic_ostream<char, _Traits>::sentry __s(__os);
1014 typedef ostreambuf_iterator<char, _Traits> _Ip;
1015 size_t __len = _Traits::length((const char*)__str);
1016 if (__pad_and_output(_Ip(__os),
1018 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1019 (const char*)__str + __len :
1021 (const char*)__str + __len,
1023 __os.fill()).failed())
1024 __os.setstate(ios_base::badbit | ios_base::failbit);
1026 #ifndef _LIBCPP_NO_EXCEPTIONS
1030 __os.__set_badbit_and_consider_rethrow();
1032 #endif // _LIBCPP_NO_EXCEPTIONS
1036 template<class _Traits>
1037 basic_ostream<char, _Traits>&
1038 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
1040 #ifndef _LIBCPP_NO_EXCEPTIONS
1043 #endif // _LIBCPP_NO_EXCEPTIONS
1044 typename basic_ostream<char, _Traits>::sentry __s(__os);
1047 typedef ostreambuf_iterator<char, _Traits> _Ip;
1048 size_t __len = _Traits::length((const char*)__str);
1049 if (__pad_and_output(_Ip(__os),
1051 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1052 (const char*)__str + __len :
1054 (const char*)__str + __len,
1056 __os.fill()).failed())
1057 __os.setstate(ios_base::badbit | ios_base::failbit);
1059 #ifndef _LIBCPP_NO_EXCEPTIONS
1063 __os.__set_badbit_and_consider_rethrow();
1065 #endif // _LIBCPP_NO_EXCEPTIONS
1069 template <class _CharT, class _Traits>
1070 basic_ostream<_CharT, _Traits>&
1071 basic_ostream<_CharT, _Traits>::put(char_type __c)
1073 #ifndef _LIBCPP_NO_EXCEPTIONS
1076 #endif // _LIBCPP_NO_EXCEPTIONS
1080 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
1084 this->setstate(ios_base::badbit);
1086 #ifndef _LIBCPP_NO_EXCEPTIONS
1090 this->__set_badbit_and_consider_rethrow();
1092 #endif // _LIBCPP_NO_EXCEPTIONS
1096 template <class _CharT, class _Traits>
1097 basic_ostream<_CharT, _Traits>&
1098 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
1100 #ifndef _LIBCPP_NO_EXCEPTIONS
1103 #endif // _LIBCPP_NO_EXCEPTIONS
1104 sentry __sen(*this);
1107 if (this->rdbuf()->sputn(__s, __n) != __n)
1108 this->setstate(ios_base::badbit);
1110 #ifndef _LIBCPP_NO_EXCEPTIONS
1114 this->__set_badbit_and_consider_rethrow();
1116 #endif // _LIBCPP_NO_EXCEPTIONS
1120 template <class _CharT, class _Traits>
1121 basic_ostream<_CharT, _Traits>&
1122 basic_ostream<_CharT, _Traits>::flush()
1124 #ifndef _LIBCPP_NO_EXCEPTIONS
1127 #endif // _LIBCPP_NO_EXCEPTIONS
1133 if (this->rdbuf()->pubsync() == -1)
1134 this->setstate(ios_base::badbit);
1137 #ifndef _LIBCPP_NO_EXCEPTIONS
1141 this->__set_badbit_and_consider_rethrow();
1143 #endif // _LIBCPP_NO_EXCEPTIONS
1147 template <class _CharT, class _Traits>
1148 inline _LIBCPP_INLINE_VISIBILITY
1149 typename basic_ostream<_CharT, _Traits>::pos_type
1150 basic_ostream<_CharT, _Traits>::tellp()
1153 return pos_type(-1);
1154 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1157 template <class _CharT, class _Traits>
1158 inline _LIBCPP_INLINE_VISIBILITY
1159 basic_ostream<_CharT, _Traits>&
1160 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1165 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1166 this->setstate(ios_base::failbit);
1171 template <class _CharT, class _Traits>
1172 inline _LIBCPP_INLINE_VISIBILITY
1173 basic_ostream<_CharT, _Traits>&
1174 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1179 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
1180 this->setstate(ios_base::failbit);
1185 template <class _CharT, class _Traits>
1186 inline _LIBCPP_INLINE_VISIBILITY
1187 basic_ostream<_CharT, _Traits>&
1188 endl(basic_ostream<_CharT, _Traits>& __os)
1190 __os.put(__os.widen('\n'));
1195 template <class _CharT, class _Traits>
1196 inline _LIBCPP_INLINE_VISIBILITY
1197 basic_ostream<_CharT, _Traits>&
1198 ends(basic_ostream<_CharT, _Traits>& __os)
1204 template <class _CharT, class _Traits>
1205 inline _LIBCPP_INLINE_VISIBILITY
1206 basic_ostream<_CharT, _Traits>&
1207 flush(basic_ostream<_CharT, _Traits>& __os)
1213 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1215 template <class _Stream, class _Tp>
1216 inline _LIBCPP_INLINE_VISIBILITY
1219 !is_lvalue_reference<_Stream>::value &&
1220 is_base_of<ios_base, _Stream>::value,
1223 operator<<(_Stream&& __os, const _Tp& __x)
1226 return _VSTD::move(__os);
1229 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1231 template<class _CharT, class _Traits, class _Allocator>
1232 basic_ostream<_CharT, _Traits>&
1233 operator<<(basic_ostream<_CharT, _Traits>& __os,
1234 const basic_string<_CharT, _Traits, _Allocator>& __str)
1236 #ifndef _LIBCPP_NO_EXCEPTIONS
1239 #endif // _LIBCPP_NO_EXCEPTIONS
1240 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
1243 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
1244 size_t __len = __str.size();
1245 if (__pad_and_output(_Ip(__os),
1247 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1248 __str.data() + __len :
1250 __str.data() + __len,
1252 __os.fill()).failed())
1253 __os.setstate(ios_base::badbit | ios_base::failbit);
1255 #ifndef _LIBCPP_NO_EXCEPTIONS
1259 __os.__set_badbit_and_consider_rethrow();
1261 #endif // _LIBCPP_NO_EXCEPTIONS
1265 template <class _CharT, class _Traits>
1266 inline _LIBCPP_INLINE_VISIBILITY
1267 basic_ostream<_CharT, _Traits>&
1268 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1270 return __os << __ec.category().name() << ':' << __ec.value();
1273 template<class _CharT, class _Traits, class _Yp>
1274 inline _LIBCPP_INLINE_VISIBILITY
1275 basic_ostream<_CharT, _Traits>&
1276 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1278 return __os << __p.get();
1281 template <class _CharT, class _Traits, size_t _Size>
1282 basic_ostream<_CharT, _Traits>&
1283 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1285 return __os << __x.template to_string<_CharT, _Traits>
1286 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1287 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1290 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>)
1291 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>)
1293 _LIBCPP_END_NAMESPACE_STD
1295 #endif // _LIBCPP_OSTREAM