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