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_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_EXTERN_TEMPLATE_INLINE_VISIBILITY
164 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
165 { this->init(__sb); }
166 virtual ~basic_ostream();
168 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
169 inline _LIBCPP_INLINE_VISIBILITY
170 basic_ostream(basic_ostream&& __rhs);
173 // 27.7.2.3 Assign/swap
174 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
175 inline _LIBCPP_INLINE_VISIBILITY
176 basic_ostream& operator=(basic_ostream&& __rhs);
178 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
179 void swap(basic_ostream& __rhs)
180 { basic_ios<char_type, traits_type>::swap(__rhs); }
182 #ifndef _LIBCPP_CXX03_LANG
183 basic_ostream (const basic_ostream& __rhs) = delete;
184 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
186 basic_ostream (const basic_ostream& __rhs); // not defined
187 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
191 // 27.7.2.4 Prefix/suffix:
192 class _LIBCPP_TEMPLATE_VIS sentry;
194 // 27.7.2.6 Formatted output:
195 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
196 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
197 { return __pf(*this); }
199 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
200 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
201 (*__pf)(basic_ios<char_type,traits_type>&))
202 { __pf(*this); return *this; }
204 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
205 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
206 { __pf(*this); return *this; }
208 basic_ostream& operator<<(bool __n);
209 basic_ostream& operator<<(short __n);
210 basic_ostream& operator<<(unsigned short __n);
211 basic_ostream& operator<<(int __n);
212 basic_ostream& operator<<(unsigned int __n);
213 basic_ostream& operator<<(long __n);
214 basic_ostream& operator<<(unsigned long __n);
215 basic_ostream& operator<<(long long __n);
216 basic_ostream& operator<<(unsigned long long __n);
217 basic_ostream& operator<<(float __f);
218 basic_ostream& operator<<(double __f);
219 basic_ostream& operator<<(long double __f);
220 basic_ostream& operator<<(const void* __p);
221 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
223 // 27.7.2.7 Unformatted output:
224 basic_ostream& put(char_type __c);
225 basic_ostream& write(const char_type* __s, streamsize __n);
226 basic_ostream& flush();
229 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
231 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
232 basic_ostream& seekp(pos_type __pos);
233 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
234 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
237 _LIBCPP_ALWAYS_INLINE
238 basic_ostream() {} // extension, intentially does not initialize
241 template <class _CharT, class _Traits>
242 class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
245 basic_ostream<_CharT, _Traits>& __os_;
247 sentry(const sentry&); // = delete;
248 sentry& operator=(const sentry&); // = delete;
251 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
254 _LIBCPP_ALWAYS_INLINE
256 operator bool() const {return __ok_;}
259 template <class _CharT, class _Traits>
260 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
272 template <class _CharT, class _Traits>
273 basic_ostream<_CharT, _Traits>::sentry::~sentry()
275 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
276 && !uncaught_exception())
278 #ifndef _LIBCPP_NO_EXCEPTIONS
281 #endif // _LIBCPP_NO_EXCEPTIONS
282 if (__os_.rdbuf()->pubsync() == -1)
283 __os_.setstate(ios_base::badbit);
284 #ifndef _LIBCPP_NO_EXCEPTIONS
289 #endif // _LIBCPP_NO_EXCEPTIONS
293 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
295 template <class _CharT, class _Traits>
296 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
301 template <class _CharT, class _Traits>
302 basic_ostream<_CharT, _Traits>&
303 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
309 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
311 template <class _CharT, class _Traits>
312 basic_ostream<_CharT, _Traits>::~basic_ostream()
316 template <class _CharT, class _Traits>
317 basic_ostream<_CharT, _Traits>&
318 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
320 #ifndef _LIBCPP_NO_EXCEPTIONS
323 #endif // _LIBCPP_NO_EXCEPTIONS
329 #ifndef _LIBCPP_NO_EXCEPTIONS
332 #endif // _LIBCPP_NO_EXCEPTIONS
333 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
334 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
339 for (; __i != __eof; ++__i, ++__o, ++__c)
346 this->setstate(ios_base::failbit);
347 #ifndef _LIBCPP_NO_EXCEPTIONS
351 this->__set_failbit_and_consider_rethrow();
353 #endif // _LIBCPP_NO_EXCEPTIONS
356 this->setstate(ios_base::badbit);
358 #ifndef _LIBCPP_NO_EXCEPTIONS
362 this->__set_badbit_and_consider_rethrow();
364 #endif // _LIBCPP_NO_EXCEPTIONS
368 template <class _CharT, class _Traits>
369 basic_ostream<_CharT, _Traits>&
370 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
372 #ifndef _LIBCPP_NO_EXCEPTIONS
375 #endif // _LIBCPP_NO_EXCEPTIONS
379 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
380 const _Fp& __f = use_facet<_Fp>(this->getloc());
381 if (__f.put(*this, *this, this->fill(), __n).failed())
382 this->setstate(ios_base::badbit | ios_base::failbit);
384 #ifndef _LIBCPP_NO_EXCEPTIONS
388 this->__set_badbit_and_consider_rethrow();
390 #endif // _LIBCPP_NO_EXCEPTIONS
394 template <class _CharT, class _Traits>
395 basic_ostream<_CharT, _Traits>&
396 basic_ostream<_CharT, _Traits>::operator<<(short __n)
398 #ifndef _LIBCPP_NO_EXCEPTIONS
401 #endif // _LIBCPP_NO_EXCEPTIONS
405 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
406 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
407 const _Fp& __f = use_facet<_Fp>(this->getloc());
408 if (__f.put(*this, *this, this->fill(),
409 __flags == ios_base::oct || __flags == ios_base::hex ?
410 static_cast<long>(static_cast<unsigned short>(__n)) :
411 static_cast<long>(__n)).failed())
412 this->setstate(ios_base::badbit | ios_base::failbit);
414 #ifndef _LIBCPP_NO_EXCEPTIONS
418 this->__set_badbit_and_consider_rethrow();
420 #endif // _LIBCPP_NO_EXCEPTIONS
424 template <class _CharT, class _Traits>
425 basic_ostream<_CharT, _Traits>&
426 basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
428 #ifndef _LIBCPP_NO_EXCEPTIONS
431 #endif // _LIBCPP_NO_EXCEPTIONS
435 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
436 const _Fp& __f = use_facet<_Fp>(this->getloc());
437 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
438 this->setstate(ios_base::badbit | ios_base::failbit);
440 #ifndef _LIBCPP_NO_EXCEPTIONS
444 this->__set_badbit_and_consider_rethrow();
446 #endif // _LIBCPP_NO_EXCEPTIONS
450 template <class _CharT, class _Traits>
451 basic_ostream<_CharT, _Traits>&
452 basic_ostream<_CharT, _Traits>::operator<<(int __n)
454 #ifndef _LIBCPP_NO_EXCEPTIONS
457 #endif // _LIBCPP_NO_EXCEPTIONS
461 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
462 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
463 const _Fp& __f = use_facet<_Fp>(this->getloc());
464 if (__f.put(*this, *this, this->fill(),
465 __flags == ios_base::oct || __flags == ios_base::hex ?
466 static_cast<long>(static_cast<unsigned int>(__n)) :
467 static_cast<long>(__n)).failed())
468 this->setstate(ios_base::badbit | ios_base::failbit);
470 #ifndef _LIBCPP_NO_EXCEPTIONS
474 this->__set_badbit_and_consider_rethrow();
476 #endif // _LIBCPP_NO_EXCEPTIONS
480 template <class _CharT, class _Traits>
481 basic_ostream<_CharT, _Traits>&
482 basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
484 #ifndef _LIBCPP_NO_EXCEPTIONS
487 #endif // _LIBCPP_NO_EXCEPTIONS
491 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
492 const _Fp& __f = use_facet<_Fp>(this->getloc());
493 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
494 this->setstate(ios_base::badbit | ios_base::failbit);
496 #ifndef _LIBCPP_NO_EXCEPTIONS
500 this->__set_badbit_and_consider_rethrow();
502 #endif // _LIBCPP_NO_EXCEPTIONS
506 template <class _CharT, class _Traits>
507 basic_ostream<_CharT, _Traits>&
508 basic_ostream<_CharT, _Traits>::operator<<(long __n)
510 #ifndef _LIBCPP_NO_EXCEPTIONS
513 #endif // _LIBCPP_NO_EXCEPTIONS
517 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
518 const _Fp& __f = use_facet<_Fp>(this->getloc());
519 if (__f.put(*this, *this, this->fill(), __n).failed())
520 this->setstate(ios_base::badbit | ios_base::failbit);
522 #ifndef _LIBCPP_NO_EXCEPTIONS
526 this->__set_badbit_and_consider_rethrow();
528 #endif // _LIBCPP_NO_EXCEPTIONS
532 template <class _CharT, class _Traits>
533 basic_ostream<_CharT, _Traits>&
534 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
536 #ifndef _LIBCPP_NO_EXCEPTIONS
539 #endif // _LIBCPP_NO_EXCEPTIONS
543 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
544 const _Fp& __f = use_facet<_Fp>(this->getloc());
545 if (__f.put(*this, *this, this->fill(), __n).failed())
546 this->setstate(ios_base::badbit | ios_base::failbit);
548 #ifndef _LIBCPP_NO_EXCEPTIONS
552 this->__set_badbit_and_consider_rethrow();
554 #endif // _LIBCPP_NO_EXCEPTIONS
558 template <class _CharT, class _Traits>
559 basic_ostream<_CharT, _Traits>&
560 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
562 #ifndef _LIBCPP_NO_EXCEPTIONS
565 #endif // _LIBCPP_NO_EXCEPTIONS
569 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
570 const _Fp& __f = use_facet<_Fp>(this->getloc());
571 if (__f.put(*this, *this, this->fill(), __n).failed())
572 this->setstate(ios_base::badbit | ios_base::failbit);
574 #ifndef _LIBCPP_NO_EXCEPTIONS
578 this->__set_badbit_and_consider_rethrow();
580 #endif // _LIBCPP_NO_EXCEPTIONS
584 template <class _CharT, class _Traits>
585 basic_ostream<_CharT, _Traits>&
586 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
588 #ifndef _LIBCPP_NO_EXCEPTIONS
591 #endif // _LIBCPP_NO_EXCEPTIONS
595 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
596 const _Fp& __f = use_facet<_Fp>(this->getloc());
597 if (__f.put(*this, *this, this->fill(), __n).failed())
598 this->setstate(ios_base::badbit | ios_base::failbit);
600 #ifndef _LIBCPP_NO_EXCEPTIONS
604 this->__set_badbit_and_consider_rethrow();
606 #endif // _LIBCPP_NO_EXCEPTIONS
610 template <class _CharT, class _Traits>
611 basic_ostream<_CharT, _Traits>&
612 basic_ostream<_CharT, _Traits>::operator<<(float __n)
614 #ifndef _LIBCPP_NO_EXCEPTIONS
617 #endif // _LIBCPP_NO_EXCEPTIONS
621 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
622 const _Fp& __f = use_facet<_Fp>(this->getloc());
623 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
624 this->setstate(ios_base::badbit | ios_base::failbit);
626 #ifndef _LIBCPP_NO_EXCEPTIONS
630 this->__set_badbit_and_consider_rethrow();
632 #endif // _LIBCPP_NO_EXCEPTIONS
636 template <class _CharT, class _Traits>
637 basic_ostream<_CharT, _Traits>&
638 basic_ostream<_CharT, _Traits>::operator<<(double __n)
640 #ifndef _LIBCPP_NO_EXCEPTIONS
643 #endif // _LIBCPP_NO_EXCEPTIONS
647 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
648 const _Fp& __f = use_facet<_Fp>(this->getloc());
649 if (__f.put(*this, *this, this->fill(), __n).failed())
650 this->setstate(ios_base::badbit | ios_base::failbit);
652 #ifndef _LIBCPP_NO_EXCEPTIONS
656 this->__set_badbit_and_consider_rethrow();
658 #endif // _LIBCPP_NO_EXCEPTIONS
662 template <class _CharT, class _Traits>
663 basic_ostream<_CharT, _Traits>&
664 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
666 #ifndef _LIBCPP_NO_EXCEPTIONS
669 #endif // _LIBCPP_NO_EXCEPTIONS
673 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
674 const _Fp& __f = use_facet<_Fp>(this->getloc());
675 if (__f.put(*this, *this, this->fill(), __n).failed())
676 this->setstate(ios_base::badbit | ios_base::failbit);
678 #ifndef _LIBCPP_NO_EXCEPTIONS
682 this->__set_badbit_and_consider_rethrow();
684 #endif // _LIBCPP_NO_EXCEPTIONS
688 template <class _CharT, class _Traits>
689 basic_ostream<_CharT, _Traits>&
690 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
692 #ifndef _LIBCPP_NO_EXCEPTIONS
695 #endif // _LIBCPP_NO_EXCEPTIONS
699 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
700 const _Fp& __f = use_facet<_Fp>(this->getloc());
701 if (__f.put(*this, *this, this->fill(), __n).failed())
702 this->setstate(ios_base::badbit | ios_base::failbit);
704 #ifndef _LIBCPP_NO_EXCEPTIONS
708 this->__set_badbit_and_consider_rethrow();
710 #endif // _LIBCPP_NO_EXCEPTIONS
714 template<class _CharT, class _Traits>
715 basic_ostream<_CharT, _Traits>&
716 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
717 const _CharT* __str, size_t __len)
719 #ifndef _LIBCPP_NO_EXCEPTIONS
722 #endif // _LIBCPP_NO_EXCEPTIONS
723 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
726 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
727 if (__pad_and_output(_Ip(__os),
729 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
734 __os.fill()).failed())
735 __os.setstate(ios_base::badbit | ios_base::failbit);
737 #ifndef _LIBCPP_NO_EXCEPTIONS
741 __os.__set_badbit_and_consider_rethrow();
743 #endif // _LIBCPP_NO_EXCEPTIONS
748 template<class _CharT, class _Traits>
749 basic_ostream<_CharT, _Traits>&
750 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
752 return _VSTD::__put_character_sequence(__os, &__c, 1);
755 template<class _CharT, class _Traits>
756 basic_ostream<_CharT, _Traits>&
757 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
759 #ifndef _LIBCPP_NO_EXCEPTIONS
762 #endif // _LIBCPP_NO_EXCEPTIONS
763 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
766 _CharT __c = __os.widen(__cn);
767 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
768 if (__pad_and_output(_Ip(__os),
770 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
775 __os.fill()).failed())
776 __os.setstate(ios_base::badbit | ios_base::failbit);
778 #ifndef _LIBCPP_NO_EXCEPTIONS
782 __os.__set_badbit_and_consider_rethrow();
784 #endif // _LIBCPP_NO_EXCEPTIONS
788 template<class _Traits>
789 basic_ostream<char, _Traits>&
790 operator<<(basic_ostream<char, _Traits>& __os, char __c)
792 return _VSTD::__put_character_sequence(__os, &__c, 1);
795 template<class _Traits>
796 basic_ostream<char, _Traits>&
797 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
799 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
802 template<class _Traits>
803 basic_ostream<char, _Traits>&
804 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
806 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
809 template<class _CharT, class _Traits>
810 basic_ostream<_CharT, _Traits>&
811 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
813 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
816 template<class _CharT, class _Traits>
817 basic_ostream<_CharT, _Traits>&
818 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
820 #ifndef _LIBCPP_NO_EXCEPTIONS
823 #endif // _LIBCPP_NO_EXCEPTIONS
824 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
827 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
828 size_t __len = char_traits<char>::length(__strn);
829 const int __bs = 100;
831 _CharT* __wb = __wbb;
832 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
835 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
840 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
841 *__p = __os.widen(*__strn);
842 if (__pad_and_output(_Ip(__os),
844 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
849 __os.fill()).failed())
850 __os.setstate(ios_base::badbit | ios_base::failbit);
852 #ifndef _LIBCPP_NO_EXCEPTIONS
856 __os.__set_badbit_and_consider_rethrow();
858 #endif // _LIBCPP_NO_EXCEPTIONS
862 template<class _Traits>
863 basic_ostream<char, _Traits>&
864 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
866 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
869 template<class _Traits>
870 basic_ostream<char, _Traits>&
871 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
873 const char *__s = (const char *) __str;
874 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
877 template<class _Traits>
878 basic_ostream<char, _Traits>&
879 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
881 const char *__s = (const char *) __str;
882 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
885 template <class _CharT, class _Traits>
886 basic_ostream<_CharT, _Traits>&
887 basic_ostream<_CharT, _Traits>::put(char_type __c)
889 #ifndef _LIBCPP_NO_EXCEPTIONS
892 #endif // _LIBCPP_NO_EXCEPTIONS
896 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
900 this->setstate(ios_base::badbit);
902 #ifndef _LIBCPP_NO_EXCEPTIONS
906 this->__set_badbit_and_consider_rethrow();
908 #endif // _LIBCPP_NO_EXCEPTIONS
912 template <class _CharT, class _Traits>
913 basic_ostream<_CharT, _Traits>&
914 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
916 #ifndef _LIBCPP_NO_EXCEPTIONS
919 #endif // _LIBCPP_NO_EXCEPTIONS
923 if (this->rdbuf()->sputn(__s, __n) != __n)
924 this->setstate(ios_base::badbit);
926 #ifndef _LIBCPP_NO_EXCEPTIONS
930 this->__set_badbit_and_consider_rethrow();
932 #endif // _LIBCPP_NO_EXCEPTIONS
936 template <class _CharT, class _Traits>
937 basic_ostream<_CharT, _Traits>&
938 basic_ostream<_CharT, _Traits>::flush()
940 #ifndef _LIBCPP_NO_EXCEPTIONS
943 #endif // _LIBCPP_NO_EXCEPTIONS
949 if (this->rdbuf()->pubsync() == -1)
950 this->setstate(ios_base::badbit);
953 #ifndef _LIBCPP_NO_EXCEPTIONS
957 this->__set_badbit_and_consider_rethrow();
959 #endif // _LIBCPP_NO_EXCEPTIONS
963 template <class _CharT, class _Traits>
964 typename basic_ostream<_CharT, _Traits>::pos_type
965 basic_ostream<_CharT, _Traits>::tellp()
969 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
972 template <class _CharT, class _Traits>
973 basic_ostream<_CharT, _Traits>&
974 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
979 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
980 this->setstate(ios_base::failbit);
985 template <class _CharT, class _Traits>
986 basic_ostream<_CharT, _Traits>&
987 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
992 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
993 this->setstate(ios_base::failbit);
998 template <class _CharT, class _Traits>
999 inline _LIBCPP_INLINE_VISIBILITY
1000 basic_ostream<_CharT, _Traits>&
1001 endl(basic_ostream<_CharT, _Traits>& __os)
1003 __os.put(__os.widen('\n'));
1008 template <class _CharT, class _Traits>
1009 inline _LIBCPP_INLINE_VISIBILITY
1010 basic_ostream<_CharT, _Traits>&
1011 ends(basic_ostream<_CharT, _Traits>& __os)
1017 template <class _CharT, class _Traits>
1018 inline _LIBCPP_INLINE_VISIBILITY
1019 basic_ostream<_CharT, _Traits>&
1020 flush(basic_ostream<_CharT, _Traits>& __os)
1026 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1028 template <class _Stream, class _Tp>
1029 inline _LIBCPP_INLINE_VISIBILITY
1032 !is_lvalue_reference<_Stream>::value &&
1033 is_base_of<ios_base, _Stream>::value,
1036 operator<<(_Stream&& __os, const _Tp& __x)
1039 return _VSTD::move(__os);
1042 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1044 template<class _CharT, class _Traits, class _Allocator>
1045 basic_ostream<_CharT, _Traits>&
1046 operator<<(basic_ostream<_CharT, _Traits>& __os,
1047 const basic_string<_CharT, _Traits, _Allocator>& __str)
1049 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
1052 template<class _CharT, class _Traits>
1053 basic_ostream<_CharT, _Traits>&
1054 operator<<(basic_ostream<_CharT, _Traits>& __os,
1055 const basic_string_view<_CharT, _Traits> __sv)
1057 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1060 template <class _CharT, class _Traits>
1061 inline _LIBCPP_INLINE_VISIBILITY
1062 basic_ostream<_CharT, _Traits>&
1063 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1065 return __os << __ec.category().name() << ':' << __ec.value();
1068 template<class _CharT, class _Traits, class _Yp>
1069 inline _LIBCPP_INLINE_VISIBILITY
1070 basic_ostream<_CharT, _Traits>&
1071 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1073 return __os << __p.get();
1076 template <class _CharT, class _Traits, size_t _Size>
1077 basic_ostream<_CharT, _Traits>&
1078 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1080 return __os << __x.template to_string<_CharT, _Traits>
1081 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1082 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1085 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1086 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
1088 _LIBCPP_END_NAMESPACE_STD
1090 #endif // _LIBCPP_OSTREAM