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_CXX03_LANG
169 inline _LIBCPP_INLINE_VISIBILITY
170 basic_ostream(basic_ostream&& __rhs);
172 // 27.7.2.3 Assign/swap
173 inline _LIBCPP_INLINE_VISIBILITY
174 basic_ostream& operator=(basic_ostream&& __rhs);
176 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
177 void swap(basic_ostream& __rhs)
178 { basic_ios<char_type, traits_type>::swap(__rhs); }
180 #ifndef _LIBCPP_CXX03_LANG
181 basic_ostream (const basic_ostream& __rhs) = delete;
182 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
184 basic_ostream (const basic_ostream& __rhs); // not defined
185 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
189 // 27.7.2.4 Prefix/suffix:
190 class _LIBCPP_TEMPLATE_VIS sentry;
192 // 27.7.2.6 Formatted output:
193 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
194 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
195 { return __pf(*this); }
197 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
198 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
199 (*__pf)(basic_ios<char_type,traits_type>&))
200 { __pf(*this); return *this; }
202 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
203 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
204 { __pf(*this); return *this; }
206 basic_ostream& operator<<(bool __n);
207 basic_ostream& operator<<(short __n);
208 basic_ostream& operator<<(unsigned short __n);
209 basic_ostream& operator<<(int __n);
210 basic_ostream& operator<<(unsigned int __n);
211 basic_ostream& operator<<(long __n);
212 basic_ostream& operator<<(unsigned long __n);
213 basic_ostream& operator<<(long long __n);
214 basic_ostream& operator<<(unsigned long long __n);
215 basic_ostream& operator<<(float __f);
216 basic_ostream& operator<<(double __f);
217 basic_ostream& operator<<(long double __f);
218 basic_ostream& operator<<(const void* __p);
219 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
221 // 27.7.2.7 Unformatted output:
222 basic_ostream& put(char_type __c);
223 basic_ostream& write(const char_type* __s, streamsize __n);
224 basic_ostream& flush();
227 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
229 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
230 basic_ostream& seekp(pos_type __pos);
231 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
232 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
235 _LIBCPP_ALWAYS_INLINE
236 basic_ostream() {} // extension, intentially does not initialize
239 template <class _CharT, class _Traits>
240 class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
243 basic_ostream<_CharT, _Traits>& __os_;
245 sentry(const sentry&); // = delete;
246 sentry& operator=(const sentry&); // = delete;
249 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
252 _LIBCPP_ALWAYS_INLINE
254 operator bool() const {return __ok_;}
257 template <class _CharT, class _Traits>
258 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
270 template <class _CharT, class _Traits>
271 basic_ostream<_CharT, _Traits>::sentry::~sentry()
273 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
274 && !uncaught_exception())
276 #ifndef _LIBCPP_NO_EXCEPTIONS
279 #endif // _LIBCPP_NO_EXCEPTIONS
280 if (__os_.rdbuf()->pubsync() == -1)
281 __os_.setstate(ios_base::badbit);
282 #ifndef _LIBCPP_NO_EXCEPTIONS
287 #endif // _LIBCPP_NO_EXCEPTIONS
291 #ifndef _LIBCPP_CXX03_LANG
293 template <class _CharT, class _Traits>
294 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
299 template <class _CharT, class _Traits>
300 basic_ostream<_CharT, _Traits>&
301 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
307 #endif // _LIBCPP_CXX03_LANG
309 template <class _CharT, class _Traits>
310 basic_ostream<_CharT, _Traits>::~basic_ostream()
314 template <class _CharT, class _Traits>
315 basic_ostream<_CharT, _Traits>&
316 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
318 #ifndef _LIBCPP_NO_EXCEPTIONS
321 #endif // _LIBCPP_NO_EXCEPTIONS
327 #ifndef _LIBCPP_NO_EXCEPTIONS
330 #endif // _LIBCPP_NO_EXCEPTIONS
331 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
332 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
337 for (; __i != __eof; ++__i, ++__o, ++__c)
344 this->setstate(ios_base::failbit);
345 #ifndef _LIBCPP_NO_EXCEPTIONS
349 this->__set_failbit_and_consider_rethrow();
351 #endif // _LIBCPP_NO_EXCEPTIONS
354 this->setstate(ios_base::badbit);
356 #ifndef _LIBCPP_NO_EXCEPTIONS
360 this->__set_badbit_and_consider_rethrow();
362 #endif // _LIBCPP_NO_EXCEPTIONS
366 template <class _CharT, class _Traits>
367 basic_ostream<_CharT, _Traits>&
368 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
370 #ifndef _LIBCPP_NO_EXCEPTIONS
373 #endif // _LIBCPP_NO_EXCEPTIONS
377 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
378 const _Fp& __f = use_facet<_Fp>(this->getloc());
379 if (__f.put(*this, *this, this->fill(), __n).failed())
380 this->setstate(ios_base::badbit | ios_base::failbit);
382 #ifndef _LIBCPP_NO_EXCEPTIONS
386 this->__set_badbit_and_consider_rethrow();
388 #endif // _LIBCPP_NO_EXCEPTIONS
392 template <class _CharT, class _Traits>
393 basic_ostream<_CharT, _Traits>&
394 basic_ostream<_CharT, _Traits>::operator<<(short __n)
396 #ifndef _LIBCPP_NO_EXCEPTIONS
399 #endif // _LIBCPP_NO_EXCEPTIONS
403 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
404 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
405 const _Fp& __f = use_facet<_Fp>(this->getloc());
406 if (__f.put(*this, *this, this->fill(),
407 __flags == ios_base::oct || __flags == ios_base::hex ?
408 static_cast<long>(static_cast<unsigned short>(__n)) :
409 static_cast<long>(__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<<(unsigned short __n)
426 #ifndef _LIBCPP_NO_EXCEPTIONS
429 #endif // _LIBCPP_NO_EXCEPTIONS
433 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
434 const _Fp& __f = use_facet<_Fp>(this->getloc());
435 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
436 this->setstate(ios_base::badbit | ios_base::failbit);
438 #ifndef _LIBCPP_NO_EXCEPTIONS
442 this->__set_badbit_and_consider_rethrow();
444 #endif // _LIBCPP_NO_EXCEPTIONS
448 template <class _CharT, class _Traits>
449 basic_ostream<_CharT, _Traits>&
450 basic_ostream<_CharT, _Traits>::operator<<(int __n)
452 #ifndef _LIBCPP_NO_EXCEPTIONS
455 #endif // _LIBCPP_NO_EXCEPTIONS
459 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
460 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
461 const _Fp& __f = use_facet<_Fp>(this->getloc());
462 if (__f.put(*this, *this, this->fill(),
463 __flags == ios_base::oct || __flags == ios_base::hex ?
464 static_cast<long>(static_cast<unsigned int>(__n)) :
465 static_cast<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<<(unsigned int __n)
482 #ifndef _LIBCPP_NO_EXCEPTIONS
485 #endif // _LIBCPP_NO_EXCEPTIONS
489 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
490 const _Fp& __f = use_facet<_Fp>(this->getloc());
491 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
492 this->setstate(ios_base::badbit | ios_base::failbit);
494 #ifndef _LIBCPP_NO_EXCEPTIONS
498 this->__set_badbit_and_consider_rethrow();
500 #endif // _LIBCPP_NO_EXCEPTIONS
504 template <class _CharT, class _Traits>
505 basic_ostream<_CharT, _Traits>&
506 basic_ostream<_CharT, _Traits>::operator<<(long __n)
508 #ifndef _LIBCPP_NO_EXCEPTIONS
511 #endif // _LIBCPP_NO_EXCEPTIONS
515 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
516 const _Fp& __f = use_facet<_Fp>(this->getloc());
517 if (__f.put(*this, *this, this->fill(), __n).failed())
518 this->setstate(ios_base::badbit | ios_base::failbit);
520 #ifndef _LIBCPP_NO_EXCEPTIONS
524 this->__set_badbit_and_consider_rethrow();
526 #endif // _LIBCPP_NO_EXCEPTIONS
530 template <class _CharT, class _Traits>
531 basic_ostream<_CharT, _Traits>&
532 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
534 #ifndef _LIBCPP_NO_EXCEPTIONS
537 #endif // _LIBCPP_NO_EXCEPTIONS
541 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
542 const _Fp& __f = use_facet<_Fp>(this->getloc());
543 if (__f.put(*this, *this, this->fill(), __n).failed())
544 this->setstate(ios_base::badbit | ios_base::failbit);
546 #ifndef _LIBCPP_NO_EXCEPTIONS
550 this->__set_badbit_and_consider_rethrow();
552 #endif // _LIBCPP_NO_EXCEPTIONS
556 template <class _CharT, class _Traits>
557 basic_ostream<_CharT, _Traits>&
558 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
560 #ifndef _LIBCPP_NO_EXCEPTIONS
563 #endif // _LIBCPP_NO_EXCEPTIONS
567 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
568 const _Fp& __f = use_facet<_Fp>(this->getloc());
569 if (__f.put(*this, *this, this->fill(), __n).failed())
570 this->setstate(ios_base::badbit | ios_base::failbit);
572 #ifndef _LIBCPP_NO_EXCEPTIONS
576 this->__set_badbit_and_consider_rethrow();
578 #endif // _LIBCPP_NO_EXCEPTIONS
582 template <class _CharT, class _Traits>
583 basic_ostream<_CharT, _Traits>&
584 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
586 #ifndef _LIBCPP_NO_EXCEPTIONS
589 #endif // _LIBCPP_NO_EXCEPTIONS
593 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
594 const _Fp& __f = use_facet<_Fp>(this->getloc());
595 if (__f.put(*this, *this, this->fill(), __n).failed())
596 this->setstate(ios_base::badbit | ios_base::failbit);
598 #ifndef _LIBCPP_NO_EXCEPTIONS
602 this->__set_badbit_and_consider_rethrow();
604 #endif // _LIBCPP_NO_EXCEPTIONS
608 template <class _CharT, class _Traits>
609 basic_ostream<_CharT, _Traits>&
610 basic_ostream<_CharT, _Traits>::operator<<(float __n)
612 #ifndef _LIBCPP_NO_EXCEPTIONS
615 #endif // _LIBCPP_NO_EXCEPTIONS
619 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
620 const _Fp& __f = use_facet<_Fp>(this->getloc());
621 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
622 this->setstate(ios_base::badbit | ios_base::failbit);
624 #ifndef _LIBCPP_NO_EXCEPTIONS
628 this->__set_badbit_and_consider_rethrow();
630 #endif // _LIBCPP_NO_EXCEPTIONS
634 template <class _CharT, class _Traits>
635 basic_ostream<_CharT, _Traits>&
636 basic_ostream<_CharT, _Traits>::operator<<(double __n)
638 #ifndef _LIBCPP_NO_EXCEPTIONS
641 #endif // _LIBCPP_NO_EXCEPTIONS
645 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
646 const _Fp& __f = use_facet<_Fp>(this->getloc());
647 if (__f.put(*this, *this, this->fill(), __n).failed())
648 this->setstate(ios_base::badbit | ios_base::failbit);
650 #ifndef _LIBCPP_NO_EXCEPTIONS
654 this->__set_badbit_and_consider_rethrow();
656 #endif // _LIBCPP_NO_EXCEPTIONS
660 template <class _CharT, class _Traits>
661 basic_ostream<_CharT, _Traits>&
662 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
664 #ifndef _LIBCPP_NO_EXCEPTIONS
667 #endif // _LIBCPP_NO_EXCEPTIONS
671 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
672 const _Fp& __f = use_facet<_Fp>(this->getloc());
673 if (__f.put(*this, *this, this->fill(), __n).failed())
674 this->setstate(ios_base::badbit | ios_base::failbit);
676 #ifndef _LIBCPP_NO_EXCEPTIONS
680 this->__set_badbit_and_consider_rethrow();
682 #endif // _LIBCPP_NO_EXCEPTIONS
686 template <class _CharT, class _Traits>
687 basic_ostream<_CharT, _Traits>&
688 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
690 #ifndef _LIBCPP_NO_EXCEPTIONS
693 #endif // _LIBCPP_NO_EXCEPTIONS
697 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
698 const _Fp& __f = use_facet<_Fp>(this->getloc());
699 if (__f.put(*this, *this, this->fill(), __n).failed())
700 this->setstate(ios_base::badbit | ios_base::failbit);
702 #ifndef _LIBCPP_NO_EXCEPTIONS
706 this->__set_badbit_and_consider_rethrow();
708 #endif // _LIBCPP_NO_EXCEPTIONS
712 template<class _CharT, class _Traits>
713 basic_ostream<_CharT, _Traits>&
714 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
715 const _CharT* __str, size_t __len)
717 #ifndef _LIBCPP_NO_EXCEPTIONS
720 #endif // _LIBCPP_NO_EXCEPTIONS
721 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
724 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
725 if (__pad_and_output(_Ip(__os),
727 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
732 __os.fill()).failed())
733 __os.setstate(ios_base::badbit | ios_base::failbit);
735 #ifndef _LIBCPP_NO_EXCEPTIONS
739 __os.__set_badbit_and_consider_rethrow();
741 #endif // _LIBCPP_NO_EXCEPTIONS
746 template<class _CharT, class _Traits>
747 basic_ostream<_CharT, _Traits>&
748 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
750 return _VSTD::__put_character_sequence(__os, &__c, 1);
753 template<class _CharT, class _Traits>
754 basic_ostream<_CharT, _Traits>&
755 operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
757 #ifndef _LIBCPP_NO_EXCEPTIONS
760 #endif // _LIBCPP_NO_EXCEPTIONS
761 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
764 _CharT __c = __os.widen(__cn);
765 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
766 if (__pad_and_output(_Ip(__os),
768 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
773 __os.fill()).failed())
774 __os.setstate(ios_base::badbit | ios_base::failbit);
776 #ifndef _LIBCPP_NO_EXCEPTIONS
780 __os.__set_badbit_and_consider_rethrow();
782 #endif // _LIBCPP_NO_EXCEPTIONS
786 template<class _Traits>
787 basic_ostream<char, _Traits>&
788 operator<<(basic_ostream<char, _Traits>& __os, char __c)
790 return _VSTD::__put_character_sequence(__os, &__c, 1);
793 template<class _Traits>
794 basic_ostream<char, _Traits>&
795 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
797 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
800 template<class _Traits>
801 basic_ostream<char, _Traits>&
802 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
804 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
807 template<class _CharT, class _Traits>
808 basic_ostream<_CharT, _Traits>&
809 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
811 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
814 template<class _CharT, class _Traits>
815 basic_ostream<_CharT, _Traits>&
816 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
818 #ifndef _LIBCPP_NO_EXCEPTIONS
821 #endif // _LIBCPP_NO_EXCEPTIONS
822 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
825 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
826 size_t __len = char_traits<char>::length(__strn);
827 const int __bs = 100;
829 _CharT* __wb = __wbb;
830 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
833 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
838 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
839 *__p = __os.widen(*__strn);
840 if (__pad_and_output(_Ip(__os),
842 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
847 __os.fill()).failed())
848 __os.setstate(ios_base::badbit | ios_base::failbit);
850 #ifndef _LIBCPP_NO_EXCEPTIONS
854 __os.__set_badbit_and_consider_rethrow();
856 #endif // _LIBCPP_NO_EXCEPTIONS
860 template<class _Traits>
861 basic_ostream<char, _Traits>&
862 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
864 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
867 template<class _Traits>
868 basic_ostream<char, _Traits>&
869 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
871 const char *__s = (const char *) __str;
872 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
875 template<class _Traits>
876 basic_ostream<char, _Traits>&
877 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
879 const char *__s = (const char *) __str;
880 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
883 template <class _CharT, class _Traits>
884 basic_ostream<_CharT, _Traits>&
885 basic_ostream<_CharT, _Traits>::put(char_type __c)
887 #ifndef _LIBCPP_NO_EXCEPTIONS
890 #endif // _LIBCPP_NO_EXCEPTIONS
894 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
898 this->setstate(ios_base::badbit);
900 #ifndef _LIBCPP_NO_EXCEPTIONS
904 this->__set_badbit_and_consider_rethrow();
906 #endif // _LIBCPP_NO_EXCEPTIONS
910 template <class _CharT, class _Traits>
911 basic_ostream<_CharT, _Traits>&
912 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
914 #ifndef _LIBCPP_NO_EXCEPTIONS
917 #endif // _LIBCPP_NO_EXCEPTIONS
921 if (this->rdbuf()->sputn(__s, __n) != __n)
922 this->setstate(ios_base::badbit);
924 #ifndef _LIBCPP_NO_EXCEPTIONS
928 this->__set_badbit_and_consider_rethrow();
930 #endif // _LIBCPP_NO_EXCEPTIONS
934 template <class _CharT, class _Traits>
935 basic_ostream<_CharT, _Traits>&
936 basic_ostream<_CharT, _Traits>::flush()
938 #ifndef _LIBCPP_NO_EXCEPTIONS
941 #endif // _LIBCPP_NO_EXCEPTIONS
947 if (this->rdbuf()->pubsync() == -1)
948 this->setstate(ios_base::badbit);
951 #ifndef _LIBCPP_NO_EXCEPTIONS
955 this->__set_badbit_and_consider_rethrow();
957 #endif // _LIBCPP_NO_EXCEPTIONS
961 template <class _CharT, class _Traits>
962 typename basic_ostream<_CharT, _Traits>::pos_type
963 basic_ostream<_CharT, _Traits>::tellp()
967 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
970 template <class _CharT, class _Traits>
971 basic_ostream<_CharT, _Traits>&
972 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
977 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
978 this->setstate(ios_base::failbit);
983 template <class _CharT, class _Traits>
984 basic_ostream<_CharT, _Traits>&
985 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
990 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
991 this->setstate(ios_base::failbit);
996 template <class _CharT, class _Traits>
997 inline _LIBCPP_INLINE_VISIBILITY
998 basic_ostream<_CharT, _Traits>&
999 endl(basic_ostream<_CharT, _Traits>& __os)
1001 __os.put(__os.widen('\n'));
1006 template <class _CharT, class _Traits>
1007 inline _LIBCPP_INLINE_VISIBILITY
1008 basic_ostream<_CharT, _Traits>&
1009 ends(basic_ostream<_CharT, _Traits>& __os)
1015 template <class _CharT, class _Traits>
1016 inline _LIBCPP_INLINE_VISIBILITY
1017 basic_ostream<_CharT, _Traits>&
1018 flush(basic_ostream<_CharT, _Traits>& __os)
1024 #ifndef _LIBCPP_CXX03_LANG
1026 template <class _Stream, class _Tp>
1027 inline _LIBCPP_INLINE_VISIBILITY
1030 !is_lvalue_reference<_Stream>::value &&
1031 is_base_of<ios_base, _Stream>::value,
1034 operator<<(_Stream&& __os, const _Tp& __x)
1037 return _VSTD::move(__os);
1040 #endif // _LIBCPP_CXX03_LANG
1042 template<class _CharT, class _Traits, class _Allocator>
1043 basic_ostream<_CharT, _Traits>&
1044 operator<<(basic_ostream<_CharT, _Traits>& __os,
1045 const basic_string<_CharT, _Traits, _Allocator>& __str)
1047 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
1050 template<class _CharT, class _Traits>
1051 basic_ostream<_CharT, _Traits>&
1052 operator<<(basic_ostream<_CharT, _Traits>& __os,
1053 const basic_string_view<_CharT, _Traits> __sv)
1055 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1058 template <class _CharT, class _Traits>
1059 inline _LIBCPP_INLINE_VISIBILITY
1060 basic_ostream<_CharT, _Traits>&
1061 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1063 return __os << __ec.category().name() << ':' << __ec.value();
1066 template<class _CharT, class _Traits, class _Yp>
1067 inline _LIBCPP_INLINE_VISIBILITY
1068 basic_ostream<_CharT, _Traits>&
1069 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1071 return __os << __p.get();
1074 template <class _CharT, class _Traits, size_t _Size>
1075 basic_ostream<_CharT, _Traits>&
1076 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1078 return __os << __x.template to_string<_CharT, _Traits>
1079 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1080 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1083 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1084 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
1086 _LIBCPP_END_NAMESPACE_STD
1088 #endif // _LIBCPP_OSTREAM