1//===---------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___OSTREAM_BASIC_OSTREAM_H
10#define _LIBCPP___OSTREAM_BASIC_OSTREAM_H
11
12#include <__config>
13
14#if _LIBCPP_HAS_LOCALIZATION
15
16# include <__exception/operations.h>
17# include <__fwd/memory.h>
18# include <__iterator/ostreambuf_iterator.h>
19# include <__locale_dir/num.h>
20# include <__locale_dir/pad_and_output.h>
21# include <__memory/addressof.h>
22# include <__memory/unique_ptr.h>
23# include <__new/exceptions.h>
24# include <__ostream/put_character_sequence.h>
25# include <__system_error/error_code.h>
26# include <__type_traits/conjunction.h>
27# include <__type_traits/enable_if.h>
28# include <__type_traits/is_base_of.h>
29# include <__type_traits/void_t.h>
30# include <__utility/declval.h>
31# include <bitset>
32# include <ios>
33# include <streambuf>
34# include <string_view>
35
36# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
37# pragma GCC system_header
38# endif
39
40_LIBCPP_PUSH_MACROS
41# include <__undef_macros>
42
43_LIBCPP_BEGIN_NAMESPACE_STD
44_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
45
46template <class _CharT, class _Traits>
47class basic_ostream : virtual public basic_ios<_CharT, _Traits> {
48public:
49 // types (inherited from basic_ios (27.5.4)):
50 typedef _CharT char_type;
51 typedef _Traits traits_type;
52 typedef typename traits_type::int_type int_type;
53 typedef typename traits_type::pos_type pos_type;
54 typedef typename traits_type::off_type off_type;
55
56 // 27.7.2.2 Constructor/destructor:
57 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb) {
58 this->init(__sb);
59 }
60 ~basic_ostream() override;
61
62 basic_ostream(const basic_ostream& __rhs) = delete;
63 basic_ostream& operator=(const basic_ostream& __rhs) = delete;
64
65protected:
66 inline _LIBCPP_HIDE_FROM_ABI basic_ostream(basic_ostream&& __rhs);
67
68 // 27.7.2.3 Assign/swap
69 inline _LIBCPP_HIDE_FROM_ABI basic_ostream& operator=(basic_ostream&& __rhs);
70
71 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 void swap(basic_ostream& __rhs) {
72 basic_ios<char_type, traits_type>::swap(__rhs);
73 }
74
75public:
76 // 27.7.2.4 Prefix/suffix:
77 class sentry;
78
79 // 27.7.2.6 Formatted output:
80 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&)) {
81 return __pf(*this);
82 }
83
84 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream&
85 operator<<(basic_ios<char_type, traits_type>& (*__pf)(basic_ios<char_type, traits_type>&)) {
86 __pf(*this);
87 return *this;
88 }
89
90 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& operator<<(ios_base& (*__pf)(ios_base&)) {
91 __pf(*this);
92 return *this;
93 }
94
95 template <class _Tp>
96 _LIBCPP_HIDE_FROM_ABI basic_ostream& __put_num(_Tp __value) {
97# if _LIBCPP_HAS_EXCEPTIONS
98 try {
99# endif // _LIBCPP_HAS_EXCEPTIONS
100 sentry __s(*this);
101 if (__s) {
102 using _Fp = num_put<char_type, ostreambuf_iterator<char_type, traits_type> >;
103 const _Fp& __facet = std::use_facet<_Fp>(this->getloc());
104 if (__facet.put(*this, *this, this->fill(), __value).failed())
105 this->setstate(ios_base::badbit | ios_base::failbit);
106 }
107# if _LIBCPP_HAS_EXCEPTIONS
108 } catch (...) {
109 this->__set_badbit_and_consider_rethrow();
110 }
111# endif // _LIBCPP_HAS_EXCEPTIONS
112 return *this;
113 }
114
115 template <class _Tp>
116 _LIBCPP_HIDE_FROM_ABI basic_ostream& __put_num_integer_promote(_Tp __value) {
117# if _LIBCPP_HAS_EXCEPTIONS
118 try {
119# endif // _LIBCPP_HAS_EXCEPTIONS
120 sentry __s(*this);
121 if (__s) {
122 ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
123
124 using _Fp = num_put<char_type, ostreambuf_iterator<char_type, traits_type> >;
125 const _Fp& __facet = std::use_facet<_Fp>(this->getloc());
126 if (__facet
127 .put(*this,
128 *this,
129 this->fill(),
130 __flags == ios_base::oct || __flags == ios_base::hex
131 ? static_cast<__copy_unsigned_t<_Tp, long> >(std::__to_unsigned_like(__value))
132 : static_cast<__copy_unsigned_t<_Tp, long> >(__value))
133 .failed())
134 this->setstate(ios_base::badbit | ios_base::failbit);
135 }
136# if _LIBCPP_HAS_EXCEPTIONS
137 } catch (...) {
138 this->__set_badbit_and_consider_rethrow();
139 }
140# endif // _LIBCPP_HAS_EXCEPTIONS
141 return *this;
142 }
143
144 basic_ostream& operator<<(bool __n);
145 basic_ostream& operator<<(short __n);
146 basic_ostream& operator<<(unsigned short __n);
147 basic_ostream& operator<<(int __n);
148 basic_ostream& operator<<(unsigned int __n);
149 basic_ostream& operator<<(long __n);
150 basic_ostream& operator<<(unsigned long __n);
151 basic_ostream& operator<<(long long __n);
152 basic_ostream& operator<<(unsigned long long __n);
153 basic_ostream& operator<<(float __f);
154 basic_ostream& operator<<(double __f);
155 basic_ostream& operator<<(long double __f);
156 basic_ostream& operator<<(const void* __p);
157
158# if _LIBCPP_STD_VER >= 23
159 _LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(const volatile void* __p) {
160 return operator<<(const_cast<const void*>(__p));
161 }
162# endif
163
164 basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
165
166# if _LIBCPP_STD_VER >= 17
167 // LWG 2221 - nullptr. This is not backported to older standards modes.
168 // See https://reviews.llvm.org/D127033 for more info on the rationale.
169 _LIBCPP_HIDE_FROM_ABI basic_ostream& operator<<(nullptr_t) { return *this << "nullptr"; }
170# endif
171
172 // 27.7.2.7 Unformatted output:
173 basic_ostream& put(char_type __c);
174 basic_ostream& write(const char_type* __s, streamsize __n);
175 basic_ostream& flush();
176
177 // 27.7.2.5 seeks:
178 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 pos_type tellp();
179 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& seekp(pos_type __pos);
180 inline _LIBCPP_HIDE_FROM_ABI_SINCE_LLVM8 basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
181
182protected:
183 _LIBCPP_HIDE_FROM_ABI basic_ostream() {} // extension, intentially does not initialize
184};
185
186template <class _CharT, class _Traits>
187class basic_ostream<_CharT, _Traits>::sentry {
188 bool __ok_;
189 basic_ostream<_CharT, _Traits>& __os_;
190
191public:
192 explicit sentry(basic_ostream<_CharT, _Traits>& __os);
193 ~sentry();
194 sentry(const sentry&) = delete;
195 sentry& operator=(const sentry&) = delete;
196
197 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ok_; }
198};
199
200template <class _CharT, class _Traits>
201basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os) : __ok_(false), __os_(__os) {
202 if (__os.good()) {
203 if (__os.tie())
204 __os.tie()->flush();
205 __ok_ = true;
206 }
207}
208
209template <class _CharT, class _Traits>
210basic_ostream<_CharT, _Traits>::sentry::~sentry() {
211 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf) && uncaught_exceptions() == 0) {
212# if _LIBCPP_HAS_EXCEPTIONS
213 try {
214# endif // _LIBCPP_HAS_EXCEPTIONS
215 if (__os_.rdbuf()->pubsync() == -1)
216 __os_.setstate(ios_base::badbit);
217# if _LIBCPP_HAS_EXCEPTIONS
218 } catch (...) {
219 }
220# endif // _LIBCPP_HAS_EXCEPTIONS
221 }
222}
223
224template <class _CharT, class _Traits>
225basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) {
226 this->move(__rhs);
227}
228
229template <class _CharT, class _Traits>
230basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) {
231 swap(__rhs);
232 return *this;
233}
234
235template <class _CharT, class _Traits>
236basic_ostream<_CharT, _Traits>::~basic_ostream() {}
237
238template <class _CharT, class _Traits>
239basic_ostream<_CharT, _Traits>&
240basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) {
241# if _LIBCPP_HAS_EXCEPTIONS
242 try {
243# endif // _LIBCPP_HAS_EXCEPTIONS
244 sentry __s(*this);
245 if (__s) {
246 if (__sb) {
247# if _LIBCPP_HAS_EXCEPTIONS
248 try {
249# endif // _LIBCPP_HAS_EXCEPTIONS
250 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
251 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
252 _Ip __i(__sb);
253 _Ip __eof;
254 _Op __o(*this);
255 size_t __c = 0;
256 for (; __i != __eof; ++__i, ++__o, ++__c) {
257 *__o = *__i;
258 if (__o.failed())
259 break;
260 }
261 if (__c == 0)
262 this->setstate(ios_base::failbit);
263# if _LIBCPP_HAS_EXCEPTIONS
264 } catch (...) {
265 this->__set_failbit_and_consider_rethrow();
266 }
267# endif // _LIBCPP_HAS_EXCEPTIONS
268 } else
269 this->setstate(ios_base::badbit);
270 }
271# if _LIBCPP_HAS_EXCEPTIONS
272 } catch (...) {
273 this->__set_badbit_and_consider_rethrow();
274 }
275# endif // _LIBCPP_HAS_EXCEPTIONS
276 return *this;
277}
278
279template <class _CharT, class _Traits>
280basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __n) {
281 return __put_num(__n);
282}
283
284template <class _CharT, class _Traits>
285basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __n) {
286 return __put_num_integer_promote(__n);
287}
288
289template <class _CharT, class _Traits>
290basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) {
291 return __put_num_integer_promote(__n);
292}
293
294template <class _CharT, class _Traits>
295basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __n) {
296 return __put_num_integer_promote(__n);
297}
298
299template <class _CharT, class _Traits>
300basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) {
301 return __put_num_integer_promote(__n);
302}
303
304template <class _CharT, class _Traits>
305basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {
306 return __put_num(__n);
307}
308
309template <class _CharT, class _Traits>
310basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) {
311 return __put_num(__n);
312}
313
314template <class _CharT, class _Traits>
315basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long long __n) {
316 return __put_num(__n);
317}
318
319template <class _CharT, class _Traits>
320basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) {
321 return __put_num(__n);
322}
323
324template <class _CharT, class _Traits>
325basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __n) {
326 return *this << static_cast<double>(__n);
327}
328
329template <class _CharT, class _Traits>
330basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __n) {
331 return __put_num(__n);
332}
333
334template <class _CharT, class _Traits>
335basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __n) {
336 return __put_num(__n);
337}
338
339template <class _CharT, class _Traits>
340basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __n) {
341 return __put_num(__n);
342}
343
344template <class _CharT, class _Traits>
345_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
346 return std::__put_character_sequence(__os, std::addressof(__c), 1);
347}
348
349template <class _CharT, class _Traits>
350_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) {
351# if _LIBCPP_HAS_EXCEPTIONS
352 try {
353# endif // _LIBCPP_HAS_EXCEPTIONS
354 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
355 if (__s) {
356 _CharT __c = __os.widen(__cn);
357 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
358 if (std::__pad_and_output(
359 _Ip(__os),
360 std::addressof(__c),
361 std::addressof(__c) + (((__os.flags() & ios_base::adjustfield) == ios_base::left) ? 1 : 0),
362 std::addressof(__c) + 1,
363 __os,
364 __os.fill())
365 .failed())
366 __os.setstate(ios_base::badbit | ios_base::failbit);
367 }
368# if _LIBCPP_HAS_EXCEPTIONS
369 } catch (...) {
370 __os.__set_badbit_and_consider_rethrow();
371 }
372# endif // _LIBCPP_HAS_EXCEPTIONS
373 return __os;
374}
375
376template <class _Traits>
377_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, char __c) {
378 return std::__put_character_sequence(__os, &__c, 1);
379}
380
381template <class _Traits>
382_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
383 return std::__put_character_sequence(__os, (char*)&__c, 1);
384}
385
386template <class _Traits>
387_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
388 return std::__put_character_sequence(__os, (char*)&__c, 1);
389}
390
391template <class _CharT, class _Traits>
392_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
393operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) {
394 return std::__put_character_sequence(__os, __str, _Traits::length(__str));
395}
396
397template <class _CharT, class _Traits>
398_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
399operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
400# if _LIBCPP_HAS_EXCEPTIONS
401 try {
402# endif // _LIBCPP_HAS_EXCEPTIONS
403 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
404 if (__s) {
405 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
406 size_t __len = char_traits<char>::length(s: __strn);
407 const int __bs = 100;
408 _CharT __wbb[__bs];
409 _CharT* __wb = __wbb;
410 unique_ptr<_CharT, void (*)(void*)> __h(0, free);
411 if (__len > __bs) {
412 __wb = (_CharT*)malloc(size: __len * sizeof(_CharT));
413 if (__wb == 0)
414 std::__throw_bad_alloc();
415 __h.reset(__wb);
416 }
417 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
418 *__p = __os.widen(*__strn);
419 if (std::__pad_and_output(
420 _Ip(__os),
421 __wb,
422 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __wb + __len : __wb,
423 __wb + __len,
424 __os,
425 __os.fill())
426 .failed())
427 __os.setstate(ios_base::badbit | ios_base::failbit);
428 }
429# if _LIBCPP_HAS_EXCEPTIONS
430 } catch (...) {
431 __os.__set_badbit_and_consider_rethrow();
432 }
433# endif // _LIBCPP_HAS_EXCEPTIONS
434 return __os;
435}
436
437template <class _Traits>
438_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, const char* __str) {
439 return std::__put_character_sequence(__os, __str, _Traits::length(__str));
440}
441
442template <class _Traits>
443_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
444operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) {
445 const char* __s = (const char*)__str;
446 return std::__put_character_sequence(__os, __s, _Traits::length(__s));
447}
448
449template <class _Traits>
450_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
451operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) {
452 const char* __s = (const char*)__str;
453 return std::__put_character_sequence(__os, __s, _Traits::length(__s));
454}
455
456template <class _CharT, class _Traits>
457basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __c) {
458# if _LIBCPP_HAS_EXCEPTIONS
459 try {
460# endif // _LIBCPP_HAS_EXCEPTIONS
461 sentry __s(*this);
462 if (__s) {
463 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
464 _Op __o(*this);
465 *__o = __c;
466 if (__o.failed())
467 this->setstate(ios_base::badbit);
468 }
469# if _LIBCPP_HAS_EXCEPTIONS
470 } catch (...) {
471 this->__set_badbit_and_consider_rethrow();
472 }
473# endif // _LIBCPP_HAS_EXCEPTIONS
474 return *this;
475}
476
477template <class _CharT, class _Traits>
478basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) {
479# if _LIBCPP_HAS_EXCEPTIONS
480 try {
481# endif // _LIBCPP_HAS_EXCEPTIONS
482 sentry __sen(*this);
483 if (__sen && __n) {
484 if (this->rdbuf()->sputn(__s, __n) != __n)
485 this->setstate(ios_base::badbit);
486 }
487# if _LIBCPP_HAS_EXCEPTIONS
488 } catch (...) {
489 this->__set_badbit_and_consider_rethrow();
490 }
491# endif // _LIBCPP_HAS_EXCEPTIONS
492 return *this;
493}
494
495template <class _CharT, class _Traits>
496basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() {
497# if _LIBCPP_HAS_EXCEPTIONS
498 try {
499# endif // _LIBCPP_HAS_EXCEPTIONS
500 if (this->rdbuf()) {
501 sentry __s(*this);
502 if (__s) {
503 if (this->rdbuf()->pubsync() == -1)
504 this->setstate(ios_base::badbit);
505 }
506 }
507# if _LIBCPP_HAS_EXCEPTIONS
508 } catch (...) {
509 this->__set_badbit_and_consider_rethrow();
510 }
511# endif // _LIBCPP_HAS_EXCEPTIONS
512 return *this;
513}
514
515template <class _CharT, class _Traits>
516typename basic_ostream<_CharT, _Traits>::pos_type basic_ostream<_CharT, _Traits>::tellp() {
517 if (this->fail())
518 return pos_type(-1);
519 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
520}
521
522template <class _CharT, class _Traits>
523basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) {
524 sentry __s(*this);
525 if (!this->fail()) {
526 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
527 this->setstate(ios_base::failbit);
528 }
529 return *this;
530}
531
532template <class _CharT, class _Traits>
533basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) {
534 sentry __s(*this);
535 if (!this->fail()) {
536 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
537 this->setstate(ios_base::failbit);
538 }
539 return *this;
540}
541
542template <class _CharT, class _Traits>
543_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& endl(basic_ostream<_CharT, _Traits>& __os) {
544 __os.put(__os.widen('\n'));
545 __os.flush();
546 return __os;
547}
548
549template <class _CharT, class _Traits>
550_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& ends(basic_ostream<_CharT, _Traits>& __os) {
551 __os.put(_CharT());
552 return __os;
553}
554
555template <class _CharT, class _Traits>
556_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) {
557 __os.flush();
558 return __os;
559}
560
561template <class _Stream, class _Tp, class = void>
562struct __is_ostreamable : false_type {};
563
564template <class _Stream, class _Tp>
565struct __is_ostreamable<_Stream, _Tp, decltype(std::declval<_Stream>() << std::declval<_Tp>(), void())> : true_type {};
566
567template <class _Stream,
568 class _Tp,
569 __enable_if_t<_And<is_base_of<ios_base, _Stream>, __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0>
570_LIBCPP_HIDE_FROM_ABI _Stream&& operator<<(_Stream&& __os, const _Tp& __x) {
571 __os << __x;
572 return std::move(__os);
573}
574
575template <class _CharT, class _Traits, class _Allocator>
576basic_ostream<_CharT, _Traits>&
577operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) {
578 return std::__put_character_sequence(__os, __str.data(), __str.size());
579}
580
581template <class _CharT, class _Traits>
582_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
583operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv) {
584 return std::__put_character_sequence(__os, __sv.data(), __sv.size());
585}
586
587template <class _CharT, class _Traits>
588inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
589operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) {
590 return __os << __ec.category().name() << ':' << __ec.value();
591}
592
593template <class _CharT, class _Traits, class _Yp>
594inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
595operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) {
596 return __os << __p.get();
597}
598
599template <
600 class _CharT,
601 class _Traits,
602 class _Yp,
603 class _Dp,
604 __enable_if_t<is_same<void,
605 __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>()
606 << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
607 int> = 0>
608inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
609operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) {
610 return __os << __p.get();
611}
612
613template <class _CharT, class _Traits, size_t _Size>
614_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
615operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) {
616 return __os << __x.template to_string<_CharT, _Traits>(std::use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
617 std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
618}
619
620# if _LIBCPP_STD_VER >= 20
621
622# if _LIBCPP_HAS_WIDE_CHARACTERS
623template <class _Traits>
624basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
625
626template <class _Traits>
627basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
628
629template <class _Traits>
630basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
631
632template <class _Traits>
633basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
634
635template <class _Traits>
636basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
637
638template <class _Traits>
639basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
640
641# endif // _LIBCPP_HAS_WIDE_CHARACTERS
642
643# if _LIBCPP_HAS_CHAR8_T
644template <class _Traits>
645basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
646
647template <class _Traits>
648basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
649
650template <class _Traits>
651basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
652
653template <class _Traits>
654basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
655# endif
656
657template <class _Traits>
658basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
659
660template <class _Traits>
661basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
662
663template <class _Traits>
664basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
665
666template <class _Traits>
667basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
668
669# endif // _LIBCPP_STD_VER >= 20
670
671extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
672# if _LIBCPP_HAS_WIDE_CHARACTERS
673extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
674# endif
675
676_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
677_LIBCPP_END_NAMESPACE_STD
678
679_LIBCPP_POP_MACROS
680
681#endif // _LIBCPP_HAS_LOCALIZATION
682
683#endif // _LIBCPP___OSTREAM_BASIC_OSTREAM_H
684