ostream 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. // Output streams -*- C++ -*-
  2. // Copyright (C) 1997-2019 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/ostream
  21. * This is a Standard C++ Library header.
  22. */
  23. //
  24. // ISO C++ 14882: 27.6.2 Output streams
  25. //
  26. #ifndef _GLIBCXX_OSTREAM
  27. #define _GLIBCXX_OSTREAM 1
  28. #pragma GCC system_header
  29. #include <ios>
  30. #include <bits/ostream_insert.h>
  31. namespace std _GLIBCXX_VISIBILITY(default)
  32. {
  33. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  34. /**
  35. * @brief Template class basic_ostream.
  36. * @ingroup io
  37. *
  38. * @tparam _CharT Type of character stream.
  39. * @tparam _Traits Traits for character type, defaults to
  40. * char_traits<_CharT>.
  41. *
  42. * This is the base class for all output streams. It provides text
  43. * formatting of all builtin types, and communicates with any class
  44. * derived from basic_streambuf to do the actual output.
  45. */
  46. template<typename _CharT, typename _Traits>
  47. class basic_ostream : virtual public basic_ios<_CharT, _Traits>
  48. {
  49. public:
  50. // Types (inherited from basic_ios):
  51. typedef _CharT char_type;
  52. typedef typename _Traits::int_type int_type;
  53. typedef typename _Traits::pos_type pos_type;
  54. typedef typename _Traits::off_type off_type;
  55. typedef _Traits traits_type;
  56. // Non-standard Types:
  57. typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
  58. typedef basic_ios<_CharT, _Traits> __ios_type;
  59. typedef basic_ostream<_CharT, _Traits> __ostream_type;
  60. typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
  61. __num_put_type;
  62. typedef ctype<_CharT> __ctype_type;
  63. /**
  64. * @brief Base constructor.
  65. *
  66. * This ctor is almost never called by the user directly, rather from
  67. * derived classes' initialization lists, which pass a pointer to
  68. * their own stream buffer.
  69. */
  70. explicit
  71. basic_ostream(__streambuf_type* __sb)
  72. { this->init(__sb); }
  73. /**
  74. * @brief Base destructor.
  75. *
  76. * This does very little apart from providing a virtual base dtor.
  77. */
  78. virtual
  79. ~basic_ostream() { }
  80. /// Safe prefix/suffix operations.
  81. class sentry;
  82. friend class sentry;
  83. //@{
  84. /**
  85. * @brief Interface for manipulators.
  86. *
  87. * Manipulators such as @c std::endl and @c std::hex use these
  88. * functions in constructs like "std::cout << std::endl". For more
  89. * information, see the iomanip header.
  90. */
  91. __ostream_type&
  92. operator<<(__ostream_type& (*__pf)(__ostream_type&))
  93. {
  94. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  95. // DR 60. What is a formatted input function?
  96. // The inserters for manipulators are *not* formatted output functions.
  97. return __pf(*this);
  98. }
  99. __ostream_type&
  100. operator<<(__ios_type& (*__pf)(__ios_type&))
  101. {
  102. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  103. // DR 60. What is a formatted input function?
  104. // The inserters for manipulators are *not* formatted output functions.
  105. __pf(*this);
  106. return *this;
  107. }
  108. __ostream_type&
  109. operator<<(ios_base& (*__pf) (ios_base&))
  110. {
  111. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  112. // DR 60. What is a formatted input function?
  113. // The inserters for manipulators are *not* formatted output functions.
  114. __pf(*this);
  115. return *this;
  116. }
  117. //@}
  118. //@{
  119. /**
  120. * @name Inserters
  121. *
  122. * All the @c operator<< functions (aka <em>formatted output
  123. * functions</em>) have some common behavior. Each starts by
  124. * constructing a temporary object of type std::basic_ostream::sentry.
  125. * This can have several effects, concluding with the setting of a
  126. * status flag; see the sentry documentation for more.
  127. *
  128. * If the sentry status is good, the function tries to generate
  129. * whatever data is appropriate for the type of the argument.
  130. *
  131. * If an exception is thrown during insertion, ios_base::badbit
  132. * will be turned on in the stream's error state without causing an
  133. * ios_base::failure to be thrown. The original exception will then
  134. * be rethrown.
  135. */
  136. //@{
  137. /**
  138. * @brief Integer arithmetic inserters
  139. * @param __n A variable of builtin integral type.
  140. * @return @c *this if successful
  141. *
  142. * These functions use the stream's current locale (specifically, the
  143. * @c num_get facet) to perform numeric formatting.
  144. */
  145. __ostream_type&
  146. operator<<(long __n)
  147. { return _M_insert(__n); }
  148. __ostream_type&
  149. operator<<(unsigned long __n)
  150. { return _M_insert(__n); }
  151. __ostream_type&
  152. operator<<(bool __n)
  153. { return _M_insert(__n); }
  154. __ostream_type&
  155. operator<<(short __n);
  156. __ostream_type&
  157. operator<<(unsigned short __n)
  158. {
  159. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  160. // 117. basic_ostream uses nonexistent num_put member functions.
  161. return _M_insert(static_cast<unsigned long>(__n));
  162. }
  163. __ostream_type&
  164. operator<<(int __n);
  165. __ostream_type&
  166. operator<<(unsigned int __n)
  167. {
  168. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  169. // 117. basic_ostream uses nonexistent num_put member functions.
  170. return _M_insert(static_cast<unsigned long>(__n));
  171. }
  172. #ifdef _GLIBCXX_USE_LONG_LONG
  173. __ostream_type&
  174. operator<<(long long __n)
  175. { return _M_insert(__n); }
  176. __ostream_type&
  177. operator<<(unsigned long long __n)
  178. { return _M_insert(__n); }
  179. #endif
  180. //@}
  181. //@{
  182. /**
  183. * @brief Floating point arithmetic inserters
  184. * @param __f A variable of builtin floating point type.
  185. * @return @c *this if successful
  186. *
  187. * These functions use the stream's current locale (specifically, the
  188. * @c num_get facet) to perform numeric formatting.
  189. */
  190. __ostream_type&
  191. operator<<(double __f)
  192. { return _M_insert(__f); }
  193. __ostream_type&
  194. operator<<(float __f)
  195. {
  196. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  197. // 117. basic_ostream uses nonexistent num_put member functions.
  198. return _M_insert(static_cast<double>(__f));
  199. }
  200. __ostream_type&
  201. operator<<(long double __f)
  202. { return _M_insert(__f); }
  203. //@}
  204. /**
  205. * @brief Pointer arithmetic inserters
  206. * @param __p A variable of pointer type.
  207. * @return @c *this if successful
  208. *
  209. * These functions use the stream's current locale (specifically, the
  210. * @c num_get facet) to perform numeric formatting.
  211. */
  212. __ostream_type&
  213. operator<<(const void* __p)
  214. { return _M_insert(__p); }
  215. #if __cplusplus >= 201703L
  216. __ostream_type&
  217. operator<<(nullptr_t)
  218. { return *this << "nullptr"; }
  219. #endif
  220. /**
  221. * @brief Extracting from another streambuf.
  222. * @param __sb A pointer to a streambuf
  223. *
  224. * This function behaves like one of the basic arithmetic extractors,
  225. * in that it also constructs a sentry object and has the same error
  226. * handling behavior.
  227. *
  228. * If @p __sb is NULL, the stream will set failbit in its error state.
  229. *
  230. * Characters are extracted from @p __sb and inserted into @c *this
  231. * until one of the following occurs:
  232. *
  233. * - the input stream reaches end-of-file,
  234. * - insertion into the output sequence fails (in this case, the
  235. * character that would have been inserted is not extracted), or
  236. * - an exception occurs while getting a character from @p __sb, which
  237. * sets failbit in the error state
  238. *
  239. * If the function inserts no characters, failbit is set.
  240. */
  241. __ostream_type&
  242. operator<<(__streambuf_type* __sb);
  243. //@}
  244. //@{
  245. /**
  246. * @name Unformatted Output Functions
  247. *
  248. * All the unformatted output functions have some common behavior.
  249. * Each starts by constructing a temporary object of type
  250. * std::basic_ostream::sentry. This has several effects, concluding
  251. * with the setting of a status flag; see the sentry documentation
  252. * for more.
  253. *
  254. * If the sentry status is good, the function tries to generate
  255. * whatever data is appropriate for the type of the argument.
  256. *
  257. * If an exception is thrown during insertion, ios_base::badbit
  258. * will be turned on in the stream's error state. If badbit is on in
  259. * the stream's exceptions mask, the exception will be rethrown
  260. * without completing its actions.
  261. */
  262. /**
  263. * @brief Simple insertion.
  264. * @param __c The character to insert.
  265. * @return *this
  266. *
  267. * Tries to insert @p __c.
  268. *
  269. * @note This function is not overloaded on signed char and
  270. * unsigned char.
  271. */
  272. __ostream_type&
  273. put(char_type __c);
  274. /**
  275. * @brief Core write functionality, without sentry.
  276. * @param __s The array to insert.
  277. * @param __n Maximum number of characters to insert.
  278. */
  279. void
  280. _M_write(const char_type* __s, streamsize __n)
  281. {
  282. const streamsize __put = this->rdbuf()->sputn(__s, __n);
  283. if (__put != __n)
  284. this->setstate(ios_base::badbit);
  285. }
  286. /**
  287. * @brief Character string insertion.
  288. * @param __s The array to insert.
  289. * @param __n Maximum number of characters to insert.
  290. * @return *this
  291. *
  292. * Characters are copied from @p __s and inserted into the stream until
  293. * one of the following happens:
  294. *
  295. * - @p __n characters are inserted
  296. * - inserting into the output sequence fails (in this case, badbit
  297. * will be set in the stream's error state)
  298. *
  299. * @note This function is not overloaded on signed char and
  300. * unsigned char.
  301. */
  302. __ostream_type&
  303. write(const char_type* __s, streamsize __n);
  304. //@}
  305. /**
  306. * @brief Synchronizing the stream buffer.
  307. * @return *this
  308. *
  309. * If @c rdbuf() is a null pointer, changes nothing.
  310. *
  311. * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
  312. * sets badbit.
  313. */
  314. __ostream_type&
  315. flush();
  316. /**
  317. * @brief Getting the current write position.
  318. * @return A file position object.
  319. *
  320. * If @c fail() is not false, returns @c pos_type(-1) to indicate
  321. * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,out).
  322. */
  323. pos_type
  324. tellp();
  325. /**
  326. * @brief Changing the current write position.
  327. * @param __pos A file position object.
  328. * @return *this
  329. *
  330. * If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos). If
  331. * that function fails, sets failbit.
  332. */
  333. __ostream_type&
  334. seekp(pos_type);
  335. /**
  336. * @brief Changing the current write position.
  337. * @param __off A file offset object.
  338. * @param __dir The direction in which to seek.
  339. * @return *this
  340. *
  341. * If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir).
  342. * If that function fails, sets failbit.
  343. */
  344. __ostream_type&
  345. seekp(off_type, ios_base::seekdir);
  346. protected:
  347. basic_ostream()
  348. { this->init(0); }
  349. #if __cplusplus >= 201103L
  350. // Non-standard constructor that does not call init()
  351. basic_ostream(basic_iostream<_CharT, _Traits>&) { }
  352. basic_ostream(const basic_ostream&) = delete;
  353. basic_ostream(basic_ostream&& __rhs)
  354. : __ios_type()
  355. { __ios_type::move(__rhs); }
  356. // 27.7.3.3 Assign/swap
  357. basic_ostream& operator=(const basic_ostream&) = delete;
  358. basic_ostream&
  359. operator=(basic_ostream&& __rhs)
  360. {
  361. swap(__rhs);
  362. return *this;
  363. }
  364. void
  365. swap(basic_ostream& __rhs)
  366. { __ios_type::swap(__rhs); }
  367. #endif
  368. template<typename _ValueT>
  369. __ostream_type&
  370. _M_insert(_ValueT __v);
  371. };
  372. /**
  373. * @brief Performs setup work for output streams.
  374. *
  375. * Objects of this class are created before all of the standard
  376. * inserters are run. It is responsible for <em>exception-safe prefix and
  377. * suffix operations</em>.
  378. */
  379. template <typename _CharT, typename _Traits>
  380. class basic_ostream<_CharT, _Traits>::sentry
  381. {
  382. // Data Members.
  383. bool _M_ok;
  384. basic_ostream<_CharT, _Traits>& _M_os;
  385. public:
  386. /**
  387. * @brief The constructor performs preparatory work.
  388. * @param __os The output stream to guard.
  389. *
  390. * If the stream state is good (@a __os.good() is true), then if the
  391. * stream is tied to another output stream, @c is.tie()->flush()
  392. * is called to synchronize the output sequences.
  393. *
  394. * If the stream state is still good, then the sentry state becomes
  395. * true (@a okay).
  396. */
  397. explicit
  398. sentry(basic_ostream<_CharT, _Traits>& __os);
  399. #pragma GCC diagnostic push
  400. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  401. /**
  402. * @brief Possibly flushes the stream.
  403. *
  404. * If @c ios_base::unitbuf is set in @c os.flags(), and
  405. * @c std::uncaught_exception() is true, the sentry destructor calls
  406. * @c flush() on the output stream.
  407. */
  408. ~sentry()
  409. {
  410. // XXX MT
  411. if (bool(_M_os.flags() & ios_base::unitbuf) && !uncaught_exception())
  412. {
  413. // Can't call flush directly or else will get into recursive lock.
  414. if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
  415. _M_os.setstate(ios_base::badbit);
  416. }
  417. }
  418. #pragma GCC diagnostic pop
  419. /**
  420. * @brief Quick status checking.
  421. * @return The sentry state.
  422. *
  423. * For ease of use, sentries may be converted to booleans. The
  424. * return value is that of the sentry state (true == okay).
  425. */
  426. #if __cplusplus >= 201103L
  427. explicit
  428. #endif
  429. operator bool() const
  430. { return _M_ok; }
  431. };
  432. //@{
  433. /**
  434. * @brief Character inserters
  435. * @param __out An output stream.
  436. * @param __c A character.
  437. * @return out
  438. *
  439. * Behaves like one of the formatted arithmetic inserters described in
  440. * std::basic_ostream. After constructing a sentry object with good
  441. * status, this function inserts a single character and any required
  442. * padding (as determined by [22.2.2.2.2]). @c __out.width(0) is then
  443. * called.
  444. *
  445. * If @p __c is of type @c char and the character type of the stream is not
  446. * @c char, the character is widened before insertion.
  447. */
  448. template<typename _CharT, typename _Traits>
  449. inline basic_ostream<_CharT, _Traits>&
  450. operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
  451. { return __ostream_insert(__out, &__c, 1); }
  452. template<typename _CharT, typename _Traits>
  453. inline basic_ostream<_CharT, _Traits>&
  454. operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
  455. { return (__out << __out.widen(__c)); }
  456. // Specialization
  457. template <class _Traits>
  458. inline basic_ostream<char, _Traits>&
  459. operator<<(basic_ostream<char, _Traits>& __out, char __c)
  460. { return __ostream_insert(__out, &__c, 1); }
  461. // Signed and unsigned
  462. template<class _Traits>
  463. inline basic_ostream<char, _Traits>&
  464. operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
  465. { return (__out << static_cast<char>(__c)); }
  466. template<class _Traits>
  467. inline basic_ostream<char, _Traits>&
  468. operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
  469. { return (__out << static_cast<char>(__c)); }
  470. //@}
  471. //@{
  472. /**
  473. * @brief String inserters
  474. * @param __out An output stream.
  475. * @param __s A character string.
  476. * @return out
  477. * @pre @p __s must be a non-NULL pointer
  478. *
  479. * Behaves like one of the formatted arithmetic inserters described in
  480. * std::basic_ostream. After constructing a sentry object with good
  481. * status, this function inserts @c traits::length(__s) characters starting
  482. * at @p __s, widened if necessary, followed by any required padding (as
  483. * determined by [22.2.2.2.2]). @c __out.width(0) is then called.
  484. */
  485. template<typename _CharT, typename _Traits>
  486. inline basic_ostream<_CharT, _Traits>&
  487. operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
  488. {
  489. if (!__s)
  490. __out.setstate(ios_base::badbit);
  491. else
  492. __ostream_insert(__out, __s,
  493. static_cast<streamsize>(_Traits::length(__s)));
  494. return __out;
  495. }
  496. template<typename _CharT, typename _Traits>
  497. basic_ostream<_CharT, _Traits> &
  498. operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
  499. // Partial specializations
  500. template<class _Traits>
  501. inline basic_ostream<char, _Traits>&
  502. operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
  503. {
  504. if (!__s)
  505. __out.setstate(ios_base::badbit);
  506. else
  507. __ostream_insert(__out, __s,
  508. static_cast<streamsize>(_Traits::length(__s)));
  509. return __out;
  510. }
  511. // Signed and unsigned
  512. template<class _Traits>
  513. inline basic_ostream<char, _Traits>&
  514. operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
  515. { return (__out << reinterpret_cast<const char*>(__s)); }
  516. template<class _Traits>
  517. inline basic_ostream<char, _Traits> &
  518. operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
  519. { return (__out << reinterpret_cast<const char*>(__s)); }
  520. //@}
  521. // Standard basic_ostream manipulators
  522. /**
  523. * @brief Write a newline and flush the stream.
  524. *
  525. * This manipulator is often mistakenly used when a simple newline is
  526. * desired, leading to poor buffering performance. See
  527. * https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering
  528. * for more on this subject.
  529. */
  530. template<typename _CharT, typename _Traits>
  531. inline basic_ostream<_CharT, _Traits>&
  532. endl(basic_ostream<_CharT, _Traits>& __os)
  533. { return flush(__os.put(__os.widen('\n'))); }
  534. /**
  535. * @brief Write a null character into the output sequence.
  536. *
  537. * <em>Null character</em> is @c CharT() by definition. For CharT
  538. * of @c char, this correctly writes the ASCII @c NUL character
  539. * string terminator.
  540. */
  541. template<typename _CharT, typename _Traits>
  542. inline basic_ostream<_CharT, _Traits>&
  543. ends(basic_ostream<_CharT, _Traits>& __os)
  544. { return __os.put(_CharT()); }
  545. /**
  546. * @brief Flushes the output stream.
  547. *
  548. * This manipulator simply calls the stream's @c flush() member function.
  549. */
  550. template<typename _CharT, typename _Traits>
  551. inline basic_ostream<_CharT, _Traits>&
  552. flush(basic_ostream<_CharT, _Traits>& __os)
  553. { return __os.flush(); }
  554. #if __cplusplus >= 201103L
  555. template<typename _Ch, typename _Up>
  556. basic_ostream<_Ch, _Up>&
  557. __is_convertible_to_basic_ostream_test(basic_ostream<_Ch, _Up>*);
  558. template<typename _Tp, typename = void>
  559. struct __is_convertible_to_basic_ostream_impl
  560. {
  561. using __ostream_type = void;
  562. };
  563. template<typename _Tp>
  564. using __do_is_convertible_to_basic_ostream_impl =
  565. decltype(__is_convertible_to_basic_ostream_test
  566. (declval<typename remove_reference<_Tp>::type*>()));
  567. template<typename _Tp>
  568. struct __is_convertible_to_basic_ostream_impl
  569. <_Tp,
  570. __void_t<__do_is_convertible_to_basic_ostream_impl<_Tp>>>
  571. {
  572. using __ostream_type =
  573. __do_is_convertible_to_basic_ostream_impl<_Tp>;
  574. };
  575. template<typename _Tp>
  576. struct __is_convertible_to_basic_ostream
  577. : __is_convertible_to_basic_ostream_impl<_Tp>
  578. {
  579. public:
  580. using type = __not_<is_void<
  581. typename __is_convertible_to_basic_ostream_impl<_Tp>::__ostream_type>>;
  582. constexpr static bool value = type::value;
  583. };
  584. template<typename _Ostream, typename _Tp, typename = void>
  585. struct __is_insertable : false_type {};
  586. template<typename _Ostream, typename _Tp>
  587. struct __is_insertable<_Ostream, _Tp,
  588. __void_t<decltype(declval<_Ostream&>()
  589. << declval<const _Tp&>())>>
  590. : true_type {};
  591. template<typename _Ostream>
  592. using __rvalue_ostream_type =
  593. typename __is_convertible_to_basic_ostream<
  594. _Ostream>::__ostream_type;
  595. /**
  596. * @brief Generic inserter for rvalue stream
  597. * @param __os An input stream.
  598. * @param __x A reference to the object being inserted.
  599. * @return os
  600. *
  601. * This is just a forwarding function to allow insertion to
  602. * rvalue streams since they won't bind to the inserter functions
  603. * that take an lvalue reference.
  604. */
  605. template<typename _Ostream, typename _Tp>
  606. inline
  607. typename enable_if<__and_<__not_<is_lvalue_reference<_Ostream>>,
  608. __is_convertible_to_basic_ostream<_Ostream>,
  609. __is_insertable<
  610. __rvalue_ostream_type<_Ostream>,
  611. const _Tp&>>::value,
  612. __rvalue_ostream_type<_Ostream>>::type
  613. operator<<(_Ostream&& __os, const _Tp& __x)
  614. {
  615. __rvalue_ostream_type<_Ostream> __ret_os = __os;
  616. __ret_os << __x;
  617. return __ret_os;
  618. }
  619. #endif // C++11
  620. _GLIBCXX_END_NAMESPACE_VERSION
  621. } // namespace std
  622. #include <bits/ostream.tcc>
  623. #endif /* _GLIBCXX_OSTREAM */