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);
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 charT, class traits, class T>
130 basic_ostream<charT, traits>&
131 operator<<(basic_ostream<charT, traits>&& 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_TYPE_VIS_ONLY 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 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb);
164 virtual ~basic_ostream();
166 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
167 _LIBCPP_INLINE_VISIBILITY
168 basic_ostream(basic_ostream&& __rhs);
171 // 27.7.2.3 Assign/swap
172 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
173 _LIBCPP_INLINE_VISIBILITY
174 basic_ostream& operator=(basic_ostream&& __rhs);
176 void swap(basic_ostream& __rhs);
178 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
179 basic_ostream (const basic_ostream& __rhs) = delete;
180 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
182 basic_ostream (const basic_ostream& __rhs); // not defined
183 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
187 // 27.7.2.4 Prefix/suffix:
188 class _LIBCPP_TYPE_VIS_ONLY sentry;
190 // 27.7.2.6 Formatted output:
191 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&));
192 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
193 (*__pf)(basic_ios<char_type,traits_type>&));
194 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&));
195 basic_ostream& operator<<(bool __n);
196 basic_ostream& operator<<(short __n);
197 basic_ostream& operator<<(unsigned short __n);
198 basic_ostream& operator<<(int __n);
199 basic_ostream& operator<<(unsigned int __n);
200 basic_ostream& operator<<(long __n);
201 basic_ostream& operator<<(unsigned long __n);
202 basic_ostream& operator<<(long long __n);
203 basic_ostream& operator<<(unsigned long long __n);
204 basic_ostream& operator<<(float __f);
205 basic_ostream& operator<<(double __f);
206 basic_ostream& operator<<(long double __f);
207 basic_ostream& operator<<(const void* __p);
208 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
210 // 27.7.2.7 Unformatted output:
211 basic_ostream& put(char_type __c);
212 basic_ostream& write(const char_type* __s, streamsize __n);
213 basic_ostream& flush();
217 basic_ostream& seekp(pos_type __pos);
218 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
221 _LIBCPP_ALWAYS_INLINE
222 basic_ostream() {} // extension, intentially does not initialize
225 template <class _CharT, class _Traits>
226 class _LIBCPP_TYPE_VIS_ONLY basic_ostream<_CharT, _Traits>::sentry
229 basic_ostream<_CharT, _Traits>& __os_;
231 sentry(const sentry&); // = delete;
232 sentry& operator=(const sentry&); // = delete;
235 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
238 _LIBCPP_ALWAYS_INLINE
240 operator bool() const {return __ok_;}
243 template <class _CharT, class _Traits>
244 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
256 template <class _CharT, class _Traits>
257 basic_ostream<_CharT, _Traits>::sentry::~sentry()
259 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
260 && !uncaught_exception())
262 #ifndef _LIBCPP_NO_EXCEPTIONS
265 #endif // _LIBCPP_NO_EXCEPTIONS
266 if (__os_.rdbuf()->pubsync() == -1)
267 __os_.setstate(ios_base::badbit);
268 #ifndef _LIBCPP_NO_EXCEPTIONS
273 #endif // _LIBCPP_NO_EXCEPTIONS
277 template <class _CharT, class _Traits>
278 inline _LIBCPP_INLINE_VISIBILITY
279 basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
284 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
286 template <class _CharT, class _Traits>
287 inline _LIBCPP_INLINE_VISIBILITY
288 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
293 template <class _CharT, class _Traits>
294 inline _LIBCPP_INLINE_VISIBILITY
295 basic_ostream<_CharT, _Traits>&
296 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
302 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
304 template <class _CharT, class _Traits>
305 basic_ostream<_CharT, _Traits>::~basic_ostream()
309 template <class _CharT, class _Traits>
310 inline _LIBCPP_INLINE_VISIBILITY
312 basic_ostream<_CharT, _Traits>::swap(basic_ostream& __rhs)
314 basic_ios<char_type, traits_type>::swap(__rhs);
317 template <class _CharT, class _Traits>
318 inline _LIBCPP_INLINE_VISIBILITY
319 basic_ostream<_CharT, _Traits>&
320 basic_ostream<_CharT, _Traits>::operator<<(basic_ostream& (*__pf)(basic_ostream&))
325 template <class _CharT, class _Traits>
326 inline _LIBCPP_INLINE_VISIBILITY
327 basic_ostream<_CharT, _Traits>&
328 basic_ostream<_CharT, _Traits>::operator<<(basic_ios<char_type, traits_type>&
329 (*__pf)(basic_ios<char_type,traits_type>&))
335 template <class _CharT, class _Traits>
336 inline _LIBCPP_INLINE_VISIBILITY
337 basic_ostream<_CharT, _Traits>&
338 basic_ostream<_CharT, _Traits>::operator<<(ios_base& (*__pf)(ios_base&))
344 template <class _CharT, class _Traits>
345 basic_ostream<_CharT, _Traits>&
346 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
348 #ifndef _LIBCPP_NO_EXCEPTIONS
351 #endif // _LIBCPP_NO_EXCEPTIONS
357 #ifndef _LIBCPP_NO_EXCEPTIONS
360 #endif // _LIBCPP_NO_EXCEPTIONS
361 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
362 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
367 for (; __i != __eof; ++__i, ++__o, ++__c)
374 this->setstate(ios_base::failbit);
375 #ifndef _LIBCPP_NO_EXCEPTIONS
379 this->__set_failbit_and_consider_rethrow();
381 #endif // _LIBCPP_NO_EXCEPTIONS
384 this->setstate(ios_base::badbit);
386 #ifndef _LIBCPP_NO_EXCEPTIONS
390 this->__set_badbit_and_consider_rethrow();
392 #endif // _LIBCPP_NO_EXCEPTIONS
396 template <class _CharT, class _Traits>
397 basic_ostream<_CharT, _Traits>&
398 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
400 #ifndef _LIBCPP_NO_EXCEPTIONS
403 #endif // _LIBCPP_NO_EXCEPTIONS
407 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
408 const _Fp& __f = use_facet<_Fp>(this->getloc());
409 if (__f.put(*this, *this, this->fill(), __n).failed())
410 this->setstate(ios_base::badbit | ios_base::failbit);
412 #ifndef _LIBCPP_NO_EXCEPTIONS
416 this->__set_badbit_and_consider_rethrow();
418 #endif // _LIBCPP_NO_EXCEPTIONS
422 template <class _CharT, class _Traits>
423 basic_ostream<_CharT, _Traits>&
424 basic_ostream<_CharT, _Traits>::operator<<(short __n)
426 #ifndef _LIBCPP_NO_EXCEPTIONS
429 #endif // _LIBCPP_NO_EXCEPTIONS
433 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
434 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
435 const _Fp& __f = use_facet<_Fp>(this->getloc());
436 if (__f.put(*this, *this, this->fill(),
437 __flags == ios_base::oct || __flags == ios_base::hex ?
438 static_cast<long>(static_cast<unsigned short>(__n)) :
439 static_cast<long>(__n)).failed())
440 this->setstate(ios_base::badbit | ios_base::failbit);
442 #ifndef _LIBCPP_NO_EXCEPTIONS
446 this->__set_badbit_and_consider_rethrow();
448 #endif // _LIBCPP_NO_EXCEPTIONS
452 template <class _CharT, class _Traits>
453 basic_ostream<_CharT, _Traits>&
454 basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
456 #ifndef _LIBCPP_NO_EXCEPTIONS
459 #endif // _LIBCPP_NO_EXCEPTIONS
463 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
464 const _Fp& __f = use_facet<_Fp>(this->getloc());
465 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
466 this->setstate(ios_base::badbit | ios_base::failbit);
468 #ifndef _LIBCPP_NO_EXCEPTIONS
472 this->__set_badbit_and_consider_rethrow();
474 #endif // _LIBCPP_NO_EXCEPTIONS
478 template <class _CharT, class _Traits>
479 basic_ostream<_CharT, _Traits>&
480 basic_ostream<_CharT, _Traits>::operator<<(int __n)
482 #ifndef _LIBCPP_NO_EXCEPTIONS
485 #endif // _LIBCPP_NO_EXCEPTIONS
489 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
490 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
491 const _Fp& __f = use_facet<_Fp>(this->getloc());
492 if (__f.put(*this, *this, this->fill(),
493 __flags == ios_base::oct || __flags == ios_base::hex ?
494 static_cast<long>(static_cast<unsigned int>(__n)) :
495 static_cast<long>(__n)).failed())
496 this->setstate(ios_base::badbit | ios_base::failbit);
498 #ifndef _LIBCPP_NO_EXCEPTIONS
502 this->__set_badbit_and_consider_rethrow();
504 #endif // _LIBCPP_NO_EXCEPTIONS
508 template <class _CharT, class _Traits>
509 basic_ostream<_CharT, _Traits>&
510 basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
512 #ifndef _LIBCPP_NO_EXCEPTIONS
515 #endif // _LIBCPP_NO_EXCEPTIONS
519 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
520 const _Fp& __f = use_facet<_Fp>(this->getloc());
521 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
522 this->setstate(ios_base::badbit | ios_base::failbit);
524 #ifndef _LIBCPP_NO_EXCEPTIONS
528 this->__set_badbit_and_consider_rethrow();
530 #endif // _LIBCPP_NO_EXCEPTIONS
534 template <class _CharT, class _Traits>
535 basic_ostream<_CharT, _Traits>&
536 basic_ostream<_CharT, _Traits>::operator<<(long __n)
538 #ifndef _LIBCPP_NO_EXCEPTIONS
541 #endif // _LIBCPP_NO_EXCEPTIONS
545 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
546 const _Fp& __f = use_facet<_Fp>(this->getloc());
547 if (__f.put(*this, *this, this->fill(), __n).failed())
548 this->setstate(ios_base::badbit | ios_base::failbit);
550 #ifndef _LIBCPP_NO_EXCEPTIONS
554 this->__set_badbit_and_consider_rethrow();
556 #endif // _LIBCPP_NO_EXCEPTIONS
560 template <class _CharT, class _Traits>
561 basic_ostream<_CharT, _Traits>&
562 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
564 #ifndef _LIBCPP_NO_EXCEPTIONS
567 #endif // _LIBCPP_NO_EXCEPTIONS
571 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
572 const _Fp& __f = use_facet<_Fp>(this->getloc());
573 if (__f.put(*this, *this, this->fill(), __n).failed())
574 this->setstate(ios_base::badbit | ios_base::failbit);
576 #ifndef _LIBCPP_NO_EXCEPTIONS
580 this->__set_badbit_and_consider_rethrow();
582 #endif // _LIBCPP_NO_EXCEPTIONS
586 template <class _CharT, class _Traits>
587 basic_ostream<_CharT, _Traits>&
588 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
590 #ifndef _LIBCPP_NO_EXCEPTIONS
593 #endif // _LIBCPP_NO_EXCEPTIONS
597 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
598 const _Fp& __f = use_facet<_Fp>(this->getloc());
599 if (__f.put(*this, *this, this->fill(), __n).failed())
600 this->setstate(ios_base::badbit | ios_base::failbit);
602 #ifndef _LIBCPP_NO_EXCEPTIONS
606 this->__set_badbit_and_consider_rethrow();
608 #endif // _LIBCPP_NO_EXCEPTIONS
612 template <class _CharT, class _Traits>
613 basic_ostream<_CharT, _Traits>&
614 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
616 #ifndef _LIBCPP_NO_EXCEPTIONS
619 #endif // _LIBCPP_NO_EXCEPTIONS
623 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
624 const _Fp& __f = use_facet<_Fp>(this->getloc());
625 if (__f.put(*this, *this, this->fill(), __n).failed())
626 this->setstate(ios_base::badbit | ios_base::failbit);
628 #ifndef _LIBCPP_NO_EXCEPTIONS
632 this->__set_badbit_and_consider_rethrow();
634 #endif // _LIBCPP_NO_EXCEPTIONS
638 template <class _CharT, class _Traits>
639 basic_ostream<_CharT, _Traits>&
640 basic_ostream<_CharT, _Traits>::operator<<(float __n)
642 #ifndef _LIBCPP_NO_EXCEPTIONS
645 #endif // _LIBCPP_NO_EXCEPTIONS
649 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
650 const _Fp& __f = use_facet<_Fp>(this->getloc());
651 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
652 this->setstate(ios_base::badbit | ios_base::failbit);
654 #ifndef _LIBCPP_NO_EXCEPTIONS
658 this->__set_badbit_and_consider_rethrow();
660 #endif // _LIBCPP_NO_EXCEPTIONS
664 template <class _CharT, class _Traits>
665 basic_ostream<_CharT, _Traits>&
666 basic_ostream<_CharT, _Traits>::operator<<(double __n)
668 #ifndef _LIBCPP_NO_EXCEPTIONS
671 #endif // _LIBCPP_NO_EXCEPTIONS
675 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
676 const _Fp& __f = use_facet<_Fp>(this->getloc());
677 if (__f.put(*this, *this, this->fill(), __n).failed())
678 this->setstate(ios_base::badbit | ios_base::failbit);
680 #ifndef _LIBCPP_NO_EXCEPTIONS
684 this->__set_badbit_and_consider_rethrow();
686 #endif // _LIBCPP_NO_EXCEPTIONS
690 template <class _CharT, class _Traits>
691 basic_ostream<_CharT, _Traits>&
692 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
694 #ifndef _LIBCPP_NO_EXCEPTIONS
697 #endif // _LIBCPP_NO_EXCEPTIONS
701 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
702 const _Fp& __f = use_facet<_Fp>(this->getloc());
703 if (__f.put(*this, *this, this->fill(), __n).failed())
704 this->setstate(ios_base::badbit | ios_base::failbit);
706 #ifndef _LIBCPP_NO_EXCEPTIONS
710 this->__set_badbit_and_consider_rethrow();
712 #endif // _LIBCPP_NO_EXCEPTIONS
716 template <class _CharT, class _Traits>
717 basic_ostream<_CharT, _Traits>&
718 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
720 #ifndef _LIBCPP_NO_EXCEPTIONS
723 #endif // _LIBCPP_NO_EXCEPTIONS
727 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
728 const _Fp& __f = use_facet<_Fp>(this->getloc());
729 if (__f.put(*this, *this, this->fill(), __n).failed())
730 this->setstate(ios_base::badbit | ios_base::failbit);
732 #ifndef _LIBCPP_NO_EXCEPTIONS
736 this->__set_badbit_and_consider_rethrow();
738 #endif // _LIBCPP_NO_EXCEPTIONS
742 template<class _CharT, class _Traits>
743 basic_ostream<_CharT, _Traits>&
744 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
745 const _CharT* __str, size_t __len)
747 #ifndef _LIBCPP_NO_EXCEPTIONS
750 #endif // _LIBCPP_NO_EXCEPTIONS
751 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
754 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
755 if (__pad_and_output(_Ip(__os),
757 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
762 __os.fill()).failed())
763 __os.setstate(ios_base::badbit | ios_base::failbit);
765 #ifndef _LIBCPP_NO_EXCEPTIONS
769 __os.__set_badbit_and_consider_rethrow();
771 #endif // _LIBCPP_NO_EXCEPTIONS
776 template<class _CharT, class _Traits>
777 basic_ostream<_CharT, _Traits>&
778 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
780 return _VSTD::__put_character_sequence(__os, &__c, 1);
783 template<class _CharT, class _Traits>
784 basic_ostream<_CharT, _Traits>&
785 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
787 #ifndef _LIBCPP_NO_EXCEPTIONS
790 #endif // _LIBCPP_NO_EXCEPTIONS
791 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
794 _CharT __c = __os.widen(__cn);
795 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
796 if (__pad_and_output(_Ip(__os),
798 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
803 __os.fill()).failed())
804 __os.setstate(ios_base::badbit | ios_base::failbit);
806 #ifndef _LIBCPP_NO_EXCEPTIONS
810 __os.__set_badbit_and_consider_rethrow();
812 #endif // _LIBCPP_NO_EXCEPTIONS
816 template<class _Traits>
817 basic_ostream<char, _Traits>&
818 operator<<(basic_ostream<char, _Traits>& __os, char __c)
820 return _VSTD::__put_character_sequence(__os, &__c, 1);
823 template<class _Traits>
824 basic_ostream<char, _Traits>&
825 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
827 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
830 template<class _Traits>
831 basic_ostream<char, _Traits>&
832 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
834 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
837 template<class _CharT, class _Traits>
838 basic_ostream<_CharT, _Traits>&
839 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
841 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
844 template<class _CharT, class _Traits>
845 basic_ostream<_CharT, _Traits>&
846 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
848 #ifndef _LIBCPP_NO_EXCEPTIONS
851 #endif // _LIBCPP_NO_EXCEPTIONS
852 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
855 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
856 size_t __len = char_traits<char>::length(__strn);
857 const int __bs = 100;
859 _CharT* __wb = __wbb;
860 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
863 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
868 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
869 *__p = __os.widen(*__strn);
870 if (__pad_and_output(_Ip(__os),
872 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
877 __os.fill()).failed())
878 __os.setstate(ios_base::badbit | ios_base::failbit);
880 #ifndef _LIBCPP_NO_EXCEPTIONS
884 __os.__set_badbit_and_consider_rethrow();
886 #endif // _LIBCPP_NO_EXCEPTIONS
890 template<class _Traits>
891 basic_ostream<char, _Traits>&
892 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
894 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
897 template<class _Traits>
898 basic_ostream<char, _Traits>&
899 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
901 const char *__s = (const char *) __str;
902 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
905 template<class _Traits>
906 basic_ostream<char, _Traits>&
907 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
909 const char *__s = (const char *) __str;
910 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
913 template <class _CharT, class _Traits>
914 basic_ostream<_CharT, _Traits>&
915 basic_ostream<_CharT, _Traits>::put(char_type __c)
917 #ifndef _LIBCPP_NO_EXCEPTIONS
920 #endif // _LIBCPP_NO_EXCEPTIONS
924 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
928 this->setstate(ios_base::badbit);
930 #ifndef _LIBCPP_NO_EXCEPTIONS
934 this->__set_badbit_and_consider_rethrow();
936 #endif // _LIBCPP_NO_EXCEPTIONS
940 template <class _CharT, class _Traits>
941 basic_ostream<_CharT, _Traits>&
942 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
944 #ifndef _LIBCPP_NO_EXCEPTIONS
947 #endif // _LIBCPP_NO_EXCEPTIONS
951 if (this->rdbuf()->sputn(__s, __n) != __n)
952 this->setstate(ios_base::badbit);
954 #ifndef _LIBCPP_NO_EXCEPTIONS
958 this->__set_badbit_and_consider_rethrow();
960 #endif // _LIBCPP_NO_EXCEPTIONS
964 template <class _CharT, class _Traits>
965 basic_ostream<_CharT, _Traits>&
966 basic_ostream<_CharT, _Traits>::flush()
968 #ifndef _LIBCPP_NO_EXCEPTIONS
971 #endif // _LIBCPP_NO_EXCEPTIONS
977 if (this->rdbuf()->pubsync() == -1)
978 this->setstate(ios_base::badbit);
981 #ifndef _LIBCPP_NO_EXCEPTIONS
985 this->__set_badbit_and_consider_rethrow();
987 #endif // _LIBCPP_NO_EXCEPTIONS
991 template <class _CharT, class _Traits>
992 inline _LIBCPP_INLINE_VISIBILITY
993 typename basic_ostream<_CharT, _Traits>::pos_type
994 basic_ostream<_CharT, _Traits>::tellp()
998 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
1001 template <class _CharT, class _Traits>
1002 inline _LIBCPP_INLINE_VISIBILITY
1003 basic_ostream<_CharT, _Traits>&
1004 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
1009 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
1010 this->setstate(ios_base::failbit);
1015 template <class _CharT, class _Traits>
1016 inline _LIBCPP_INLINE_VISIBILITY
1017 basic_ostream<_CharT, _Traits>&
1018 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
1023 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
1024 this->setstate(ios_base::failbit);
1029 template <class _CharT, class _Traits>
1030 inline _LIBCPP_INLINE_VISIBILITY
1031 basic_ostream<_CharT, _Traits>&
1032 endl(basic_ostream<_CharT, _Traits>& __os)
1034 __os.put(__os.widen('\n'));
1039 template <class _CharT, class _Traits>
1040 inline _LIBCPP_INLINE_VISIBILITY
1041 basic_ostream<_CharT, _Traits>&
1042 ends(basic_ostream<_CharT, _Traits>& __os)
1048 template <class _CharT, class _Traits>
1049 inline _LIBCPP_INLINE_VISIBILITY
1050 basic_ostream<_CharT, _Traits>&
1051 flush(basic_ostream<_CharT, _Traits>& __os)
1057 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1059 template <class _Stream, class _Tp>
1060 inline _LIBCPP_INLINE_VISIBILITY
1063 !is_lvalue_reference<_Stream>::value &&
1064 is_base_of<ios_base, _Stream>::value,
1067 operator<<(_Stream&& __os, const _Tp& __x)
1070 return _VSTD::move(__os);
1073 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1075 template<class _CharT, class _Traits, class _Allocator>
1076 basic_ostream<_CharT, _Traits>&
1077 operator<<(basic_ostream<_CharT, _Traits>& __os,
1078 const basic_string<_CharT, _Traits, _Allocator>& __str)
1080 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
1083 template <class _CharT, class _Traits>
1084 inline _LIBCPP_INLINE_VISIBILITY
1085 basic_ostream<_CharT, _Traits>&
1086 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1088 return __os << __ec.category().name() << ':' << __ec.value();
1091 template<class _CharT, class _Traits, class _Yp>
1092 inline _LIBCPP_INLINE_VISIBILITY
1093 basic_ostream<_CharT, _Traits>&
1094 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1096 return __os << __p.get();
1099 template <class _CharT, class _Traits, size_t _Size>
1100 basic_ostream<_CharT, _Traits>&
1101 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1103 return __os << __x.template to_string<_CharT, _Traits>
1104 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1105 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1108 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<char>)
1109 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream<wchar_t>)
1111 _LIBCPP_END_NAMESPACE_STD
1113 #endif // _LIBCPP_OSTREAM