std_ostream.h revision 169691
1119452Sobrien// Output streams -*- C++ -*-
240003Skato
324113Skato// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
424113Skato// 2006, 2007
524113Skato// Free Software Foundation, Inc.
624113Skato//
724113Skato// This file is part of the GNU ISO C++ Library.  This library is free
824113Skato// software; you can redistribute it and/or modify it under the
924113Skato// terms of the GNU General Public License as published by the
1024113Skato// Free Software Foundation; either version 2, or (at your option)
1124113Skato// any later version.
1224113Skato
1324113Skato// This library is distributed in the hope that it will be useful,
1424113Skato// but WITHOUT ANY WARRANTY; without even the implied warranty of
1524113Skato// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1624113Skato// GNU General Public License for more details.
1724113Skato
1824113Skato// You should have received a copy of the GNU General Public License along
1924113Skato// with this library; see the file COPYING.  If not, write to the Free
2024113Skato// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2124113Skato// USA.
2224113Skato
2324113Skato// As a special exception, you may use this file as part of a free software
2424113Skato// library without restriction.  Specifically, if other files instantiate
2524113Skato// templates or use macros or inline functions from this file, or you compile
2624113Skato// this file and link it with other files to produce an executable, this
2724113Skato// file does not by itself cause the resulting executable to be covered by
2824113Skato// the GNU General Public License.  This exception does not however
2924113Skato// invalidate any other reasons why the executable file might be covered by
30115683Sobrien// the GNU General Public License.
31115683Sobrien
32115683Sobrien/** @file ostream
3324113Skato *  This is a Standard C++ Library header.
3424113Skato */
3524113Skato
3624113Skato//
3724113Skato// ISO C++ 14882: 27.6.2  Output streams
3879609Speter//
3924113Skato
4024113Skato#ifndef _GLIBCXX_OSTREAM
4124113Skato#define _GLIBCXX_OSTREAM 1
4224113Skato
4324113Skato#pragma GCC system_header
44168439Sru
45168439Sru#include <ios>
46168439Sru#include <bits/ostream_insert.h>
47147741Sdelphij
48103064Speter_GLIBCXX_BEGIN_NAMESPACE(std)
49103064Speter
50103064Speter  // [27.6.2.1] Template class basic_ostream
5140003Skato  /**
5240003Skato   *  @brief  Controlling output.
5340003Skato   *
5442112Smsmith   *  This is the base class for all output streams.  It provides text
5540003Skato   *  formatting of all builtin types, and communicates with any class
5640003Skato   *  derived from basic_streambuf to do the actual output.
5724113Skato  */
5824113Skato  template<typename _CharT, typename _Traits>
5924113Skato    class basic_ostream : virtual public basic_ios<_CharT, _Traits>
6024113Skato    {
6125159Skato    public:
6224113Skato      // Types (inherited from basic_ios (27.4.4)):
6324113Skato      typedef _CharT                     		char_type;
6424113Skato      typedef typename _Traits::int_type 		int_type;
6524113Skato      typedef typename _Traits::pos_type 		pos_type;
6624113Skato      typedef typename _Traits::off_type 		off_type;
6724113Skato      typedef _Traits                    		traits_type;
6827654Skato
6926298Skato      // Non-standard Types:
7036094Skato      typedef basic_streambuf<_CharT, _Traits> 		__streambuf_type;
7161616Skato      typedef basic_ios<_CharT, _Traits>		__ios_type;
7281879Speter      typedef basic_ostream<_CharT, _Traits>		__ostream_type;
7326298Skato      typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
74109700Sjhb      							__num_put_type;
7579609Speter      typedef ctype<_CharT>           			__ctype_type;
76109700Sjhb
77199067Skuriyama      // [27.6.2.2] constructor/destructor
78199067Skuriyama      /**
79199067Skuriyama       *  @brief  Base constructor.
80199067Skuriyama       *
81199067Skuriyama       *  This ctor is almost never called by the user directly, rather from
82199067Skuriyama       *  derived classes' initialization lists, which pass a pointer to
8379609Speter       *  their own stream buffer.
8482957Speter      */
8582957Speter      explicit
8682957Speter      basic_ostream(__streambuf_type* __sb)
87146263Sobrien      { this->init(__sb); }
88151348Sjkim
89151348Sjkim      /**
90184101Sjkim       *  @brief  Base destructor.
91160309Smr       *
92160309Smr       *  This does very little apart from providing a virtual base dtor.
9382957Speter      */
94109700Sjhb      virtual
95109696Sjhb      ~basic_ostream() { }
96151348Sjkim
97109700Sjhb      // [27.6.2.3] prefix/suffix
98185341Sjkim      class sentry;
99195940Skib      friend class sentry;
100253747Savg
101253747Savg      // [27.6.2.5] formatted output
102253747Savg      // [27.6.2.5.3]  basic_ostream::operator<<
103109700Sjhb      //@{
104160309Smr      /**
105220018Sjkim       *  @brief  Interface for manipulators.
106160309Smr       *
107220018Sjkim       *  Manuipulators such as @c std::endl and @c std::hex use these
108160309Smr       *  functions in constructs like "std::cout << std::endl".  For more
10982261Speter       *  information, see the iomanip header.
110109700Sjhb      */
111159087Sdavidxu      __ostream_type&
11282261Speter      operator<<(__ostream_type& (*__pf)(__ostream_type&))
11382261Speter      {
11424113Skato	// _GLIBCXX_RESOLVE_LIB_DEFECTS
11524113Skato	// DR 60. What is a formatted input function?
11624113Skato	// The inserters for manipulators are *not* formatted output functions.
11724113Skato	return __pf(*this);
11824113Skato      }
11924113Skato
12024113Skato      __ostream_type&
121214346Sjhb      operator<<(__ios_type& (*__pf)(__ios_type&))
12224113Skato      {
12324113Skato	// _GLIBCXX_RESOLVE_LIB_DEFECTS
12424113Skato	// DR 60. What is a formatted input function?
12524113Skato	// The inserters for manipulators are *not* formatted output functions.
12624113Skato	__pf(*this);
127214346Sjhb	return *this;
12824113Skato      }
12924113Skato
13024113Skato      __ostream_type&
13124113Skato      operator<<(ios_base& (*__pf) (ios_base&))
13224113Skato      {
13324113Skato	// _GLIBCXX_RESOLVE_LIB_DEFECTS
13424113Skato	// DR 60. What is a formatted input function?
13524113Skato	// The inserters for manipulators are *not* formatted output functions.
13624113Skato	__pf(*this);
13724113Skato	return *this;
13824113Skato      }
13924113Skato      //@}
14024113Skato
14124113Skato      // [27.6.2.5.2] arithmetic inserters
14224113Skato      /**
14324113Skato       *  @name Arithmetic Inserters
14424113Skato       *
14524113Skato       *  All the @c operator<< functions (aka <em>formatted output
14624113Skato       *  functions</em>) have some common behavior.  Each starts by
14724113Skato       *  constructing a temporary object of type std::basic_ostream::sentry.
148214346Sjhb       *  This can have several effects, concluding with the setting of a
14924113Skato       *  status flag; see the sentry documentation for more.
15024113Skato       *
15124113Skato       *  If the sentry status is good, the function tries to generate
15225159Skato       *  whatever data is appropriate for the type of the argument.
15324113Skato       *
15424113Skato       *  If an exception is thrown during insertion, ios_base::badbit
15524113Skato       *  will be turned on in the stream's error state without causing an
15624113Skato       *  ios_base::failure to be thrown.  The original exception will then
157214346Sjhb       *  be rethrown.
15824113Skato      */
15924113Skato      //@{
160214346Sjhb      /**
16124113Skato       *  @brief  Basic arithmetic inserters
16224113Skato       *  @param  A variable of builtin type.
16324113Skato       *  @return  @c *this if successful
16424113Skato       *
16524113Skato       *  These functions use the stream's current locale (specifically, the
16624113Skato       *  @c num_get facet) to perform numeric formatting.
16724113Skato      */
16824113Skato      __ostream_type&
16924113Skato      operator<<(long __n)
17024113Skato      { return _M_insert(__n); }
17124113Skato
17224113Skato      __ostream_type&
17324113Skato      operator<<(unsigned long __n)
17424113Skato      { return _M_insert(__n); }
17526985Skato
17626985Skato      __ostream_type&
17726985Skato      operator<<(bool __n)
17824113Skato      { return _M_insert(__n); }
17924113Skato
18024113Skato      __ostream_type&
18124113Skato      operator<<(short __n);
18224113Skato
18324113Skato      __ostream_type&
18424113Skato      operator<<(unsigned short __n)
18524113Skato      {
18624113Skato	// _GLIBCXX_RESOLVE_LIB_DEFECTS
18724113Skato	// 117. basic_ostream uses nonexistent num_put member functions.
18824113Skato	return _M_insert(static_cast<unsigned long>(__n));
18924113Skato      }
19024113Skato
19124113Skato      __ostream_type&
192214346Sjhb      operator<<(int __n);
19324113Skato
19424113Skato      __ostream_type&
19524113Skato      operator<<(unsigned int __n)
19624113Skato      {
19725159Skato	// _GLIBCXX_RESOLVE_LIB_DEFECTS
19825159Skato	// 117. basic_ostream uses nonexistent num_put member functions.
19925159Skato	return _M_insert(static_cast<unsigned long>(__n));
20025159Skato      }
20125159Skato
202214346Sjhb#ifdef _GLIBCXX_USE_LONG_LONG
20325159Skato      __ostream_type&
20425159Skato      operator<<(long long __n)
205214346Sjhb      { return _M_insert(__n); }
20625159Skato
20725159Skato      __ostream_type&
20825159Skato      operator<<(unsigned long long __n)
20932199Skato      { return _M_insert(__n); }
21032199Skato#endif
21125159Skato
21265273Skato      __ostream_type&
21365273Skato      operator<<(double __f)
21465273Skato      { return _M_insert(__f); }
21565273Skato
21665273Skato      __ostream_type&
21765273Skato      operator<<(float __f)
21865273Skato      {
21965273Skato	// _GLIBCXX_RESOLVE_LIB_DEFECTS
22065273Skato	// 117. basic_ostream uses nonexistent num_put member functions.
22125159Skato	return _M_insert(static_cast<double>(__f));
222214346Sjhb      }
22325159Skato
22425159Skato      __ostream_type&
22525159Skato      operator<<(long double __f)
22625159Skato      { return _M_insert(__f); }
22724113Skato
22824113Skato      __ostream_type&
22924113Skato      operator<<(const void* __p)
23024113Skato      { return _M_insert(__p); }
23124113Skato
232214346Sjhb      /**
23324113Skato       *  @brief  Extracting from another streambuf.
23424113Skato       *  @param  sb  A pointer to a streambuf
235214346Sjhb       *
23624113Skato       *  This function behaves like one of the basic arithmetic extractors,
23724113Skato       *  in that it also constructs a sentry object and has the same error
23824113Skato       *  handling behavior.
23924113Skato       *
24024113Skato       *  If @a sb is NULL, the stream will set failbit in its error state.
24124113Skato       *
24224113Skato       *  Characters are extracted from @a sb and inserted into @c *this
24324113Skato       *  until one of the following occurs:
24424113Skato       *
24524113Skato       *  - the input stream reaches end-of-file,
24624113Skato       *  - insertion into the output sequence fails (in this case, the
24724113Skato       *    character that would have been inserted is not extracted), or
24824113Skato       *  - an exception occurs while getting a character from @a sb, which
24924113Skato       *    sets failbit in the error state
25024113Skato       *
25124113Skato       *  If the function inserts no characters, failbit is set.
25224113Skato      */
25324113Skato      __ostream_type&
25424113Skato      operator<<(__streambuf_type* __sb);
25524113Skato      //@}
25624113Skato
25724113Skato      // [27.6.2.6] unformatted output functions
25824113Skato      /**
25924113Skato       *  @name Unformatted Output Functions
26024113Skato       *
26124113Skato       *  All the unformatted output functions have some common behavior.
26224113Skato       *  Each starts by constructing a temporary object of type
26324113Skato       *  std::basic_ostream::sentry.  This has several effects, concluding
26424113Skato       *  with the setting of a status flag; see the sentry documentation
26524113Skato       *  for more.
26624113Skato       *
26724113Skato       *  If the sentry status is good, the function tries to generate
26824113Skato       *  whatever data is appropriate for the type of the argument.
26924113Skato       *
27024113Skato       *  If an exception is thrown during insertion, ios_base::badbit
27124113Skato       *  will be turned on in the stream's error state.  If badbit is on in
27224113Skato       *  the stream's exceptions mask, the exception will be rethrown
27324113Skato       *  without completing its actions.
27424113Skato      */
27524113Skato      //@{
27624113Skato      /**
27724113Skato       *  @brief  Simple insertion.
27824113Skato       *  @param  c  The character to insert.
27924113Skato       *  @return  *this
28024113Skato       *
28124113Skato       *  Tries to insert @a c.
28224113Skato       *
28324113Skato       *  @note  This function is not overloaded on signed char and
28424113Skato       *         unsigned char.
28524113Skato      */
28624113Skato      __ostream_type&
28724113Skato      put(char_type __c);
28824113Skato
28924113Skato      // Core write functionality, without sentry.
29024113Skato      void
29124113Skato      _M_write(const char_type* __s, streamsize __n)
29224113Skato      {
29324113Skato	const streamsize __put = this->rdbuf()->sputn(__s, __n);
29424113Skato	if (__put != __n)
29524113Skato	  this->setstate(ios_base::badbit);
29624113Skato      }
29724113Skato
29824113Skato      /**
29924113Skato       *  @brief  Character string insertion.
30024113Skato       *  @param  s  The array to insert.
30124113Skato       *  @param  n  Maximum number of characters to insert.
30224113Skato       *  @return  *this
30324113Skato       *
30424113Skato       *  Characters are copied from @a s and inserted into the stream until
30524113Skato       *  one of the following happens:
30624113Skato       *
30724113Skato       *  - @a n characters are inserted
30824113Skato       *  - inserting into the output sequence fails (in this case, badbit
30924113Skato       *    will be set in the stream's error state)
31024113Skato       *
31124113Skato       *  @note  This function is not overloaded on signed char and
31224113Skato       *         unsigned char.
31324113Skato      */
31424113Skato      __ostream_type&
31524113Skato      write(const char_type* __s, streamsize __n);
31624113Skato      //@}
31724113Skato
31824113Skato      /**
31924113Skato       *  @brief  Synchronizing the stream buffer.
32024113Skato       *  @return  *this
321214346Sjhb       *
32224113Skato       *  If @c rdbuf() is a null pointer, changes nothing.
32324113Skato       *
32424113Skato       *  Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
32524113Skato       *  sets badbit.
32624113Skato      */
327214346Sjhb      __ostream_type&
32824113Skato      flush();
329105216Sphk
33024113Skato      // [27.6.2.4] seek members
33124113Skato      /**
332214346Sjhb       *  @brief  Getting the current write position.
33324113Skato       *  @return  A file position object.
33424113Skato       *
33524113Skato       *  If @c fail() is not false, returns @c pos_type(-1) to indicate
33624113Skato       *  failure.  Otherwise returns @c rdbuf()->pubseekoff(0,cur,out).
33724113Skato      */
338214346Sjhb      pos_type
33924113Skato      tellp();
34024113Skato
34124113Skato      /**
342214346Sjhb       *  @brief  Changing the current write position.
34324113Skato       *  @param  pos  A file position object.
34424113Skato       *  @return  *this
34524113Skato       *
34624113Skato       *  If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos).  If
34724113Skato       *  that function fails, sets failbit.
34824113Skato      */
34924113Skato      __ostream_type&
35024113Skato      seekp(pos_type);
35124113Skato
35224113Skato      /**
35324113Skato       *  @brief  Changing the current write position.
354214346Sjhb       *  @param  off  A file offset object.
35524113Skato       *  @param  dir  The direction in which to seek.
35624113Skato       *  @return  *this
357214346Sjhb       *
35824113Skato       *  If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir).
35924113Skato       *  If that function fails, sets failbit.
36024113Skato      */
36124113Skato       __ostream_type&
36224113Skato      seekp(off_type, ios_base::seekdir);
36324113Skato
36424113Skato    protected:
36530162Skato      explicit
36630162Skato      basic_ostream() { }
36731338Sjlemon
36830162Skato      template<typename _ValueT>
36931338Sjlemon        __ostream_type&
37030162Skato        _M_insert(_ValueT __v);
37130162Skato    };
37224113Skato
37324113Skato  /**
37424113Skato   *  @brief  Performs setup work for output streams.
37524113Skato   *
37624113Skato   *  Objects of this class are created before all of the standard
37724113Skato   *  inserters are run.  It is responsible for "exception-safe prefix and
37824113Skato   *  suffix operations."  Additional actions may be added by the
37924113Skato   *  implementation, and we list them in
38024113Skato   *  http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/howto.html#5
38124113Skato   *  under [27.6] notes.
38224113Skato  */
38324113Skato  template <typename _CharT, typename _Traits>
38424113Skato    class basic_ostream<_CharT, _Traits>::sentry
38524113Skato    {
38624113Skato      // Data Members:
38724113Skato      bool 				_M_ok;
38824113Skato      basic_ostream<_CharT, _Traits>& 	_M_os;
38924113Skato
39024113Skato    public:
39124113Skato      /**
39230162Skato       *  @brief  The constructor performs preparatory work.
39330162Skato       *  @param  os  The output stream to guard.
39430162Skato       *
39530162Skato       *  If the stream state is good (@a os.good() is true), then if the
39630162Skato       *  stream is tied to another output stream, @c is.tie()->flush()
39724113Skato       *  is called to synchronize the output sequences.
39824113Skato       *
39924113Skato       *  If the stream state is still good, then the sentry state becomes
40024113Skato       *  true ("okay").
40124113Skato      */
40224113Skato      explicit
40324113Skato      sentry(basic_ostream<_CharT, _Traits>& __os);
40424113Skato
40524113Skato      /**
40624113Skato       *  @brief  Possibly flushes the stream.
40724113Skato       *
40824113Skato       *  If @c ios_base::unitbuf is set in @c os.flags(), and
40924113Skato       *  @c std::uncaught_exception() is true, the sentry destructor calls
41024113Skato       *  @c flush() on the output stream.
41124113Skato      */
41224113Skato      ~sentry()
41324113Skato      {
41424113Skato	// XXX MT
41524113Skato	if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
41624113Skato	  {
41724113Skato	    // Can't call flush directly or else will get into recursive lock.
41824113Skato	    if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
41924113Skato	      _M_os.setstate(ios_base::badbit);
42024113Skato	  }
421214346Sjhb      }
42224113Skato
42324113Skato      /**
42424113Skato       *  @brief  Quick status checking.
425220018Sjkim       *  @return  The sentry state.
426220018Sjkim       *
427254384Sjkim       *  For ease of use, sentries may be converted to booleans.  The
428254384Sjkim       *  return value is that of the sentry state (true == okay).
429254384Sjkim      */
430254384Sjkim      operator bool() const
431254384Sjkim      { return _M_ok; }
432254384Sjkim    };
433254384Sjkim
434254384Sjkim  // [27.6.2.5.4] character insertion templates
435254384Sjkim  //@{
436254384Sjkim  /**
437254384Sjkim   *  @brief  Character inserters
438254384Sjkim   *  @param  out  An output stream.
439254384Sjkim   *  @param  c  A character.
440220018Sjkim   *  @return  out
441220018Sjkim   *
442220018Sjkim   *  Behaves like one of the formatted arithmetic inserters described in
443220018Sjkim   *  std::basic_ostream.  After constructing a sentry object with good
444220018Sjkim   *  status, this function inserts a single character and any required
445220018Sjkim   *  padding (as determined by [22.2.2.2.2]).  @c out.width(0) is then
446220018Sjkim   *  called.
447220018Sjkim   *
448220018Sjkim   *  If @a c is of type @c char and the character type of the stream is not
449220018Sjkim   *  @c char, the character is widened before insertion.
450220018Sjkim  */
451220018Sjkim  template<typename _CharT, typename _Traits>
452220018Sjkim    inline basic_ostream<_CharT, _Traits>&
453220018Sjkim    operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
454220018Sjkim    { return __ostream_insert(__out, &__c, 1); }
455220018Sjkim
456220018Sjkim  template<typename _CharT, typename _Traits>
457220018Sjkim    inline basic_ostream<_CharT, _Traits>&
458220018Sjkim    operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
459220018Sjkim    { return (__out << __out.widen(__c)); }
460220018Sjkim
461220018Sjkim  // Specialization
462220018Sjkim  template <class _Traits>
463220018Sjkim    inline basic_ostream<char, _Traits>&
464220018Sjkim    operator<<(basic_ostream<char, _Traits>& __out, char __c)
465220018Sjkim    { return __ostream_insert(__out, &__c, 1); }
466220018Sjkim
467220018Sjkim  // Signed and unsigned
468220018Sjkim  template<class _Traits>
469220018Sjkim    inline basic_ostream<char, _Traits>&
47027654Skato    operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
47126298Skato    { return (__out << static_cast<char>(__c)); }
47226298Skato
47326298Skato  template<class _Traits>
47426298Skato    inline basic_ostream<char, _Traits>&
47526298Skato    operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
47626298Skato    { return (__out << static_cast<char>(__c)); }
47726298Skato  //@}
47826298Skato
479214346Sjhb  //@{
48026298Skato  /**
48126298Skato   *  @brief  String inserters
482214346Sjhb   *  @param  out  An output stream.
48326298Skato   *  @param  s  A character string.
48426298Skato   *  @return  out
48526298Skato   *  @pre  @a s must be a non-NULL pointer
48626298Skato   *
48726298Skato   *  Behaves like one of the formatted arithmetic inserters described in
48826298Skato   *  std::basic_ostream.  After constructing a sentry object with good
48926298Skato   *  status, this function inserts @c traits::length(s) characters starting
49030162Skato   *  at @a s, widened if necessary, followed by any required padding (as
49130162Skato   *  determined by [22.2.2.2.2]).  @c out.width(0) is then called.
49231338Sjlemon  */
49330162Skato  template<typename _CharT, typename _Traits>
49431338Sjlemon    inline basic_ostream<_CharT, _Traits>&
49530162Skato    operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
49630162Skato    {
49726298Skato      if (!__s)
49826298Skato	__out.setstate(ios_base::badbit);
49926298Skato      else
50026298Skato	__ostream_insert(__out, __s,
50126298Skato			 static_cast<streamsize>(_Traits::length(__s)));
50226298Skato      return __out;
50326298Skato    }
50426298Skato
50526298Skato  template<typename _CharT, typename _Traits>
50626298Skato    basic_ostream<_CharT, _Traits> &
50726298Skato    operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
50826298Skato
50926298Skato  // Partial specializationss
51026298Skato  template<class _Traits>
51126298Skato    inline basic_ostream<char, _Traits>&
51226298Skato    operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
51326298Skato    {
51426298Skato      if (!__s)
51526298Skato	__out.setstate(ios_base::badbit);
51630162Skato      else
51730162Skato	__ostream_insert(__out, __s,
51830162Skato			 static_cast<streamsize>(_Traits::length(__s)));
51930162Skato      return __out;
52030162Skato    }
52126298Skato
52226298Skato  // Signed and unsigned
52326298Skato  template<class _Traits>
52426298Skato    inline basic_ostream<char, _Traits>&
52526298Skato    operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
52626298Skato    { return (__out << reinterpret_cast<const char*>(__s)); }
52726298Skato
52826298Skato  template<class _Traits>
52926298Skato    inline basic_ostream<char, _Traits> &
53026298Skato    operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
53126298Skato    { return (__out << reinterpret_cast<const char*>(__s)); }
532214346Sjhb  //@}
53326298Skato
53436094Skato  // [27.6.2.7] standard basic_ostream manipulators
53536094Skato  /**
53636094Skato   *  @brief  Write a newline and flush the stream.
53736094Skato   *
53840003Skato   *  This manipulator is often mistakenly used when a simple newline is
53936094Skato   *  desired, leading to poor buffering performance.  See
54036094Skato   *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for more
541122425Sjhb   *  on this subject.
54236094Skato  */
543118955Sjhb  template<typename _CharT, typename _Traits>
544118955Sjhb    inline basic_ostream<_CharT, _Traits>&
545118955Sjhb    endl(basic_ostream<_CharT, _Traits>& __os)
54636094Skato    { return flush(__os.put(__os.widen('\n'))); }
54761616Skato
54861616Skato  /**
54961616Skato   *  @brief  Write a null character into the output sequence.
55061616Skato   *
55161616Skato   *  "Null character" is @c CharT() by definition.  For CharT of @c char,
552104094Sphk   *  this correctly writes the ASCII @c NUL character string terminator.
55361616Skato  */
55461616Skato  template<typename _CharT, typename _Traits>
55561616Skato    inline basic_ostream<_CharT, _Traits>&
556214346Sjhb    ends(basic_ostream<_CharT, _Traits>& __os)
55761616Skato    { return __os.put(_CharT()); }
55861616Skato
559214346Sjhb  /**
56061616Skato   *  @brief  Flushes the output stream.
56161616Skato   *
56261616Skato   *  This manipulator simply calls the stream's @c flush() member function.
56361616Skato  */
564118955Sjhb  template<typename _CharT, typename _Traits>
56561616Skato    inline basic_ostream<_CharT, _Traits>&
56661616Skato    flush(basic_ostream<_CharT, _Traits>& __os)
56761616Skato    { return __os.flush(); }
56861616Skato
56961616Skato_GLIBCXX_END_NAMESPACE
57061616Skato
57161616Skato#ifndef _GLIBCXX_EXPORT_TEMPLATE
57261616Skato# include <bits/ostream.tcc>
57361616Skato#endif
57461616Skato
57561616Skato#endif	/* _GLIBCXX_OSTREAM */
57661616Skato