2 //===-------------------------- ostream -----------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_OSTREAM
11 #define _LIBCPP_OSTREAM
16 template <class charT, class traits = char_traits<charT> >
18 : virtual public basic_ios<charT,traits>
21 // types (inherited from basic_ios (27.5.4)):
22 typedef charT char_type;
23 typedef traits traits_type;
24 typedef typename traits_type::int_type int_type;
25 typedef typename traits_type::pos_type pos_type;
26 typedef typename traits_type::off_type off_type;
28 // 27.7.2.2 Constructor/destructor:
29 explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
30 basic_ostream(basic_ostream&& rhs);
31 virtual ~basic_ostream();
33 // 27.7.2.3 Assign/swap
34 basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
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);
59 basic_ostream& operator<<(nullptr_t);
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);
145 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
146 #pragma GCC system_header
149 _LIBCPP_BEGIN_NAMESPACE_STD
151 template <class _CharT, class _Traits>
152 class _LIBCPP_TEMPLATE_VIS basic_ostream
153 : virtual public basic_ios<_CharT, _Traits>
156 // types (inherited from basic_ios (27.5.4)):
157 typedef _CharT char_type;
158 typedef _Traits traits_type;
159 typedef typename traits_type::int_type int_type;
160 typedef typename traits_type::pos_type pos_type;
161 typedef typename traits_type::off_type off_type;
163 // 27.7.2.2 Constructor/destructor:
164 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
165 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
166 { this->init(__sb); }
167 virtual ~basic_ostream();
169 #ifndef _LIBCPP_CXX03_LANG
170 inline _LIBCPP_INLINE_VISIBILITY
171 basic_ostream(basic_ostream&& __rhs);
173 // 27.7.2.3 Assign/swap
174 inline _LIBCPP_INLINE_VISIBILITY
175 basic_ostream& operator=(basic_ostream&& __rhs);
177 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
178 void swap(basic_ostream& __rhs)
179 { basic_ios<char_type, traits_type>::swap(__rhs); }
181 #ifndef _LIBCPP_CXX03_LANG
182 basic_ostream (const basic_ostream& __rhs) = delete;
183 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
185 basic_ostream (const basic_ostream& __rhs); // not defined
186 basic_ostream& operator=(const basic_ostream& __rhs); // not defined
190 // 27.7.2.4 Prefix/suffix:
191 class _LIBCPP_TEMPLATE_VIS sentry;
193 // 27.7.2.6 Formatted output:
194 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
195 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
196 { return __pf(*this); }
198 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
199 basic_ostream& operator<<(basic_ios<char_type, traits_type>&
200 (*__pf)(basic_ios<char_type,traits_type>&))
201 { __pf(*this); return *this; }
203 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
204 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
205 { __pf(*this); return *this; }
207 basic_ostream& operator<<(bool __n);
208 basic_ostream& operator<<(short __n);
209 basic_ostream& operator<<(unsigned short __n);
210 basic_ostream& operator<<(int __n);
211 basic_ostream& operator<<(unsigned int __n);
212 basic_ostream& operator<<(long __n);
213 basic_ostream& operator<<(unsigned long __n);
214 basic_ostream& operator<<(long long __n);
215 basic_ostream& operator<<(unsigned long long __n);
216 basic_ostream& operator<<(float __f);
217 basic_ostream& operator<<(double __f);
218 basic_ostream& operator<<(long double __f);
219 basic_ostream& operator<<(const void* __p);
220 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
222 _LIBCPP_INLINE_VISIBILITY
223 basic_ostream& operator<<(nullptr_t)
224 { return *this << "nullptr"; }
226 // 27.7.2.7 Unformatted output:
227 basic_ostream& put(char_type __c);
228 basic_ostream& write(const char_type* __s, streamsize __n);
229 basic_ostream& flush();
232 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
234 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
235 basic_ostream& seekp(pos_type __pos);
236 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
237 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
240 _LIBCPP_INLINE_VISIBILITY
241 basic_ostream() {} // extension, intentially does not initialize
244 template <class _CharT, class _Traits>
245 class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
248 basic_ostream<_CharT, _Traits>& __os_;
250 sentry(const sentry&); // = delete;
251 sentry& operator=(const sentry&); // = delete;
254 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
257 _LIBCPP_INLINE_VISIBILITY
259 operator bool() const {return __ok_;}
262 template <class _CharT, class _Traits>
263 basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
275 template <class _CharT, class _Traits>
276 basic_ostream<_CharT, _Traits>::sentry::~sentry()
278 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
279 && !uncaught_exception())
281 #ifndef _LIBCPP_NO_EXCEPTIONS
284 #endif // _LIBCPP_NO_EXCEPTIONS
285 if (__os_.rdbuf()->pubsync() == -1)
286 __os_.setstate(ios_base::badbit);
287 #ifndef _LIBCPP_NO_EXCEPTIONS
292 #endif // _LIBCPP_NO_EXCEPTIONS
296 #ifndef _LIBCPP_CXX03_LANG
298 template <class _CharT, class _Traits>
299 basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
304 template <class _CharT, class _Traits>
305 basic_ostream<_CharT, _Traits>&
306 basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
312 #endif // _LIBCPP_CXX03_LANG
314 template <class _CharT, class _Traits>
315 basic_ostream<_CharT, _Traits>::~basic_ostream()
319 template <class _CharT, class _Traits>
320 basic_ostream<_CharT, _Traits>&
321 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
323 #ifndef _LIBCPP_NO_EXCEPTIONS
326 #endif // _LIBCPP_NO_EXCEPTIONS
332 #ifndef _LIBCPP_NO_EXCEPTIONS
335 #endif // _LIBCPP_NO_EXCEPTIONS
336 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
337 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
342 for (; __i != __eof; ++__i, ++__o, ++__c)
349 this->setstate(ios_base::failbit);
350 #ifndef _LIBCPP_NO_EXCEPTIONS
354 this->__set_failbit_and_consider_rethrow();
356 #endif // _LIBCPP_NO_EXCEPTIONS
359 this->setstate(ios_base::badbit);
361 #ifndef _LIBCPP_NO_EXCEPTIONS
365 this->__set_badbit_and_consider_rethrow();
367 #endif // _LIBCPP_NO_EXCEPTIONS
371 template <class _CharT, class _Traits>
372 basic_ostream<_CharT, _Traits>&
373 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
375 #ifndef _LIBCPP_NO_EXCEPTIONS
378 #endif // _LIBCPP_NO_EXCEPTIONS
382 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
383 const _Fp& __f = use_facet<_Fp>(this->getloc());
384 if (__f.put(*this, *this, this->fill(), __n).failed())
385 this->setstate(ios_base::badbit | ios_base::failbit);
387 #ifndef _LIBCPP_NO_EXCEPTIONS
391 this->__set_badbit_and_consider_rethrow();
393 #endif // _LIBCPP_NO_EXCEPTIONS
397 template <class _CharT, class _Traits>
398 basic_ostream<_CharT, _Traits>&
399 basic_ostream<_CharT, _Traits>::operator<<(short __n)
401 #ifndef _LIBCPP_NO_EXCEPTIONS
404 #endif // _LIBCPP_NO_EXCEPTIONS
408 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
409 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
410 const _Fp& __f = use_facet<_Fp>(this->getloc());
411 if (__f.put(*this, *this, this->fill(),
412 __flags == ios_base::oct || __flags == ios_base::hex ?
413 static_cast<long>(static_cast<unsigned short>(__n)) :
414 static_cast<long>(__n)).failed())
415 this->setstate(ios_base::badbit | ios_base::failbit);
417 #ifndef _LIBCPP_NO_EXCEPTIONS
421 this->__set_badbit_and_consider_rethrow();
423 #endif // _LIBCPP_NO_EXCEPTIONS
427 template <class _CharT, class _Traits>
428 basic_ostream<_CharT, _Traits>&
429 basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
431 #ifndef _LIBCPP_NO_EXCEPTIONS
434 #endif // _LIBCPP_NO_EXCEPTIONS
438 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
439 const _Fp& __f = use_facet<_Fp>(this->getloc());
440 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
441 this->setstate(ios_base::badbit | ios_base::failbit);
443 #ifndef _LIBCPP_NO_EXCEPTIONS
447 this->__set_badbit_and_consider_rethrow();
449 #endif // _LIBCPP_NO_EXCEPTIONS
453 template <class _CharT, class _Traits>
454 basic_ostream<_CharT, _Traits>&
455 basic_ostream<_CharT, _Traits>::operator<<(int __n)
457 #ifndef _LIBCPP_NO_EXCEPTIONS
460 #endif // _LIBCPP_NO_EXCEPTIONS
464 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
465 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
466 const _Fp& __f = use_facet<_Fp>(this->getloc());
467 if (__f.put(*this, *this, this->fill(),
468 __flags == ios_base::oct || __flags == ios_base::hex ?
469 static_cast<long>(static_cast<unsigned int>(__n)) :
470 static_cast<long>(__n)).failed())
471 this->setstate(ios_base::badbit | ios_base::failbit);
473 #ifndef _LIBCPP_NO_EXCEPTIONS
477 this->__set_badbit_and_consider_rethrow();
479 #endif // _LIBCPP_NO_EXCEPTIONS
483 template <class _CharT, class _Traits>
484 basic_ostream<_CharT, _Traits>&
485 basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
487 #ifndef _LIBCPP_NO_EXCEPTIONS
490 #endif // _LIBCPP_NO_EXCEPTIONS
494 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
495 const _Fp& __f = use_facet<_Fp>(this->getloc());
496 if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
497 this->setstate(ios_base::badbit | ios_base::failbit);
499 #ifndef _LIBCPP_NO_EXCEPTIONS
503 this->__set_badbit_and_consider_rethrow();
505 #endif // _LIBCPP_NO_EXCEPTIONS
509 template <class _CharT, class _Traits>
510 basic_ostream<_CharT, _Traits>&
511 basic_ostream<_CharT, _Traits>::operator<<(long __n)
513 #ifndef _LIBCPP_NO_EXCEPTIONS
516 #endif // _LIBCPP_NO_EXCEPTIONS
520 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
521 const _Fp& __f = use_facet<_Fp>(this->getloc());
522 if (__f.put(*this, *this, this->fill(), __n).failed())
523 this->setstate(ios_base::badbit | ios_base::failbit);
525 #ifndef _LIBCPP_NO_EXCEPTIONS
529 this->__set_badbit_and_consider_rethrow();
531 #endif // _LIBCPP_NO_EXCEPTIONS
535 template <class _CharT, class _Traits>
536 basic_ostream<_CharT, _Traits>&
537 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
539 #ifndef _LIBCPP_NO_EXCEPTIONS
542 #endif // _LIBCPP_NO_EXCEPTIONS
546 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
547 const _Fp& __f = use_facet<_Fp>(this->getloc());
548 if (__f.put(*this, *this, this->fill(), __n).failed())
549 this->setstate(ios_base::badbit | ios_base::failbit);
551 #ifndef _LIBCPP_NO_EXCEPTIONS
555 this->__set_badbit_and_consider_rethrow();
557 #endif // _LIBCPP_NO_EXCEPTIONS
561 template <class _CharT, class _Traits>
562 basic_ostream<_CharT, _Traits>&
563 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
565 #ifndef _LIBCPP_NO_EXCEPTIONS
568 #endif // _LIBCPP_NO_EXCEPTIONS
572 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
573 const _Fp& __f = use_facet<_Fp>(this->getloc());
574 if (__f.put(*this, *this, this->fill(), __n).failed())
575 this->setstate(ios_base::badbit | ios_base::failbit);
577 #ifndef _LIBCPP_NO_EXCEPTIONS
581 this->__set_badbit_and_consider_rethrow();
583 #endif // _LIBCPP_NO_EXCEPTIONS
587 template <class _CharT, class _Traits>
588 basic_ostream<_CharT, _Traits>&
589 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
591 #ifndef _LIBCPP_NO_EXCEPTIONS
594 #endif // _LIBCPP_NO_EXCEPTIONS
598 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
599 const _Fp& __f = use_facet<_Fp>(this->getloc());
600 if (__f.put(*this, *this, this->fill(), __n).failed())
601 this->setstate(ios_base::badbit | ios_base::failbit);
603 #ifndef _LIBCPP_NO_EXCEPTIONS
607 this->__set_badbit_and_consider_rethrow();
609 #endif // _LIBCPP_NO_EXCEPTIONS
613 template <class _CharT, class _Traits>
614 basic_ostream<_CharT, _Traits>&
615 basic_ostream<_CharT, _Traits>::operator<<(float __n)
617 #ifndef _LIBCPP_NO_EXCEPTIONS
620 #endif // _LIBCPP_NO_EXCEPTIONS
624 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
625 const _Fp& __f = use_facet<_Fp>(this->getloc());
626 if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
627 this->setstate(ios_base::badbit | ios_base::failbit);
629 #ifndef _LIBCPP_NO_EXCEPTIONS
633 this->__set_badbit_and_consider_rethrow();
635 #endif // _LIBCPP_NO_EXCEPTIONS
639 template <class _CharT, class _Traits>
640 basic_ostream<_CharT, _Traits>&
641 basic_ostream<_CharT, _Traits>::operator<<(double __n)
643 #ifndef _LIBCPP_NO_EXCEPTIONS
646 #endif // _LIBCPP_NO_EXCEPTIONS
650 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
651 const _Fp& __f = use_facet<_Fp>(this->getloc());
652 if (__f.put(*this, *this, this->fill(), __n).failed())
653 this->setstate(ios_base::badbit | ios_base::failbit);
655 #ifndef _LIBCPP_NO_EXCEPTIONS
659 this->__set_badbit_and_consider_rethrow();
661 #endif // _LIBCPP_NO_EXCEPTIONS
665 template <class _CharT, class _Traits>
666 basic_ostream<_CharT, _Traits>&
667 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
669 #ifndef _LIBCPP_NO_EXCEPTIONS
672 #endif // _LIBCPP_NO_EXCEPTIONS
676 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
677 const _Fp& __f = use_facet<_Fp>(this->getloc());
678 if (__f.put(*this, *this, this->fill(), __n).failed())
679 this->setstate(ios_base::badbit | ios_base::failbit);
681 #ifndef _LIBCPP_NO_EXCEPTIONS
685 this->__set_badbit_and_consider_rethrow();
687 #endif // _LIBCPP_NO_EXCEPTIONS
691 template <class _CharT, class _Traits>
692 basic_ostream<_CharT, _Traits>&
693 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
695 #ifndef _LIBCPP_NO_EXCEPTIONS
698 #endif // _LIBCPP_NO_EXCEPTIONS
702 typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
703 const _Fp& __f = use_facet<_Fp>(this->getloc());
704 if (__f.put(*this, *this, this->fill(), __n).failed())
705 this->setstate(ios_base::badbit | ios_base::failbit);
707 #ifndef _LIBCPP_NO_EXCEPTIONS
711 this->__set_badbit_and_consider_rethrow();
713 #endif // _LIBCPP_NO_EXCEPTIONS
717 template<class _CharT, class _Traits>
718 basic_ostream<_CharT, _Traits>&
719 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
720 const _CharT* __str, size_t __len)
722 #ifndef _LIBCPP_NO_EXCEPTIONS
725 #endif // _LIBCPP_NO_EXCEPTIONS
726 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
729 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
730 if (__pad_and_output(_Ip(__os),
732 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
737 __os.fill()).failed())
738 __os.setstate(ios_base::badbit | ios_base::failbit);
740 #ifndef _LIBCPP_NO_EXCEPTIONS
744 __os.__set_badbit_and_consider_rethrow();
746 #endif // _LIBCPP_NO_EXCEPTIONS
751 template<class _CharT, class _Traits>
752 basic_ostream<_CharT, _Traits>&
753 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
755 return _VSTD::__put_character_sequence(__os, &__c, 1);
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 return _VSTD::__put_character_sequence(__os, &__c, 1);
798 template<class _Traits>
799 basic_ostream<char, _Traits>&
800 operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
802 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
805 template<class _Traits>
806 basic_ostream<char, _Traits>&
807 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
809 return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
812 template<class _CharT, class _Traits>
813 basic_ostream<_CharT, _Traits>&
814 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
816 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
819 template<class _CharT, class _Traits>
820 basic_ostream<_CharT, _Traits>&
821 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
823 #ifndef _LIBCPP_NO_EXCEPTIONS
826 #endif // _LIBCPP_NO_EXCEPTIONS
827 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
830 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
831 size_t __len = char_traits<char>::length(__strn);
832 const int __bs = 100;
834 _CharT* __wb = __wbb;
835 unique_ptr<_CharT, void(*)(void*)> __h(0, free);
838 __wb = (_CharT*)malloc(__len*sizeof(_CharT));
843 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
844 *__p = __os.widen(*__strn);
845 if (__pad_and_output(_Ip(__os),
847 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
852 __os.fill()).failed())
853 __os.setstate(ios_base::badbit | ios_base::failbit);
855 #ifndef _LIBCPP_NO_EXCEPTIONS
859 __os.__set_badbit_and_consider_rethrow();
861 #endif // _LIBCPP_NO_EXCEPTIONS
865 template<class _Traits>
866 basic_ostream<char, _Traits>&
867 operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
869 return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
872 template<class _Traits>
873 basic_ostream<char, _Traits>&
874 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
876 const char *__s = (const char *) __str;
877 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
880 template<class _Traits>
881 basic_ostream<char, _Traits>&
882 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
884 const char *__s = (const char *) __str;
885 return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
888 template <class _CharT, class _Traits>
889 basic_ostream<_CharT, _Traits>&
890 basic_ostream<_CharT, _Traits>::put(char_type __c)
892 #ifndef _LIBCPP_NO_EXCEPTIONS
895 #endif // _LIBCPP_NO_EXCEPTIONS
899 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
903 this->setstate(ios_base::badbit);
905 #ifndef _LIBCPP_NO_EXCEPTIONS
909 this->__set_badbit_and_consider_rethrow();
911 #endif // _LIBCPP_NO_EXCEPTIONS
915 template <class _CharT, class _Traits>
916 basic_ostream<_CharT, _Traits>&
917 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
919 #ifndef _LIBCPP_NO_EXCEPTIONS
922 #endif // _LIBCPP_NO_EXCEPTIONS
926 if (this->rdbuf()->sputn(__s, __n) != __n)
927 this->setstate(ios_base::badbit);
929 #ifndef _LIBCPP_NO_EXCEPTIONS
933 this->__set_badbit_and_consider_rethrow();
935 #endif // _LIBCPP_NO_EXCEPTIONS
939 template <class _CharT, class _Traits>
940 basic_ostream<_CharT, _Traits>&
941 basic_ostream<_CharT, _Traits>::flush()
943 #ifndef _LIBCPP_NO_EXCEPTIONS
946 #endif // _LIBCPP_NO_EXCEPTIONS
952 if (this->rdbuf()->pubsync() == -1)
953 this->setstate(ios_base::badbit);
956 #ifndef _LIBCPP_NO_EXCEPTIONS
960 this->__set_badbit_and_consider_rethrow();
962 #endif // _LIBCPP_NO_EXCEPTIONS
966 template <class _CharT, class _Traits>
967 typename basic_ostream<_CharT, _Traits>::pos_type
968 basic_ostream<_CharT, _Traits>::tellp()
972 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
975 template <class _CharT, class _Traits>
976 basic_ostream<_CharT, _Traits>&
977 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
982 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
983 this->setstate(ios_base::failbit);
988 template <class _CharT, class _Traits>
989 basic_ostream<_CharT, _Traits>&
990 basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
995 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
996 this->setstate(ios_base::failbit);
1001 template <class _CharT, class _Traits>
1002 inline _LIBCPP_INLINE_VISIBILITY
1003 basic_ostream<_CharT, _Traits>&
1004 endl(basic_ostream<_CharT, _Traits>& __os)
1006 __os.put(__os.widen('\n'));
1011 template <class _CharT, class _Traits>
1012 inline _LIBCPP_INLINE_VISIBILITY
1013 basic_ostream<_CharT, _Traits>&
1014 ends(basic_ostream<_CharT, _Traits>& __os)
1020 template <class _CharT, class _Traits>
1021 inline _LIBCPP_INLINE_VISIBILITY
1022 basic_ostream<_CharT, _Traits>&
1023 flush(basic_ostream<_CharT, _Traits>& __os)
1029 #ifndef _LIBCPP_CXX03_LANG
1031 template <class _Stream, class _Tp>
1032 inline _LIBCPP_INLINE_VISIBILITY
1035 !is_lvalue_reference<_Stream>::value &&
1036 is_base_of<ios_base, _Stream>::value,
1039 operator<<(_Stream&& __os, const _Tp& __x)
1042 return _VSTD::move(__os);
1045 #endif // _LIBCPP_CXX03_LANG
1047 template<class _CharT, class _Traits, class _Allocator>
1048 basic_ostream<_CharT, _Traits>&
1049 operator<<(basic_ostream<_CharT, _Traits>& __os,
1050 const basic_string<_CharT, _Traits, _Allocator>& __str)
1052 return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
1055 template<class _CharT, class _Traits>
1056 basic_ostream<_CharT, _Traits>&
1057 operator<<(basic_ostream<_CharT, _Traits>& __os,
1058 basic_string_view<_CharT, _Traits> __sv)
1060 return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1063 template <class _CharT, class _Traits>
1064 inline _LIBCPP_INLINE_VISIBILITY
1065 basic_ostream<_CharT, _Traits>&
1066 operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1068 return __os << __ec.category().name() << ':' << __ec.value();
1071 template<class _CharT, class _Traits, class _Yp>
1072 inline _LIBCPP_INLINE_VISIBILITY
1073 basic_ostream<_CharT, _Traits>&
1074 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1076 return __os << __p.get();
1079 template<class _CharT, class _Traits, class _Yp, class _Dp>
1080 inline _LIBCPP_INLINE_VISIBILITY
1083 is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value,
1084 basic_ostream<_CharT, _Traits>&
1086 operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1088 return __os << __p.get();
1091 template <class _CharT, class _Traits, size_t _Size>
1092 basic_ostream<_CharT, _Traits>&
1093 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1095 return __os << __x.template to_string<_CharT, _Traits>
1096 (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1097 use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1100 #ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
1101 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1102 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
1105 _LIBCPP_END_NAMESPACE_STD
1107 #endif // _LIBCPP_OSTREAM