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=(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);
60 // 27.7.2.7 Unformatted output:
61 basic_ostream& put(char_type c);
62 basic_ostream& write(const char_type* s, streamsize n);
63 basic_ostream& flush();
67 basic_ostream& seekp(pos_type);
68 basic_ostream& seekp(off_type, ios_base::seekdir);
71 // 27.7.2.6.4 character inserters
73 template<class charT, class traits>
74 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
76 template<class charT, class traits>
77 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
79 template<class traits>
80 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
82 // signed and unsigned
84 template<class traits>
85 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
87 template<class traits>
88 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
91 template<class charT, class traits>
92 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
94 template<class charT, class traits>
95 basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
97 template<class traits>
98 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
100 // signed and unsigned
101 template<class traits>
102 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
104 template<class traits>
105 basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
108 template <class charT, class traits>
109 void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
111 template <class charT, class traits>
112 basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
114 template <class charT, class traits>
115 basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
117 template <class charT, class traits>
118 basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
120 // rvalue stream insertion
121 template <class charT, class traits, class T>
122 basic_ostream<charT, traits>&
123 operator<<(basic_ostream<charT, traits>&& os, const T& x);
136 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
137 #pragma GCC system_header
140 _LIBCPP_BEGIN_NAMESPACE_STD
142 template <class _CharT, class _Traits>
143 class _LIBCPP_TYPE_VIS basic_ostream
144 : virtual public basic_ios<_CharT, _Traits>
147 // types (inherited from basic_ios (27.5.4)):
148 typedef _CharT char_type;
149 typedef _Traits traits_type;
150 typedef typename traits_type::int_type int_type;
151 typedef typename traits_type::pos_type pos_type;
152 typedef typename traits_type::off_type off_type;
154 // 27.7.2.2 Constructor/destructor:
155 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
156 virtual ~basic_ostream();
158 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
159 _LIBCPP_INLINE_VISIBILITY
160 basic_ostream(basic_ostream&& __rhs);
163 // 27.7.2.3 Assign/swap
164 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
165 _LIBCPP_INLINE_VISIBILITY
166 basic_ostream& operator=(basic_ostream&& __rhs);
168 void swap(basic_ostream& __rhs);
171 // 27.7.2.4 Prefix/suffix:
172 class _LIBCPP_TYPE_VIS sentry;
174 // 27.7.2.6 Formatted output:
175 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
176 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
177 (*__pf)(basic_ios<char_type,traits_type>&));
178 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
179 basic_ostream& operator<<(bool __n);
180 basic_ostream& operator<<(short __n);
181 basic_ostream& operator<<(unsigned short __n);
182 basic_ostream& operator<<(int __n);
183 basic_ostream& operator<<(unsigned int __n);
184 basic_ostream& operator<<(long __n);
185 basic_ostream& operator<<(unsigned long __n);
186 basic_ostream& operator<<(long long __n);
187 basic_ostream& operator<<(unsigned long long __n);
188 basic_ostream& operator<<(float __f);
189 basic_ostream& operator<<(double __f);
190 basic_ostream& operator<<(long double __f);
191 basic_ostream& operator<<(const void* __p);
192 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
194 // 27.7.2.7 Unformatted output:
195 basic_ostream& put(char_type __c);
196 basic_ostream& write(const char_type* __s, streamsize __n);
197 basic_ostream& flush();
201 basic_ostream& seekp(pos_type __pos);
202 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
205 _LIBCPP_ALWAYS_INLINE
206 basic_ostream() {} // extension, intentially does not initialize
209 template <class _CharT, class _Traits>
210 class _LIBCPP_TYPE_VIS basic_ostream<_CharT, _Traits>::sentry
213 basic_ostream<_CharT, _Traits>& __os_;
215 sentry(const sentry&); // = delete;
216 sentry& operator=(const sentry&); // = delete;
219 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
222 _LIBCPP_ALWAYS_INLINE
224 operator bool() const {return __ok_;}
227 template <class _CharT, class _Traits>
228 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
240 template <class _CharT, class _Traits>
241 basic_ostream<_CharT, _Traits>::sentry::~sentry()
243 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
244 && !uncaught_exception())
246 #ifndef _LIBCPP_NO_EXCEPTIONS
249 #endif // _LIBCPP_NO_EXCEPTIONS
250 if (__os_.rdbuf()->pubsync() == -1)
251 __os_.setstate(ios_base::badbit);
252 #ifndef _LIBCPP_NO_EXCEPTIONS
257 #endif // _LIBCPP_NO_EXCEPTIONS
261 template <class _CharT, class _Traits>
262 inline _LIBCPP_INLINE_VISIBILITY
263 basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
268 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
270 template <class _CharT, class _Traits>
271 inline _LIBCPP_INLINE_VISIBILITY
272 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
277 template <class _CharT, class _Traits>
278 inline _LIBCPP_INLINE_VISIBILITY
279 basic_ostream<_CharT, _Traits>&
280 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
286 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
288 template <class _CharT, class _Traits>
289 basic_ostream<_CharT, _Traits>::~basic_ostream()
293 template <class _CharT, class _Traits>
294 inline _LIBCPP_INLINE_VISIBILITY
296 basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
298 basic_ios<char_type, traits_type>::swap(__rhs);
301 template <class _CharT, class _Traits>
302 inline _LIBCPP_INLINE_VISIBILITY
303 basic_ostream<_CharT, _Traits>&
304 basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
309 template <class _CharT, class _Traits>
310 inline _LIBCPP_INLINE_VISIBILITY
311 basic_ostream<_CharT, _Traits>&
312 basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
313 (*__pf)(basic_ios<char_type,traits_type>&))
319 template <class _CharT, class _Traits>
320 inline _LIBCPP_INLINE_VISIBILITY
321 basic_ostream<_CharT, _Traits>&
322 basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
328 template <class _CharT, class _Traits>
329 basic_ostream<_CharT, _Traits>&
330 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
332 #ifndef _LIBCPP_NO_EXCEPTIONS
335 #endif // _LIBCPP_NO_EXCEPTIONS
341 #ifndef _LIBCPP_NO_EXCEPTIONS
344 #endif // _LIBCPP_NO_EXCEPTIONS
345 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
346 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
351 for (; __i != __eof; ++__i, ++__o, ++__c)
358 this->setstate(ios_base::failbit);
359 #ifndef _LIBCPP_NO_EXCEPTIONS
363 this->__set_failbit_and_consider_rethrow();
365 #endif // _LIBCPP_NO_EXCEPTIONS
368 this->setstate(ios_base::badbit);
370 #ifndef _LIBCPP_NO_EXCEPTIONS
374 this->__set_badbit_and_consider_rethrow();
376 #endif // _LIBCPP_NO_EXCEPTIONS
380 template <class _CharT, class _Traits>
381 basic_ostream<_CharT, _Traits>&
382 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
384 #ifndef _LIBCPP_NO_EXCEPTIONS
387 #endif // _LIBCPP_NO_EXCEPTIONS
391 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
392 const _Fp& __f = use_facet<_Fp>(this->getloc());
393 if (__f.put(*this, *this, this->fill(), __n).failed())
394 this->setstate(ios_base::badbit | ios_base::failbit);
396 #ifndef _LIBCPP_NO_EXCEPTIONS
400 this->__set_badbit_and_consider_rethrow();
402 #endif // _LIBCPP_NO_EXCEPTIONS
406 template <class _CharT, class _Traits>
407 basic_ostream<_CharT, _Traits>&
408 basic_ostream<_CharT, _Traits>::operator<<(short __n)
410 #ifndef _LIBCPP_NO_EXCEPTIONS
413 #endif // _LIBCPP_NO_EXCEPTIONS
417 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
418 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
419 const _Fp& __f = use_facet<_Fp>(this->getloc());
420 if (__f.put(*this, *this, this->fill(),
421 __flags == ios_base::oct || __flags == ios_base::hex ?
422 static_cast<long>(static_cast<unsigned short>(__n)) :
423 static_cast<long>(__n)).failed())
424 this->setstate(ios_base::badbit | ios_base::failbit);
426 #ifndef _LIBCPP_NO_EXCEPTIONS
430 this->__set_badbit_and_consider_rethrow();
432 #endif // _LIBCPP_NO_EXCEPTIONS
436 template <class _CharT, class _Traits>
437 basic_ostream<_CharT, _Traits>&
438 basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
440 #ifndef _LIBCPP_NO_EXCEPTIONS
443 #endif // _LIBCPP_NO_EXCEPTIONS
447 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
448 const _Fp& __f = use_facet<_Fp>(this->getloc());
449 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
450 this->setstate(ios_base::badbit | ios_base::failbit);
452 #ifndef _LIBCPP_NO_EXCEPTIONS
456 this->__set_badbit_and_consider_rethrow();
458 #endif // _LIBCPP_NO_EXCEPTIONS
462 template <class _CharT, class _Traits>
463 basic_ostream<_CharT, _Traits>&
464 basic_ostream<_CharT, _Traits>::operator<<(int __n)
466 #ifndef _LIBCPP_NO_EXCEPTIONS
469 #endif // _LIBCPP_NO_EXCEPTIONS
473 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
474 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
475 const _Fp& __f = use_facet<_Fp>(this->getloc());
476 if (__f.put(*this, *this, this->fill(),
477 __flags == ios_base::oct || __flags == ios_base::hex ?
478 static_cast<long>(static_cast<unsigned int>(__n)) :
479 static_cast<long>(__n)).failed())
480 this->setstate(ios_base::badbit | ios_base::failbit);
482 #ifndef _LIBCPP_NO_EXCEPTIONS
486 this->__set_badbit_and_consider_rethrow();
488 #endif // _LIBCPP_NO_EXCEPTIONS
492 template <class _CharT, class _Traits>
493 basic_ostream<_CharT, _Traits>&
494 basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
496 #ifndef _LIBCPP_NO_EXCEPTIONS
499 #endif // _LIBCPP_NO_EXCEPTIONS
503 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
504 const _Fp& __f = use_facet<_Fp>(this->getloc());
505 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
506 this->setstate(ios_base::badbit | ios_base::failbit);
508 #ifndef _LIBCPP_NO_EXCEPTIONS
512 this->__set_badbit_and_consider_rethrow();
514 #endif // _LIBCPP_NO_EXCEPTIONS
518 template <class _CharT, class _Traits>
519 basic_ostream<_CharT, _Traits>&
520 basic_ostream<_CharT, _Traits>::operator<<(long __n)
522 #ifndef _LIBCPP_NO_EXCEPTIONS
525 #endif // _LIBCPP_NO_EXCEPTIONS
529 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
530 const _Fp& __f = use_facet<_Fp>(this->getloc());
531 if (__f.put(*this, *this, this->fill(), __n).failed())
532 this->setstate(ios_base::badbit | ios_base::failbit);
534 #ifndef _LIBCPP_NO_EXCEPTIONS
538 this->__set_badbit_and_consider_rethrow();
540 #endif // _LIBCPP_NO_EXCEPTIONS
544 template <class _CharT, class _Traits>
545 basic_ostream<_CharT, _Traits>&
546 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
548 #ifndef _LIBCPP_NO_EXCEPTIONS
551 #endif // _LIBCPP_NO_EXCEPTIONS
555 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
556 const _Fp& __f = use_facet<_Fp>(this->getloc());
557 if (__f.put(*this, *this, this->fill(), __n).failed())
558 this->setstate(ios_base::badbit | ios_base::failbit);
560 #ifndef _LIBCPP_NO_EXCEPTIONS
564 this->__set_badbit_and_consider_rethrow();
566 #endif // _LIBCPP_NO_EXCEPTIONS
570 template <class _CharT, class _Traits>
571 basic_ostream<_CharT, _Traits>&
572 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
574 #ifndef _LIBCPP_NO_EXCEPTIONS
577 #endif // _LIBCPP_NO_EXCEPTIONS
581 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
582 const _Fp& __f = use_facet<_Fp>(this->getloc());
583 if (__f.put(*this, *this, this->fill(), __n).failed())
584 this->setstate(ios_base::badbit | ios_base::failbit);
586 #ifndef _LIBCPP_NO_EXCEPTIONS
590 this->__set_badbit_and_consider_rethrow();
592 #endif // _LIBCPP_NO_EXCEPTIONS
596 template <class _CharT, class _Traits>
597 basic_ostream<_CharT, _Traits>&
598 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
600 #ifndef _LIBCPP_NO_EXCEPTIONS
603 #endif // _LIBCPP_NO_EXCEPTIONS
607 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
608 const _Fp& __f = use_facet<_Fp>(this->getloc());
609 if (__f.put(*this, *this, this->fill(), __n).failed())
610 this->setstate(ios_base::badbit | ios_base::failbit);
612 #ifndef _LIBCPP_NO_EXCEPTIONS
616 this->__set_badbit_and_consider_rethrow();
618 #endif // _LIBCPP_NO_EXCEPTIONS
622 template <class _CharT, class _Traits>
623 basic_ostream<_CharT, _Traits>&
624 basic_ostream<_CharT, _Traits>::operator<<(float __n)
626 #ifndef _LIBCPP_NO_EXCEPTIONS
629 #endif // _LIBCPP_NO_EXCEPTIONS
633 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
634 const _Fp& __f = use_facet<_Fp>(this->getloc());
635 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
636 this->setstate(ios_base::badbit | ios_base::failbit);
638 #ifndef _LIBCPP_NO_EXCEPTIONS
642 this->__set_badbit_and_consider_rethrow();
644 #endif // _LIBCPP_NO_EXCEPTIONS
648 template <class _CharT, class _Traits>
649 basic_ostream<_CharT, _Traits>&
650 basic_ostream<_CharT, _Traits>::operator<<(double __n)
652 #ifndef _LIBCPP_NO_EXCEPTIONS
655 #endif // _LIBCPP_NO_EXCEPTIONS
659 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
660 const _Fp& __f = use_facet<_Fp>(this->getloc());
661 if (__f.put(*this, *this, this->fill(), __n).failed())
662 this->setstate(ios_base::badbit | ios_base::failbit);
664 #ifndef _LIBCPP_NO_EXCEPTIONS
668 this->__set_badbit_and_consider_rethrow();
670 #endif // _LIBCPP_NO_EXCEPTIONS
674 template <class _CharT, class _Traits>
675 basic_ostream<_CharT, _Traits>&
676 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
678 #ifndef _LIBCPP_NO_EXCEPTIONS
681 #endif // _LIBCPP_NO_EXCEPTIONS
685 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
686 const _Fp& __f = use_facet<_Fp>(this->getloc());
687 if (__f.put(*this, *this, this->fill(), __n).failed())
688 this->setstate(ios_base::badbit | ios_base::failbit);
690 #ifndef _LIBCPP_NO_EXCEPTIONS
694 this->__set_badbit_and_consider_rethrow();
696 #endif // _LIBCPP_NO_EXCEPTIONS
700 template <class _CharT, class _Traits>
701 basic_ostream<_CharT, _Traits>&
702 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
704 #ifndef _LIBCPP_NO_EXCEPTIONS
707 #endif // _LIBCPP_NO_EXCEPTIONS
711 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
712 const _Fp& __f = use_facet<_Fp>(this->getloc());
713 if (__f.put(*this, *this, this->fill(), __n).failed())
714 this->setstate(ios_base::badbit | ios_base::failbit);
716 #ifndef _LIBCPP_NO_EXCEPTIONS
720 this->__set_badbit_and_consider_rethrow();
722 #endif // _LIBCPP_NO_EXCEPTIONS
726 template<class _CharT, class _Traits>
727 basic_ostream<_CharT, _Traits>&
728 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
730 #ifndef _LIBCPP_NO_EXCEPTIONS
733 #endif // _LIBCPP_NO_EXCEPTIONS
734 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
737 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
738 if (__pad_and_output(_Ip(__os),
740 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
745 __os.fill()).failed())
746 __os.setstate(ios_base::badbit | ios_base::failbit);
748 #ifndef _LIBCPP_NO_EXCEPTIONS
752 __os.__set_badbit_and_consider_rethrow();
754 #endif // _LIBCPP_NO_EXCEPTIONS
758 template<class _CharT, class _Traits>
759 basic_ostream<_CharT, _Traits>&
760 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
762 #ifndef _LIBCPP_NO_EXCEPTIONS
765 #endif // _LIBCPP_NO_EXCEPTIONS
766 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
769 _CharT __c = __os.widen(__cn);
770 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
771 if (__pad_and_output(_Ip(__os),
773 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
778 __os.fill()).failed())
779 __os.setstate(ios_base::badbit | ios_base::failbit);
781 #ifndef _LIBCPP_NO_EXCEPTIONS
785 __os.__set_badbit_and_consider_rethrow();
787 #endif // _LIBCPP_NO_EXCEPTIONS
791 template<class _Traits>
792 basic_ostream<char, _Traits>&
793 operator<<(basic_ostream<char, _Traits>& __os, char __c)
795 #ifndef _LIBCPP_NO_EXCEPTIONS
798 #endif // _LIBCPP_NO_EXCEPTIONS
799 typename basic_ostream<char, _Traits>::sentry __s(__os);
802 typedef ostreambuf_iterator<char, _Traits> _Ip;
803 if (__pad_and_output(_Ip(__os),
805 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
810 __os.fill()).failed())
811 __os.setstate(ios_base::badbit | ios_base::failbit);
813 #ifndef _LIBCPP_NO_EXCEPTIONS
817 __os.__set_badbit_and_consider_rethrow();
819 #endif // _LIBCPP_NO_EXCEPTIONS
823 template<class _Traits>
824 basic_ostream<char, _Traits>&
825 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
827 #ifndef _LIBCPP_NO_EXCEPTIONS
830 #endif // _LIBCPP_NO_EXCEPTIONS
831 typename basic_ostream<char, _Traits>::sentry __s(__os);
834 typedef ostreambuf_iterator<char, _Traits> _Ip;
835 if (__pad_and_output(_Ip(__os),
837 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
842 __os.fill()).failed())
843 __os.setstate(ios_base::badbit | ios_base::failbit);
845 #ifndef _LIBCPP_NO_EXCEPTIONS
849 __os.__set_badbit_and_consider_rethrow();
851 #endif // _LIBCPP_NO_EXCEPTIONS
855 template<class _Traits>
856 basic_ostream<char, _Traits>&
857 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
859 #ifndef _LIBCPP_NO_EXCEPTIONS
862 #endif // _LIBCPP_NO_EXCEPTIONS
863 typename basic_ostream<char, _Traits>::sentry __s(__os);
866 typedef ostreambuf_iterator<char, _Traits> _Ip;
867 if (__pad_and_output(_Ip(__os),
869 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
874 __os.fill()).failed())
875 __os.setstate(ios_base::badbit | ios_base::failbit);
877 #ifndef _LIBCPP_NO_EXCEPTIONS
881 __os.__set_badbit_and_consider_rethrow();
883 #endif // _LIBCPP_NO_EXCEPTIONS
887 template<class _CharT, class _Traits>
888 basic_ostream<_CharT, _Traits>&
889 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
891 #ifndef _LIBCPP_NO_EXCEPTIONS
894 #endif // _LIBCPP_NO_EXCEPTIONS
895 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
898 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
899 size_t __len = _Traits::length(__str);
900 if (__pad_and_output(_Ip(__os),
902 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
907 __os.fill()).failed())
908 __os.setstate(ios_base::badbit | ios_base::failbit);
910 #ifndef _LIBCPP_NO_EXCEPTIONS
914 __os.__set_badbit_and_consider_rethrow();
916 #endif // _LIBCPP_NO_EXCEPTIONS
920 template<class _CharT, class _Traits>
921 basic_ostream<_CharT, _Traits>&
922 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
924 #ifndef _LIBCPP_NO_EXCEPTIONS
927 #endif // _LIBCPP_NO_EXCEPTIONS
928 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
931 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
932 size_t __len = char_traits<char>::length(__strn);
933 const int __bs = 100;
935 _CharT* __wb = __wbb;
936 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
939 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
944 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
945 *__p = __os.widen(*__strn);
946 if (__pad_and_output(_Ip(__os),
948 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
953 __os.fill()).failed())
954 __os.setstate(ios_base::badbit | ios_base::failbit);
956 #ifndef _LIBCPP_NO_EXCEPTIONS
960 __os.__set_badbit_and_consider_rethrow();
962 #endif // _LIBCPP_NO_EXCEPTIONS
966 template<class _Traits>
967 basic_ostream<char, _Traits>&
968 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
970 #ifndef _LIBCPP_NO_EXCEPTIONS
973 #endif // _LIBCPP_NO_EXCEPTIONS
974 typename basic_ostream<char, _Traits>::sentry __s(__os);
977 typedef ostreambuf_iterator<char, _Traits> _Ip;
978 size_t __len = _Traits::length(__str);
979 if (__pad_and_output(_Ip(__os),
981 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
986 __os.fill()).failed())
987 __os.setstate(ios_base::badbit | ios_base::failbit);
989 #ifndef _LIBCPP_NO_EXCEPTIONS
993 __os.__set_badbit_and_consider_rethrow();
995 #endif // _LIBCPP_NO_EXCEPTIONS
999 template<class _Traits>
1000 basic_ostream<char, _Traits>&
1001 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
1003 #ifndef _LIBCPP_NO_EXCEPTIONS
1006 #endif // _LIBCPP_NO_EXCEPTIONS
1007 typename basic_ostream<char, _Traits>::sentry __s(__os);
1010 typedef ostreambuf_iterator<char, _Traits> _Ip;
1011 size_t __len = _Traits::length((const char*)__str);
1012 if (__pad_and_output(_Ip(__os),
1014 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1015 (const char*)__str + __len :
1017 (const char*)__str + __len,
1019 __os.fill()).failed())
1020 __os.setstate(ios_base::badbit | ios_base::failbit);
1022 #ifndef _LIBCPP_NO_EXCEPTIONS
1026 __os.__set_badbit_and_consider_rethrow();
1028 #endif // _LIBCPP_NO_EXCEPTIONS
1032 template<class _Traits>
1033 basic_ostream<char, _Traits>&
1034 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
1036 #ifndef _LIBCPP_NO_EXCEPTIONS
1039 #endif // _LIBCPP_NO_EXCEPTIONS
1040 typename basic_ostream<char, _Traits>::sentry __s(__os);
1043 typedef ostreambuf_iterator<char, _Traits> _Ip;
1044 size_t __len = _Traits::length((const char*)__str);
1045 if (__pad_and_output(_Ip(__os),
1047 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1048 (const char*)__str + __len :
1050 (const char*)__str + __len,
1052 __os.fill()).failed())
1053 __os.setstate(ios_base::badbit | ios_base::failbit);
1055 #ifndef _LIBCPP_NO_EXCEPTIONS
1059 __os.__set_badbit_and_consider_rethrow();
1061 #endif // _LIBCPP_NO_EXCEPTIONS
1065 template <class _CharT, class _Traits>
1066 basic_ostream<_CharT, _Traits>&
1067 basic_ostream<_CharT, _Traits>::put(char_type __c)
1069 #ifndef _LIBCPP_NO_EXCEPTIONS
1072 #endif // _LIBCPP_NO_EXCEPTIONS
1076 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
1080 this->setstate(ios_base::badbit);
1082 #ifndef _LIBCPP_NO_EXCEPTIONS
1086 this->__set_badbit_and_consider_rethrow();
1088 #endif // _LIBCPP_NO_EXCEPTIONS
1092 template <class _CharT, class _Traits>
1093 basic_ostream<_CharT, _Traits>&
1094 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
1096 #ifndef _LIBCPP_NO_EXCEPTIONS
1099 #endif // _LIBCPP_NO_EXCEPTIONS
1100 sentry __sen(*this);
1103 if (this->rdbuf()->sputn(__s, __n) != __n)
1104 this->setstate(ios_base::badbit);
1106 #ifndef _LIBCPP_NO_EXCEPTIONS
1110 this->__set_badbit_and_consider_rethrow();
1112 #endif // _LIBCPP_NO_EXCEPTIONS
1116 template <class _CharT, class _Traits>
1117 basic_ostream<_CharT, _Traits>&
1118 basic_ostream<_CharT, _Traits>::flush()
1120 #ifndef _LIBCPP_NO_EXCEPTIONS
1123 #endif // _LIBCPP_NO_EXCEPTIONS
1129 if (this->rdbuf()->pubsync() == -1)
1130 this->setstate(ios_base::badbit);
1133 #ifndef _LIBCPP_NO_EXCEPTIONS
1137 this->__set_badbit_and_consider_rethrow();
1139 #endif // _LIBCPP_NO_EXCEPTIONS
1143 template <class _CharT, class _Traits>
1144 inline _LIBCPP_INLINE_VISIBILITY
1145 typename basic_ostream<_CharT, _Traits>::pos_type
1146 basic_ostream<_CharT, _Traits>::tellp()
1149 return pos_type(-1);
1150 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1153 template <class _CharT, class _Traits>
1154 inline _LIBCPP_INLINE_VISIBILITY
1155 basic_ostream<_CharT, _Traits>&
1156 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1160 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1161 this->setstate(ios_base::failbit);
1166 template <class _CharT, class _Traits>
1167 inline _LIBCPP_INLINE_VISIBILITY
1168 basic_ostream<_CharT, _Traits>&
1169 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1172 this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
1176 template <class _CharT, class _Traits>
1177 inline _LIBCPP_INLINE_VISIBILITY
1178 basic_ostream<_CharT, _Traits>&
1179 endl(basic_ostream<_CharT, _Traits>& __os)
1181 __os.put(__os.widen('\n'));
1186 template <class _CharT, class _Traits>
1187 inline _LIBCPP_INLINE_VISIBILITY
1188 basic_ostream<_CharT, _Traits>&
1189 ends(basic_ostream<_CharT, _Traits>& __os)
1195 template <class _CharT, class _Traits>
1196 inline _LIBCPP_INLINE_VISIBILITY
1197 basic_ostream<_CharT, _Traits>&
1198 flush(basic_ostream<_CharT, _Traits>& __os)
1204 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1206 template <class _Stream, class _Tp>
1207 inline _LIBCPP_INLINE_VISIBILITY
1210 !is_lvalue_reference<_Stream>::value &&
1211 is_base_of<ios_base, _Stream>::value,
1214 operator<<(_Stream&& __os, const _Tp& __x)
1217 return _VSTD::move(__os);
1220 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1222 template<class _CharT, class _Traits, class _Allocator>
1223 basic_ostream<_CharT, _Traits>&
1224 operator<<(basic_ostream<_CharT, _Traits>& __os,
1225 const basic_string<_CharT, _Traits, _Allocator>& __str)
1227 #ifndef _LIBCPP_NO_EXCEPTIONS
1230 #endif // _LIBCPP_NO_EXCEPTIONS
1231 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
1234 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
1235 size_t __len = __str.size();
1236 if (__pad_and_output(_Ip(__os),
1238 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
1239 __str.data() + __len :
1241 __str.data() + __len,
1243 __os.fill()).failed())
1244 __os.setstate(ios_base::badbit | ios_base::failbit);
1246 #ifndef _LIBCPP_NO_EXCEPTIONS
1250 __os.__set_badbit_and_consider_rethrow();
1252 #endif // _LIBCPP_NO_EXCEPTIONS
1256 template <class _CharT, class _Traits>
1257 inline _LIBCPP_INLINE_VISIBILITY
1258 basic_ostream<_CharT, _Traits>&
1259 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1261 return __os << __ec.category().name() << ':' << __ec.value();
1264 template<class _CharT, class _Traits, class _Yp>
1265 inline _LIBCPP_INLINE_VISIBILITY
1266 basic_ostream<_CharT, _Traits>&
1267 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1269 return __os << __p.get();
1272 template <class _CharT, class _Traits, size_t _Size>
1273 basic_ostream<_CharT, _Traits>&
1274 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1276 return __os << __x.template to_string<_CharT, _Traits>
1277 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1278 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1281 _LIBCPP_EXTERN_TEMPLATE(class basic_ostream<char>)
1282 _LIBCPP_EXTERN_TEMPLATE(class basic_ostream<wchar_t>)
1284 _LIBCPP_END_NAMESPACE_STD
1286 #endif // _LIBCPP_OSTREAM