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_nothrow(ios_base::badbit);
217# if _LIBCPP_HAS_EXCEPTIONS
218 } catch (...) {
219 __os_.__setstate_nothrow(ios_base::badbit);
220 }
221# endif // _LIBCPP_HAS_EXCEPTIONS
222 }
223}
224
225template <class _CharT, class _Traits>
226basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs) {
227 this->move(__rhs);
228}
229
230template <class _CharT, class _Traits>
231basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs) {
232 swap(__rhs);
233 return *this;
234}
235
236template <class _CharT, class _Traits>
237basic_ostream<_CharT, _Traits>::~basic_ostream() {}
238
239template <class _CharT, class _Traits>
240basic_ostream<_CharT, _Traits>&
241basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb) {
242# if _LIBCPP_HAS_EXCEPTIONS
243 try {
244# endif // _LIBCPP_HAS_EXCEPTIONS
245 sentry __s(*this);
246 if (__s) {
247 if (__sb) {
248# if _LIBCPP_HAS_EXCEPTIONS
249 try {
250# endif // _LIBCPP_HAS_EXCEPTIONS
251 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
252 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
253 _Ip __i(__sb);
254 _Ip __eof;
255 _Op __o(*this);
256 size_t __c = 0;
257 for (; __i != __eof; ++__i, ++__o, ++__c) {
258 *__o = *__i;
259 if (__o.failed())
260 break;
261 }
262 if (__c == 0)
263 this->setstate(ios_base::failbit);
264# if _LIBCPP_HAS_EXCEPTIONS
265 } catch (...) {
266 this->__set_failbit_and_consider_rethrow();
267 }
268# endif // _LIBCPP_HAS_EXCEPTIONS
269 } else
270 this->setstate(ios_base::badbit);
271 }
272# if _LIBCPP_HAS_EXCEPTIONS
273 } catch (...) {
274 this->__set_badbit_and_consider_rethrow();
275 }
276# endif // _LIBCPP_HAS_EXCEPTIONS
277 return *this;
278}
279
280template <class _CharT, class _Traits>
281basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __n) {
282 return __put_num(__n);
283}
284
285template <class _CharT, class _Traits>
286basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __n) {
287 return __put_num_integer_promote(__n);
288}
289
290template <class _CharT, class _Traits>
291basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n) {
292 return __put_num_integer_promote(__n);
293}
294
295template <class _CharT, class _Traits>
296basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __n) {
297 return __put_num_integer_promote(__n);
298}
299
300template <class _CharT, class _Traits>
301basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n) {
302 return __put_num_integer_promote(__n);
303}
304
305template <class _CharT, class _Traits>
306basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {
307 return __put_num(__n);
308}
309
310template <class _CharT, class _Traits>
311basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) {
312 return __put_num(__n);
313}
314
315template <class _CharT, class _Traits>
316basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long long __n) {
317 return __put_num(__n);
318}
319
320template <class _CharT, class _Traits>
321basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) {
322 return __put_num(__n);
323}
324
325template <class _CharT, class _Traits>
326basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __n) {
327 return *this << static_cast<double>(__n);
328}
329
330template <class _CharT, class _Traits>
331basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __n) {
332 return __put_num(__n);
333}
334
335template <class _CharT, class _Traits>
336basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __n) {
337 return __put_num(__n);
338}
339
340template <class _CharT, class _Traits>
341basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __n) {
342 return __put_num(__n);
343}
344
345template <class _CharT, class _Traits>
346_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
347 return std::__put_character_sequence(__os, std::addressof(__c), 1);
348}
349
350template <class _CharT, class _Traits>
351_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) {
352# if _LIBCPP_HAS_EXCEPTIONS
353 try {
354# endif // _LIBCPP_HAS_EXCEPTIONS
355 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
356 if (__s) {
357 _CharT __c = __os.widen(__cn);
358 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
359 if (std::__pad_and_output(
360 _Ip(__os),
361 std::addressof(__c),
362 std::addressof(__c) + (((__os.flags() & ios_base::adjustfield) == ios_base::left) ? 1 : 0),
363 std::addressof(__c) + 1,
364 __os,
365 __os.fill())
366 .failed())
367 __os.setstate(ios_base::badbit | ios_base::failbit);
368 }
369# if _LIBCPP_HAS_EXCEPTIONS
370 } catch (...) {
371 __os.__set_badbit_and_consider_rethrow();
372 }
373# endif // _LIBCPP_HAS_EXCEPTIONS
374 return __os;
375}
376
377template <class _Traits>
378_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, char __c) {
379 return std::__put_character_sequence(__os, &__c, 1);
380}
381
382template <class _Traits>
383_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
384 return std::__put_character_sequence(__os, (char*)&__c, 1);
385}
386
387template <class _Traits>
388_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
389 return std::__put_character_sequence(__os, (char*)&__c, 1);
390}
391
392template <class _CharT, class _Traits>
393_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
394operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) {
395 return std::__put_character_sequence(__os, __str, _Traits::length(__str));
396}
397
398template <class _CharT, class _Traits>
399_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
400operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn) {
401# if _LIBCPP_HAS_EXCEPTIONS
402 try {
403# endif // _LIBCPP_HAS_EXCEPTIONS
404 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
405 if (__s) {
406 typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
407 size_t __len = char_traits<char>::length(s: __strn);
408 const int __bs = 100;
409 _CharT __wbb[__bs];
410 _CharT* __wb = __wbb;
411 unique_ptr<_CharT, void (*)(void*)> __h(0, free);
412 if (__len > __bs) {
413 __wb = (_CharT*)malloc(size: __len * sizeof(_CharT));
414 if (__wb == 0)
415 std::__throw_bad_alloc();
416 __h.reset(__wb);
417 }
418 for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
419 *__p = __os.widen(*__strn);
420 if (std::__pad_and_output(
421 _Ip(__os),
422 __wb,
423 (__os.flags() & ios_base::adjustfield) == ios_base::left ? __wb + __len : __wb,
424 __wb + __len,
425 __os,
426 __os.fill())
427 .failed())
428 __os.setstate(ios_base::badbit | ios_base::failbit);
429 }
430# if _LIBCPP_HAS_EXCEPTIONS
431 } catch (...) {
432 __os.__set_badbit_and_consider_rethrow();
433 }
434# endif // _LIBCPP_HAS_EXCEPTIONS
435 return __os;
436}
437
438template <class _Traits>
439_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& __os, const char* __str) {
440 return std::__put_character_sequence(__os, __str, _Traits::length(__str));
441}
442
443template <class _Traits>
444_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
445operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str) {
446 const char* __s = (const char*)__str;
447 return std::__put_character_sequence(__os, __s, _Traits::length(__s));
448}
449
450template <class _Traits>
451_LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
452operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str) {
453 const char* __s = (const char*)__str;
454 return std::__put_character_sequence(__os, __s, _Traits::length(__s));
455}
456
457template <class _CharT, class _Traits>
458basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::put(char_type __c) {
459# if _LIBCPP_HAS_EXCEPTIONS
460 try {
461# endif // _LIBCPP_HAS_EXCEPTIONS
462 sentry __s(*this);
463 if (__s) {
464 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
465 _Op __o(*this);
466 *__o = __c;
467 if (__o.failed())
468 this->setstate(ios_base::badbit);
469 }
470# if _LIBCPP_HAS_EXCEPTIONS
471 } catch (...) {
472 this->__set_badbit_and_consider_rethrow();
473 }
474# endif // _LIBCPP_HAS_EXCEPTIONS
475 return *this;
476}
477
478template <class _CharT, class _Traits>
479basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) {
480# if _LIBCPP_HAS_EXCEPTIONS
481 try {
482# endif // _LIBCPP_HAS_EXCEPTIONS
483 sentry __sen(*this);
484 if (__sen && __n) {
485 if (this->rdbuf()->sputn(__s, __n) != __n)
486 this->setstate(ios_base::badbit);
487 }
488# if _LIBCPP_HAS_EXCEPTIONS
489 } catch (...) {
490 this->__set_badbit_and_consider_rethrow();
491 }
492# endif // _LIBCPP_HAS_EXCEPTIONS
493 return *this;
494}
495
496template <class _CharT, class _Traits>
497basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::flush() {
498# if _LIBCPP_HAS_EXCEPTIONS
499 try {
500# endif // _LIBCPP_HAS_EXCEPTIONS
501 if (this->rdbuf()) {
502 sentry __s(*this);
503 if (__s) {
504 if (this->rdbuf()->pubsync() == -1)
505 this->setstate(ios_base::badbit);
506 }
507 }
508# if _LIBCPP_HAS_EXCEPTIONS
509 } catch (...) {
510 this->__set_badbit_and_consider_rethrow();
511 }
512# endif // _LIBCPP_HAS_EXCEPTIONS
513 return *this;
514}
515
516template <class _CharT, class _Traits>
517typename basic_ostream<_CharT, _Traits>::pos_type basic_ostream<_CharT, _Traits>::tellp() {
518 if (this->fail())
519 return pos_type(-1);
520 return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
521}
522
523template <class _CharT, class _Traits>
524basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) {
525 sentry __s(*this);
526 if (!this->fail()) {
527 if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
528 this->setstate(ios_base::failbit);
529 }
530 return *this;
531}
532
533template <class _CharT, class _Traits>
534basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir) {
535 sentry __s(*this);
536 if (!this->fail()) {
537 if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
538 this->setstate(ios_base::failbit);
539 }
540 return *this;
541}
542
543template <class _CharT, class _Traits>
544_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& endl(basic_ostream<_CharT, _Traits>& __os) {
545 __os.put(__os.widen('\n'));
546 __os.flush();
547 return __os;
548}
549
550template <class _CharT, class _Traits>
551_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& ends(basic_ostream<_CharT, _Traits>& __os) {
552 __os.put(_CharT());
553 return __os;
554}
555
556template <class _CharT, class _Traits>
557_LIBCPP_HIDE_FROM_ABI inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) {
558 __os.flush();
559 return __os;
560}
561
562template <class _Stream, class _Tp, class = void>
563struct __is_ostreamable : false_type {};
564
565template <class _Stream, class _Tp>
566struct __is_ostreamable<_Stream, _Tp, decltype(std::declval<_Stream>() << std::declval<_Tp>(), void())> : true_type {};
567
568template <class _Stream,
569 class _Tp,
570 __enable_if_t<_And<is_base_of<ios_base, _Stream>, __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0>
571_LIBCPP_HIDE_FROM_ABI _Stream&& operator<<(_Stream&& __os, const _Tp& __x) {
572 __os << __x;
573 return std::move(__os);
574}
575
576template <class _CharT, class _Traits, class _Allocator>
577basic_ostream<_CharT, _Traits>&
578operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) {
579 return std::__put_character_sequence(__os, __str.data(), __str.size());
580}
581
582template <class _CharT, class _Traits>
583_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
584operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv) {
585 return std::__put_character_sequence(__os, __sv.data(), __sv.size());
586}
587
588template <class _CharT, class _Traits>
589inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
590operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec) {
591 return __os << __ec.category().name() << ':' << __ec.value();
592}
593
594template <class _CharT, class _Traits, class _Yp>
595inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
596operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) {
597 return __os << __p.get();
598}
599
600template <
601 class _CharT,
602 class _Traits,
603 class _Yp,
604 class _Dp,
605 __enable_if_t<is_same<void,
606 __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>()
607 << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
608 int> = 0>
609inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
610operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) {
611 return __os << __p.get();
612}
613
614template <class _CharT, class _Traits, size_t _Size>
615_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
616operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) {
617 return __os << __x.template to_string<_CharT, _Traits>(std::use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
618 std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
619}
620
621# if _LIBCPP_STD_VER >= 20
622
623# if _LIBCPP_HAS_WIDE_CHARACTERS
624template <class _Traits>
625basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
626
627template <class _Traits>
628basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
629
630template <class _Traits>
631basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
632
633template <class _Traits>
634basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
635
636template <class _Traits>
637basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
638
639template <class _Traits>
640basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
641
642# endif // _LIBCPP_HAS_WIDE_CHARACTERS
643
644# if _LIBCPP_HAS_CHAR8_T
645template <class _Traits>
646basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
647
648template <class _Traits>
649basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
650
651template <class _Traits>
652basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
653
654template <class _Traits>
655basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
656# endif
657
658template <class _Traits>
659basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
660
661template <class _Traits>
662basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
663
664template <class _Traits>
665basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
666
667template <class _Traits>
668basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
669
670# endif // _LIBCPP_STD_VER >= 20
671
672extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
673# if _LIBCPP_HAS_WIDE_CHARACTERS
674extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
675# endif
676
677_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
678_LIBCPP_END_NAMESPACE_STD
679
680_LIBCPP_POP_MACROS
681
682#endif // _LIBCPP_HAS_LOCALIZATION
683
684#endif // _LIBCPP___OSTREAM_BASIC_OSTREAM_H
685