ostream 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  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
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_OSTREAM
  10. #define _LIBCPP_OSTREAM
  11. /*
  12. ostream synopsis
  13. template <class charT, class traits = char_traits<charT> >
  14. class basic_ostream
  15. : virtual public basic_ios<charT,traits>
  16. {
  17. public:
  18. // types (inherited from basic_ios (27.5.4)):
  19. typedef charT char_type;
  20. typedef traits traits_type;
  21. typedef typename traits_type::int_type int_type;
  22. typedef typename traits_type::pos_type pos_type;
  23. typedef typename traits_type::off_type off_type;
  24. // 27.7.2.2 Constructor/destructor:
  25. explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
  26. basic_ostream(basic_ostream&& rhs);
  27. virtual ~basic_ostream();
  28. // 27.7.2.3 Assign/swap
  29. basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
  30. basic_ostream& operator=(basic_ostream&& rhs);
  31. void swap(basic_ostream& rhs);
  32. // 27.7.2.4 Prefix/suffix:
  33. class sentry;
  34. // 27.7.2.6 Formatted output:
  35. basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
  36. basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
  37. basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
  38. basic_ostream& operator<<(bool n);
  39. basic_ostream& operator<<(short n);
  40. basic_ostream& operator<<(unsigned short n);
  41. basic_ostream& operator<<(int n);
  42. basic_ostream& operator<<(unsigned int n);
  43. basic_ostream& operator<<(long n);
  44. basic_ostream& operator<<(unsigned long n);
  45. basic_ostream& operator<<(long long n);
  46. basic_ostream& operator<<(unsigned long long n);
  47. basic_ostream& operator<<(float f);
  48. basic_ostream& operator<<(double f);
  49. basic_ostream& operator<<(long double f);
  50. basic_ostream& operator<<(const void* p);
  51. basic_ostream& operator<<(const volatile void* val); // C++23
  52. basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
  53. basic_ostream& operator<<(nullptr_t);
  54. // 27.7.2.7 Unformatted output:
  55. basic_ostream& put(char_type c);
  56. basic_ostream& write(const char_type* s, streamsize n);
  57. basic_ostream& flush();
  58. // 27.7.2.5 seeks:
  59. pos_type tellp();
  60. basic_ostream& seekp(pos_type);
  61. basic_ostream& seekp(off_type, ios_base::seekdir);
  62. protected:
  63. basic_ostream(const basic_ostream& rhs) = delete;
  64. basic_ostream(basic_ostream&& rhs);
  65. // 27.7.3.3 Assign/swap
  66. basic_ostream& operator=(basic_ostream& rhs) = delete;
  67. basic_ostream& operator=(const basic_ostream&& rhs);
  68. void swap(basic_ostream& rhs);
  69. };
  70. // 27.7.2.6.4 character inserters
  71. template<class charT, class traits>
  72. basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
  73. template<class charT, class traits>
  74. basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
  75. template<class traits>
  76. basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
  77. // signed and unsigned
  78. template<class traits>
  79. basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
  80. template<class traits>
  81. basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
  82. // NTBS
  83. template<class charT, class traits>
  84. basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
  85. template<class charT, class traits>
  86. basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
  87. template<class traits>
  88. basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
  89. // signed and unsigned
  90. template<class traits>
  91. basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
  92. template<class traits>
  93. basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
  94. // swap:
  95. template <class charT, class traits>
  96. void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
  97. template <class charT, class traits>
  98. basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
  99. template <class charT, class traits>
  100. basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
  101. template <class charT, class traits>
  102. basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
  103. // rvalue stream insertion
  104. template <class Stream, class T>
  105. Stream&& operator<<(Stream&& os, const T& x);
  106. template<class traits>
  107. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete; // since C++20
  108. template<class traits>
  109. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete; // since C++20
  110. template<class traits>
  111. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete; // since C++20
  112. template<class traits>
  113. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete; // since C++20
  114. template<class traits>
  115. basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete; // since C++20
  116. template<class traits>
  117. basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete; // since C++20
  118. template<class traits>
  119. basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete; // since C++20
  120. template<class traits>
  121. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete; // since C++20
  122. template<class traits>
  123. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char8_t*) = delete; // since C++20
  124. template<class traits>
  125. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char16_t*) = delete; // since C++20
  126. template<class traits>
  127. basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char32_t*) = delete; // since C++20
  128. template<class traits>
  129. basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete; // since C++20
  130. template<class traits>
  131. basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete; // since C++20
  132. template<class traits>
  133. basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete; // since C++20
  134. } // std
  135. */
  136. #include <__assert> // all public C++ headers provide the assertion handler
  137. #include <__config>
  138. #include <__exception/operations.h>
  139. #include <__fwd/ostream.h>
  140. #include <__memory/shared_ptr.h>
  141. #include <__memory/unique_ptr.h>
  142. #include <__system_error/error_code.h>
  143. #include <__type_traits/conjunction.h>
  144. #include <__type_traits/enable_if.h>
  145. #include <__type_traits/is_base_of.h>
  146. #include <__type_traits/void_t.h>
  147. #include <__utility/declval.h>
  148. #include <bitset>
  149. #include <ios>
  150. #include <locale>
  151. #include <new>
  152. #include <streambuf>
  153. #include <version>
  154. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  155. # pragma GCC system_header
  156. #endif
  157. _LIBCPP_BEGIN_NAMESPACE_STD
  158. template <class _CharT, class _Traits>
  159. class _LIBCPP_TEMPLATE_VIS basic_ostream
  160. : virtual public basic_ios<_CharT, _Traits>
  161. {
  162. public:
  163. // types (inherited from basic_ios (27.5.4)):
  164. typedef _CharT char_type;
  165. typedef _Traits traits_type;
  166. typedef typename traits_type::int_type int_type;
  167. typedef typename traits_type::pos_type pos_type;
  168. typedef typename traits_type::off_type off_type;
  169. // 27.7.2.2 Constructor/destructor:
  170. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  171. explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
  172. { this->init(__sb); }
  173. ~basic_ostream() override;
  174. protected:
  175. inline _LIBCPP_INLINE_VISIBILITY
  176. basic_ostream(basic_ostream&& __rhs);
  177. // 27.7.2.3 Assign/swap
  178. inline _LIBCPP_INLINE_VISIBILITY
  179. basic_ostream& operator=(basic_ostream&& __rhs);
  180. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  181. void swap(basic_ostream& __rhs)
  182. { basic_ios<char_type, traits_type>::swap(__rhs); }
  183. basic_ostream (const basic_ostream& __rhs) = delete;
  184. basic_ostream& operator=(const basic_ostream& __rhs) = delete;
  185. public:
  186. // 27.7.2.4 Prefix/suffix:
  187. class _LIBCPP_TEMPLATE_VIS sentry;
  188. // 27.7.2.6 Formatted output:
  189. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  190. basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
  191. { return __pf(*this); }
  192. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  193. basic_ostream& operator<<(basic_ios<char_type, traits_type>&
  194. (*__pf)(basic_ios<char_type,traits_type>&))
  195. { __pf(*this); return *this; }
  196. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  197. basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
  198. { __pf(*this); return *this; }
  199. basic_ostream& operator<<(bool __n);
  200. basic_ostream& operator<<(short __n);
  201. basic_ostream& operator<<(unsigned short __n);
  202. basic_ostream& operator<<(int __n);
  203. basic_ostream& operator<<(unsigned int __n);
  204. basic_ostream& operator<<(long __n);
  205. basic_ostream& operator<<(unsigned long __n);
  206. basic_ostream& operator<<(long long __n);
  207. basic_ostream& operator<<(unsigned long long __n);
  208. basic_ostream& operator<<(float __f);
  209. basic_ostream& operator<<(double __f);
  210. basic_ostream& operator<<(long double __f);
  211. basic_ostream& operator<<(const void* __p);
  212. #if _LIBCPP_STD_VER >= 23
  213. _LIBCPP_HIDE_FROM_ABI
  214. basic_ostream& operator<<(const volatile void* __p) {
  215. return operator<<(const_cast<const void*>(__p));
  216. }
  217. #endif
  218. basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
  219. #if _LIBCPP_STD_VER >= 17
  220. // LWG 2221 - nullptr. This is not backported to older standards modes.
  221. // See https://reviews.llvm.org/D127033 for more info on the rationale.
  222. _LIBCPP_INLINE_VISIBILITY
  223. basic_ostream& operator<<(nullptr_t)
  224. { return *this << "nullptr"; }
  225. #endif
  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();
  230. // 27.7.2.5 seeks:
  231. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  232. pos_type tellp();
  233. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  234. basic_ostream& seekp(pos_type __pos);
  235. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  236. basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
  237. protected:
  238. _LIBCPP_INLINE_VISIBILITY
  239. basic_ostream() {} // extension, intentially does not initialize
  240. };
  241. template <class _CharT, class _Traits>
  242. class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
  243. {
  244. bool __ok_;
  245. basic_ostream<_CharT, _Traits>& __os_;
  246. public:
  247. explicit sentry(basic_ostream<_CharT, _Traits>& __os);
  248. ~sentry();
  249. sentry(const sentry&) = delete;
  250. sentry& operator=(const sentry&) = delete;
  251. _LIBCPP_INLINE_VISIBILITY
  252. explicit operator bool() const {return __ok_;}
  253. };
  254. template <class _CharT, class _Traits>
  255. basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
  256. : __ok_(false),
  257. __os_(__os)
  258. {
  259. if (__os.good())
  260. {
  261. if (__os.tie())
  262. __os.tie()->flush();
  263. __ok_ = true;
  264. }
  265. }
  266. template <class _CharT, class _Traits>
  267. basic_ostream<_CharT, _Traits>::sentry::~sentry()
  268. {
  269. if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
  270. && !uncaught_exception())
  271. {
  272. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  273. try
  274. {
  275. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  276. if (__os_.rdbuf()->pubsync() == -1)
  277. __os_.setstate(ios_base::badbit);
  278. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  279. }
  280. catch (...)
  281. {
  282. }
  283. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  284. }
  285. }
  286. template <class _CharT, class _Traits>
  287. basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
  288. {
  289. this->move(__rhs);
  290. }
  291. template <class _CharT, class _Traits>
  292. basic_ostream<_CharT, _Traits>&
  293. basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
  294. {
  295. swap(__rhs);
  296. return *this;
  297. }
  298. template <class _CharT, class _Traits>
  299. basic_ostream<_CharT, _Traits>::~basic_ostream()
  300. {
  301. }
  302. template <class _CharT, class _Traits>
  303. basic_ostream<_CharT, _Traits>&
  304. basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
  305. {
  306. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  307. try
  308. {
  309. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  310. sentry __s(*this);
  311. if (__s)
  312. {
  313. if (__sb)
  314. {
  315. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  316. try
  317. {
  318. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  319. typedef istreambuf_iterator<_CharT, _Traits> _Ip;
  320. typedef ostreambuf_iterator<_CharT, _Traits> _Op;
  321. _Ip __i(__sb);
  322. _Ip __eof;
  323. _Op __o(*this);
  324. size_t __c = 0;
  325. for (; __i != __eof; ++__i, ++__o, ++__c)
  326. {
  327. *__o = *__i;
  328. if (__o.failed())
  329. break;
  330. }
  331. if (__c == 0)
  332. this->setstate(ios_base::failbit);
  333. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  334. }
  335. catch (...)
  336. {
  337. this->__set_failbit_and_consider_rethrow();
  338. }
  339. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  340. }
  341. else
  342. this->setstate(ios_base::badbit);
  343. }
  344. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  345. }
  346. catch (...)
  347. {
  348. this->__set_badbit_and_consider_rethrow();
  349. }
  350. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  351. return *this;
  352. }
  353. template <class _CharT, class _Traits>
  354. basic_ostream<_CharT, _Traits>&
  355. basic_ostream<_CharT, _Traits>::operator<<(bool __n)
  356. {
  357. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  358. try
  359. {
  360. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  361. sentry __s(*this);
  362. if (__s)
  363. {
  364. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  365. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  366. if (__f.put(*this, *this, this->fill(), __n).failed())
  367. this->setstate(ios_base::badbit | ios_base::failbit);
  368. }
  369. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  370. }
  371. catch (...)
  372. {
  373. this->__set_badbit_and_consider_rethrow();
  374. }
  375. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  376. return *this;
  377. }
  378. template <class _CharT, class _Traits>
  379. basic_ostream<_CharT, _Traits>&
  380. basic_ostream<_CharT, _Traits>::operator<<(short __n)
  381. {
  382. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  383. try
  384. {
  385. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  386. sentry __s(*this);
  387. if (__s)
  388. {
  389. ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
  390. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  391. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  392. if (__f.put(*this, *this, this->fill(),
  393. __flags == ios_base::oct || __flags == ios_base::hex ?
  394. static_cast<long>(static_cast<unsigned short>(__n)) :
  395. static_cast<long>(__n)).failed())
  396. this->setstate(ios_base::badbit | ios_base::failbit);
  397. }
  398. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  399. }
  400. catch (...)
  401. {
  402. this->__set_badbit_and_consider_rethrow();
  403. }
  404. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  405. return *this;
  406. }
  407. template <class _CharT, class _Traits>
  408. basic_ostream<_CharT, _Traits>&
  409. basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
  410. {
  411. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  412. try
  413. {
  414. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  415. sentry __s(*this);
  416. if (__s)
  417. {
  418. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  419. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  420. if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
  421. this->setstate(ios_base::badbit | ios_base::failbit);
  422. }
  423. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  424. }
  425. catch (...)
  426. {
  427. this->__set_badbit_and_consider_rethrow();
  428. }
  429. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  430. return *this;
  431. }
  432. template <class _CharT, class _Traits>
  433. basic_ostream<_CharT, _Traits>&
  434. basic_ostream<_CharT, _Traits>::operator<<(int __n)
  435. {
  436. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  437. try
  438. {
  439. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  440. sentry __s(*this);
  441. if (__s)
  442. {
  443. ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
  444. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  445. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  446. if (__f.put(*this, *this, this->fill(),
  447. __flags == ios_base::oct || __flags == ios_base::hex ?
  448. static_cast<long>(static_cast<unsigned int>(__n)) :
  449. static_cast<long>(__n)).failed())
  450. this->setstate(ios_base::badbit | ios_base::failbit);
  451. }
  452. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  453. }
  454. catch (...)
  455. {
  456. this->__set_badbit_and_consider_rethrow();
  457. }
  458. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  459. return *this;
  460. }
  461. template <class _CharT, class _Traits>
  462. basic_ostream<_CharT, _Traits>&
  463. basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
  464. {
  465. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  466. try
  467. {
  468. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  469. sentry __s(*this);
  470. if (__s)
  471. {
  472. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  473. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  474. if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
  475. this->setstate(ios_base::badbit | ios_base::failbit);
  476. }
  477. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  478. }
  479. catch (...)
  480. {
  481. this->__set_badbit_and_consider_rethrow();
  482. }
  483. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  484. return *this;
  485. }
  486. template <class _CharT, class _Traits>
  487. basic_ostream<_CharT, _Traits>&
  488. basic_ostream<_CharT, _Traits>::operator<<(long __n)
  489. {
  490. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  491. try
  492. {
  493. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  494. sentry __s(*this);
  495. if (__s)
  496. {
  497. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  498. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  499. if (__f.put(*this, *this, this->fill(), __n).failed())
  500. this->setstate(ios_base::badbit | ios_base::failbit);
  501. }
  502. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  503. }
  504. catch (...)
  505. {
  506. this->__set_badbit_and_consider_rethrow();
  507. }
  508. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  509. return *this;
  510. }
  511. template <class _CharT, class _Traits>
  512. basic_ostream<_CharT, _Traits>&
  513. basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
  514. {
  515. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  516. try
  517. {
  518. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  519. sentry __s(*this);
  520. if (__s)
  521. {
  522. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  523. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  524. if (__f.put(*this, *this, this->fill(), __n).failed())
  525. this->setstate(ios_base::badbit | ios_base::failbit);
  526. }
  527. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  528. }
  529. catch (...)
  530. {
  531. this->__set_badbit_and_consider_rethrow();
  532. }
  533. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  534. return *this;
  535. }
  536. template <class _CharT, class _Traits>
  537. basic_ostream<_CharT, _Traits>&
  538. basic_ostream<_CharT, _Traits>::operator<<(long long __n)
  539. {
  540. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  541. try
  542. {
  543. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  544. sentry __s(*this);
  545. if (__s)
  546. {
  547. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  548. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  549. if (__f.put(*this, *this, this->fill(), __n).failed())
  550. this->setstate(ios_base::badbit | ios_base::failbit);
  551. }
  552. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  553. }
  554. catch (...)
  555. {
  556. this->__set_badbit_and_consider_rethrow();
  557. }
  558. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  559. return *this;
  560. }
  561. template <class _CharT, class _Traits>
  562. basic_ostream<_CharT, _Traits>&
  563. basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
  564. {
  565. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  566. try
  567. {
  568. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  569. sentry __s(*this);
  570. if (__s)
  571. {
  572. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  573. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  574. if (__f.put(*this, *this, this->fill(), __n).failed())
  575. this->setstate(ios_base::badbit | ios_base::failbit);
  576. }
  577. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  578. }
  579. catch (...)
  580. {
  581. this->__set_badbit_and_consider_rethrow();
  582. }
  583. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  584. return *this;
  585. }
  586. template <class _CharT, class _Traits>
  587. basic_ostream<_CharT, _Traits>&
  588. basic_ostream<_CharT, _Traits>::operator<<(float __n)
  589. {
  590. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  591. try
  592. {
  593. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  594. sentry __s(*this);
  595. if (__s)
  596. {
  597. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  598. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  599. if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
  600. this->setstate(ios_base::badbit | ios_base::failbit);
  601. }
  602. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  603. }
  604. catch (...)
  605. {
  606. this->__set_badbit_and_consider_rethrow();
  607. }
  608. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  609. return *this;
  610. }
  611. template <class _CharT, class _Traits>
  612. basic_ostream<_CharT, _Traits>&
  613. basic_ostream<_CharT, _Traits>::operator<<(double __n)
  614. {
  615. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  616. try
  617. {
  618. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  619. sentry __s(*this);
  620. if (__s)
  621. {
  622. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  623. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  624. if (__f.put(*this, *this, this->fill(), __n).failed())
  625. this->setstate(ios_base::badbit | ios_base::failbit);
  626. }
  627. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  628. }
  629. catch (...)
  630. {
  631. this->__set_badbit_and_consider_rethrow();
  632. }
  633. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  634. return *this;
  635. }
  636. template <class _CharT, class _Traits>
  637. basic_ostream<_CharT, _Traits>&
  638. basic_ostream<_CharT, _Traits>::operator<<(long double __n)
  639. {
  640. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  641. try
  642. {
  643. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  644. sentry __s(*this);
  645. if (__s)
  646. {
  647. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  648. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  649. if (__f.put(*this, *this, this->fill(), __n).failed())
  650. this->setstate(ios_base::badbit | ios_base::failbit);
  651. }
  652. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  653. }
  654. catch (...)
  655. {
  656. this->__set_badbit_and_consider_rethrow();
  657. }
  658. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  659. return *this;
  660. }
  661. template <class _CharT, class _Traits>
  662. basic_ostream<_CharT, _Traits>&
  663. basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
  664. {
  665. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  666. try
  667. {
  668. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  669. sentry __s(*this);
  670. if (__s)
  671. {
  672. typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
  673. const _Fp& __f = std::use_facet<_Fp>(this->getloc());
  674. if (__f.put(*this, *this, this->fill(), __n).failed())
  675. this->setstate(ios_base::badbit | ios_base::failbit);
  676. }
  677. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  678. }
  679. catch (...)
  680. {
  681. this->__set_badbit_and_consider_rethrow();
  682. }
  683. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  684. return *this;
  685. }
  686. template<class _CharT, class _Traits>
  687. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  688. __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
  689. const _CharT* __str, size_t __len)
  690. {
  691. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  692. try
  693. {
  694. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  695. typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
  696. if (__s)
  697. {
  698. typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
  699. if (std::__pad_and_output(_Ip(__os),
  700. __str,
  701. (__os.flags() & ios_base::adjustfield) == ios_base::left ?
  702. __str + __len :
  703. __str,
  704. __str + __len,
  705. __os,
  706. __os.fill()).failed())
  707. __os.setstate(ios_base::badbit | ios_base::failbit);
  708. }
  709. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  710. }
  711. catch (...)
  712. {
  713. __os.__set_badbit_and_consider_rethrow();
  714. }
  715. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  716. return __os;
  717. }
  718. template<class _CharT, class _Traits>
  719. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  720. operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
  721. {
  722. return _VSTD::__put_character_sequence(__os, &__c, 1);
  723. }
  724. template<class _CharT, class _Traits>
  725. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  726. operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
  727. {
  728. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  729. try
  730. {
  731. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  732. typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
  733. if (__s)
  734. {
  735. _CharT __c = __os.widen(__cn);
  736. typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
  737. if (std::__pad_and_output(_Ip(__os),
  738. &__c,
  739. (__os.flags() & ios_base::adjustfield) == ios_base::left ?
  740. &__c + 1 :
  741. &__c,
  742. &__c + 1,
  743. __os,
  744. __os.fill()).failed())
  745. __os.setstate(ios_base::badbit | ios_base::failbit);
  746. }
  747. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  748. }
  749. catch (...)
  750. {
  751. __os.__set_badbit_and_consider_rethrow();
  752. }
  753. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  754. return __os;
  755. }
  756. template<class _Traits>
  757. _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
  758. operator<<(basic_ostream<char, _Traits>& __os, char __c)
  759. {
  760. return _VSTD::__put_character_sequence(__os, &__c, 1);
  761. }
  762. template<class _Traits>
  763. _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
  764. operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
  765. {
  766. return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
  767. }
  768. template<class _Traits>
  769. _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
  770. operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
  771. {
  772. return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
  773. }
  774. template<class _CharT, class _Traits>
  775. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  776. operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
  777. {
  778. return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
  779. }
  780. template<class _CharT, class _Traits>
  781. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  782. operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
  783. {
  784. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  785. try
  786. {
  787. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  788. typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
  789. if (__s)
  790. {
  791. typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
  792. size_t __len = char_traits<char>::length(__strn);
  793. const int __bs = 100;
  794. _CharT __wbb[__bs];
  795. _CharT* __wb = __wbb;
  796. unique_ptr<_CharT, void(*)(void*)> __h(0, free);
  797. if (__len > __bs)
  798. {
  799. __wb = (_CharT*)malloc(__len*sizeof(_CharT));
  800. if (__wb == 0)
  801. __throw_bad_alloc();
  802. __h.reset(__wb);
  803. }
  804. for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
  805. *__p = __os.widen(*__strn);
  806. if (std::__pad_and_output(_Ip(__os),
  807. __wb,
  808. (__os.flags() & ios_base::adjustfield) == ios_base::left ?
  809. __wb + __len :
  810. __wb,
  811. __wb + __len,
  812. __os,
  813. __os.fill()).failed())
  814. __os.setstate(ios_base::badbit | ios_base::failbit);
  815. }
  816. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  817. }
  818. catch (...)
  819. {
  820. __os.__set_badbit_and_consider_rethrow();
  821. }
  822. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  823. return __os;
  824. }
  825. template<class _Traits>
  826. _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
  827. operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
  828. {
  829. return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
  830. }
  831. template<class _Traits>
  832. _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
  833. operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
  834. {
  835. const char *__s = (const char *) __str;
  836. return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
  837. }
  838. template<class _Traits>
  839. _LIBCPP_HIDE_FROM_ABI basic_ostream<char, _Traits>&
  840. operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
  841. {
  842. const char *__s = (const char *) __str;
  843. return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
  844. }
  845. template <class _CharT, class _Traits>
  846. basic_ostream<_CharT, _Traits>&
  847. basic_ostream<_CharT, _Traits>::put(char_type __c)
  848. {
  849. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  850. try
  851. {
  852. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  853. sentry __s(*this);
  854. if (__s)
  855. {
  856. typedef ostreambuf_iterator<_CharT, _Traits> _Op;
  857. _Op __o(*this);
  858. *__o = __c;
  859. if (__o.failed())
  860. this->setstate(ios_base::badbit);
  861. }
  862. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  863. }
  864. catch (...)
  865. {
  866. this->__set_badbit_and_consider_rethrow();
  867. }
  868. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  869. return *this;
  870. }
  871. template <class _CharT, class _Traits>
  872. basic_ostream<_CharT, _Traits>&
  873. basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
  874. {
  875. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  876. try
  877. {
  878. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  879. sentry __sen(*this);
  880. if (__sen && __n)
  881. {
  882. if (this->rdbuf()->sputn(__s, __n) != __n)
  883. this->setstate(ios_base::badbit);
  884. }
  885. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  886. }
  887. catch (...)
  888. {
  889. this->__set_badbit_and_consider_rethrow();
  890. }
  891. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  892. return *this;
  893. }
  894. template <class _CharT, class _Traits>
  895. basic_ostream<_CharT, _Traits>&
  896. basic_ostream<_CharT, _Traits>::flush()
  897. {
  898. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  899. try
  900. {
  901. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  902. if (this->rdbuf())
  903. {
  904. sentry __s(*this);
  905. if (__s)
  906. {
  907. if (this->rdbuf()->pubsync() == -1)
  908. this->setstate(ios_base::badbit);
  909. }
  910. }
  911. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  912. }
  913. catch (...)
  914. {
  915. this->__set_badbit_and_consider_rethrow();
  916. }
  917. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  918. return *this;
  919. }
  920. template <class _CharT, class _Traits>
  921. typename basic_ostream<_CharT, _Traits>::pos_type
  922. basic_ostream<_CharT, _Traits>::tellp()
  923. {
  924. if (this->fail())
  925. return pos_type(-1);
  926. return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
  927. }
  928. template <class _CharT, class _Traits>
  929. basic_ostream<_CharT, _Traits>&
  930. basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
  931. {
  932. sentry __s(*this);
  933. if (!this->fail())
  934. {
  935. if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
  936. this->setstate(ios_base::failbit);
  937. }
  938. return *this;
  939. }
  940. template <class _CharT, class _Traits>
  941. basic_ostream<_CharT, _Traits>&
  942. basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
  943. {
  944. sentry __s(*this);
  945. if (!this->fail())
  946. {
  947. if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
  948. this->setstate(ios_base::failbit);
  949. }
  950. return *this;
  951. }
  952. template <class _CharT, class _Traits>
  953. _LIBCPP_HIDE_FROM_ABI inline
  954. basic_ostream<_CharT, _Traits>&
  955. endl(basic_ostream<_CharT, _Traits>& __os)
  956. {
  957. __os.put(__os.widen('\n'));
  958. __os.flush();
  959. return __os;
  960. }
  961. template <class _CharT, class _Traits>
  962. _LIBCPP_HIDE_FROM_ABI inline
  963. basic_ostream<_CharT, _Traits>&
  964. ends(basic_ostream<_CharT, _Traits>& __os)
  965. {
  966. __os.put(_CharT());
  967. return __os;
  968. }
  969. template <class _CharT, class _Traits>
  970. _LIBCPP_HIDE_FROM_ABI inline
  971. basic_ostream<_CharT, _Traits>&
  972. flush(basic_ostream<_CharT, _Traits>& __os)
  973. {
  974. __os.flush();
  975. return __os;
  976. }
  977. template <class _Stream, class _Tp, class = void>
  978. struct __is_ostreamable : false_type { };
  979. template <class _Stream, class _Tp>
  980. struct __is_ostreamable<_Stream, _Tp, decltype(
  981. std::declval<_Stream>() << std::declval<_Tp>(), void()
  982. )> : true_type { };
  983. template <class _Stream,
  984. class _Tp,
  985. __enable_if_t<_And<is_base_of<ios_base, _Stream>, __is_ostreamable<_Stream&, const _Tp&> >::value, int> = 0>
  986. _LIBCPP_INLINE_VISIBILITY
  987. _Stream&& operator<<(_Stream&& __os, const _Tp& __x)
  988. {
  989. __os << __x;
  990. return _VSTD::move(__os);
  991. }
  992. template<class _CharT, class _Traits, class _Allocator>
  993. basic_ostream<_CharT, _Traits>&
  994. operator<<(basic_ostream<_CharT, _Traits>& __os,
  995. const basic_string<_CharT, _Traits, _Allocator>& __str)
  996. {
  997. return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
  998. }
  999. template<class _CharT, class _Traits>
  1000. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  1001. operator<<(basic_ostream<_CharT, _Traits>& __os,
  1002. basic_string_view<_CharT, _Traits> __sv)
  1003. {
  1004. return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
  1005. }
  1006. template <class _CharT, class _Traits>
  1007. inline _LIBCPP_INLINE_VISIBILITY
  1008. basic_ostream<_CharT, _Traits>&
  1009. operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
  1010. {
  1011. return __os << __ec.category().name() << ':' << __ec.value();
  1012. }
  1013. template<class _CharT, class _Traits, class _Yp>
  1014. inline _LIBCPP_INLINE_VISIBILITY
  1015. basic_ostream<_CharT, _Traits>&
  1016. operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
  1017. {
  1018. return __os << __p.get();
  1019. }
  1020. template <
  1021. class _CharT,
  1022. class _Traits,
  1023. class _Yp,
  1024. class _Dp,
  1025. __enable_if_t<is_same<void,
  1026. __void_t<decltype((std::declval<basic_ostream<_CharT, _Traits>&>()
  1027. << std::declval<typename unique_ptr<_Yp, _Dp>::pointer>()))> >::value,
  1028. int> = 0>
  1029. inline _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>&
  1030. operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) {
  1031. return __os << __p.get();
  1032. }
  1033. template <class _CharT, class _Traits, size_t _Size>
  1034. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  1035. operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
  1036. {
  1037. return __os << __x.template to_string<_CharT, _Traits>
  1038. (std::use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
  1039. std::use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
  1040. }
  1041. #if 0
  1042. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1043. template <class _Traits>
  1044. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
  1045. template <class _Traits>
  1046. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
  1047. template <class _Traits>
  1048. basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
  1049. template <class _Traits>
  1050. basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
  1051. template <class _Traits>
  1052. basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
  1053. template <class _Traits>
  1054. basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
  1055. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1056. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  1057. template <class _Traits>
  1058. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
  1059. template <class _Traits>
  1060. basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
  1061. template <class _Traits>
  1062. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
  1063. template <class _Traits>
  1064. basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
  1065. #endif
  1066. template <class _Traits>
  1067. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
  1068. template <class _Traits>
  1069. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
  1070. template <class _Traits>
  1071. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
  1072. template <class _Traits>
  1073. basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
  1074. #endif // _LIBCPP_STD_VER >= 20
  1075. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
  1076. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1077. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;
  1078. #endif
  1079. _LIBCPP_END_NAMESPACE_STD
  1080. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  1081. # include <atomic>
  1082. # include <concepts>
  1083. # include <cstdlib>
  1084. # include <iterator>
  1085. # include <type_traits>
  1086. #endif
  1087. #endif // _LIBCPP_OSTREAM