# ostream.tcc

    00001 // ostream classes -*- C++ -*-
    00002
    00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    00004 // Free Software Foundation, Inc.
    00005 //
    00006 // This file is part of the GNU ISO C++ Library.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU General Public License as published by the
    00009 // Free Software Foundation; either version 2, or (at your option)
    00010 // any later version.
    00011
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016
    00017 // You should have received a copy of the GNU General Public License along
    00018 // with this library; see the file COPYING.  If not, write to the Free
    00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00020 // USA.
    00021
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 //
    00032 // ISO C++ 14882: 27.6.2  Output streams
    00033 //
    00034
    00035 #ifndef _OSTREAM_TCC
    00036 #define _OSTREAM_TCC 1
    00037
    00038 #pragma GCC system_header
    00039
    00040 #include <locale>
    00041
    00042 namespace std
    00043 {
    00044   template<typename _CharT, typename _Traits>
    00045     basic_ostream<_CharT, _Traits>::sentry::
    00046     sentry(basic_ostream<_CharT, _Traits>& __os)
    00047     : _M_ok(false), _M_os(__os)
    00048     {
    00049       // XXX MT
    00050       if (__os.tie() && __os.good())
    00051     __os.tie()->flush();
    00052
    00053       if (__os.good())
    00054     _M_ok = true;
    00055       else
    00056     __os.setstate(ios_base::failbit);
    00057     }
    00058
    00059   template<typename _CharT, typename _Traits>
    00060     basic_ostream<_CharT, _Traits>&
    00061     basic_ostream<_CharT, _Traits>::
    00062     operator<<(__ostream_type& (*__pf)(__ostream_type&))
    00063     {
    00064       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00065       // DR 60. What is a formatted input function?
    00066       // The inserters for manipulators are *not* formatted output functions.
    00067       return __pf(*this);
    00068     }
    00069
    00070   template<typename _CharT, typename _Traits>
    00071     basic_ostream<_CharT, _Traits>&
    00072     basic_ostream<_CharT, _Traits>::
    00073     operator<<(__ios_type& (*__pf)(__ios_type&))
    00074     {
    00075       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00076       // DR 60. What is a formatted input function?
    00077       // The inserters for manipulators are *not* formatted output functions.
    00078       __pf(*this);
    00079       return *this;
    00080     }
    00081
    00082   template<typename _CharT, typename _Traits>
    00083     basic_ostream<_CharT, _Traits>&
    00084     basic_ostream<_CharT, _Traits>::
    00085     operator<<(ios_base& (*__pf)(ios_base&))
    00086     {
    00087       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00088       // DR 60. What is a formatted input function?
    00089       // The inserters for manipulators are *not* formatted output functions.
    00090       __pf(*this);
    00091       return *this;
    00092     }
    00093
    00094   template<typename _CharT, typename _Traits>
    00095     basic_ostream<_CharT, _Traits>&
    00096     basic_ostream<_CharT, _Traits>::
    00097     operator<<(bool __n)
    00098     {
    00099       sentry __cerb(*this);
    00100       if (__cerb)
    00101     {
    00102       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00103       try
    00104         {
    00105           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00106           if (__np.put(*this, *this, this->fill(), __n).failed())
    00107         __err |= ios_base::badbit;
    00108         }
    00109       catch(...)
    00110         { this->_M_setstate(ios_base::badbit); }
    00111       if (__err)
    00112         this->setstate(__err);
    00113     }
    00114       return *this;
    00115     }
    00116
    00117   template<typename _CharT, typename _Traits>
    00118     basic_ostream<_CharT, _Traits>&
    00119     basic_ostream<_CharT, _Traits>::
    00120     operator<<(long __n)
    00121     {
    00122       sentry __cerb(*this);
    00123       if (__cerb)
    00124     {
    00125       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00126       try
    00127         {
    00128           bool __b = false;
    00129           const char_type __c = this->fill();
    00130           const ios_base::fmtflags __fmt = (this->flags()
    00131                         & ios_base::basefield);
    00132           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00133           if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
    00134         {
    00135           const unsigned long __l = static_cast<unsigned long>(__n);
    00136           __b = __np.put(*this, *this, __c, __l).failed();
    00137         }
    00138           else
    00139         __b = __np.put(*this, *this, __c, __n).failed();
    00140           if (__b)
    00141         __err |= ios_base::badbit;
    00142         }
    00143       catch(...)
    00144         { this->_M_setstate(ios_base::badbit); }
    00145       if (__err)
    00146         this->setstate(__err);
    00147     }
    00148       return *this;
    00149     }
    00150
    00151   template<typename _CharT, typename _Traits>
    00152     basic_ostream<_CharT, _Traits>&
    00153     basic_ostream<_CharT, _Traits>::
    00154     operator<<(unsigned long __n)
    00155     {
    00156       sentry __cerb(*this);
    00157       if (__cerb)
    00158     {
    00159       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00160       try
    00161         {
    00162           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00163           if (__np.put(*this, *this, this->fill(), __n).failed())
    00164         __err |= ios_base::badbit;
    00165         }
    00166       catch(...)
    00167         { this->_M_setstate(ios_base::badbit); }
    00168       if (__err)
    00169         this->setstate(__err);
    00170     }
    00171       return *this;
    00172     }
    00173
    00174 #ifdef _GLIBCXX_USE_LONG_LONG
    00175   template<typename _CharT, typename _Traits>
    00176     basic_ostream<_CharT, _Traits>&
    00177     basic_ostream<_CharT, _Traits>::
    00178     operator<<(long long __n)
    00179     {
    00180       sentry __cerb(*this);
    00181       if (__cerb)
    00182     {
    00183       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00184       try
    00185         {
    00186           bool __b = false;
    00187           const char_type __c = this->fill();
    00188           const ios_base::fmtflags __fmt = (this->flags()
    00189                         & ios_base::basefield);
    00190           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00191           if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex))
    00192         {
    00193           const unsigned long long __l = (static_cast<
    00194                           unsigned long long>(__n));
    00195           __b = __np.put(*this, *this, __c, __l).failed();
    00196         }
    00197           else
    00198         __b = __np.put(*this, *this, __c, __n).failed();
    00199           if (__b)
    00200         __err |= ios_base::badbit;
    00201         }
    00202       catch(...)
    00203         { this->_M_setstate(ios_base::badbit); }
    00204       if (__err)
    00205         this->setstate(__err);
    00206     }
    00207       return *this;
    00208     }
    00209
    00210   template<typename _CharT, typename _Traits>
    00211     basic_ostream<_CharT, _Traits>&
    00212     basic_ostream<_CharT, _Traits>::
    00213     operator<<(unsigned long long __n)
    00214     {
    00215       sentry __cerb(*this);
    00216       if (__cerb)
    00217     {
    00218       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00219       try
    00220         {
    00221           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00222           if (__np.put(*this, *this, this->fill(), __n).failed())
    00223         __err |= ios_base::badbit;
    00224         }
    00225       catch(...)
    00226         { this->_M_setstate(ios_base::badbit); }
    00227       if (__err)
    00228         this->setstate(__err);
    00229     }
    00230       return *this;
    00231     }
    00232 #endif
    00233
    00234   template<typename _CharT, typename _Traits>
    00235     basic_ostream<_CharT, _Traits>&
    00236     basic_ostream<_CharT, _Traits>::
    00237     operator<<(double __n)
    00238     {
    00239       sentry __cerb(*this);
    00240       if (__cerb)
    00241     {
    00242       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00243       try
    00244         {
    00245           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00246           if (__np.put(*this, *this, this->fill(), __n).failed())
    00247         __err |= ios_base::badbit;
    00248         }
    00249       catch(...)
    00250         { this->_M_setstate(ios_base::badbit); }
    00251       if (__err)
    00252         this->setstate(__err);
    00253     }
    00254       return *this;
    00255     }
    00256
    00257   template<typename _CharT, typename _Traits>
    00258     basic_ostream<_CharT, _Traits>&
    00259     basic_ostream<_CharT, _Traits>::
    00260     operator<<(long double __n)
    00261     {
    00262       sentry __cerb(*this);
    00263       if (__cerb)
    00264     {
    00265       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00266       try
    00267         {
    00268           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00269           if (__np.put(*this, *this, this->fill(), __n).failed())
    00270         __err |= ios_base::badbit;
    00271         }
    00272       catch(...)
    00273         { this->_M_setstate(ios_base::badbit); }
    00274       if (__err)
    00275         this->setstate(__err);
    00276     }
    00277       return *this;
    00278     }
    00279
    00280   template<typename _CharT, typename _Traits>
    00281     basic_ostream<_CharT, _Traits>&
    00282     basic_ostream<_CharT, _Traits>::
    00283     operator<<(const void* __n)
    00284     {
    00285       sentry __cerb(*this);
    00286       if (__cerb)
    00287     {
    00288       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00289       try
    00290         {
    00291           const __num_put_type& __np = __check_facet(this->_M_num_put);
    00292           if (__np.put(*this, *this, this->fill(), __n).failed())
    00293         __err |= ios_base::badbit;
    00294         }
    00295       catch(...)
    00296         { this->_M_setstate(ios_base::badbit); }
    00297       if (__err)
    00298         this->setstate(__err);
    00299     }
    00300       return *this;
    00301     }
    00302
    00303   template<typename _CharT, typename _Traits>
    00304     basic_ostream<_CharT, _Traits>&
    00305     basic_ostream<_CharT, _Traits>::
    00306     operator<<(__streambuf_type* __sbin)
    00307     {
    00308       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00309       sentry __cerb(*this);
    00310       if (__cerb && __sbin)
    00311     {
    00312       try
    00313         {
    00314           if (!__copy_streambufs(__sbin, this->rdbuf()))
    00315         __err |= ios_base::failbit;
    00316         }
    00317       catch(...)
    00318         { this->_M_setstate(ios_base::failbit); }
    00319     }
    00320       else if (!__sbin)
    00321     __err |= ios_base::badbit;
    00322       if (__err)
    00323     this->setstate(__err);
    00324       return *this;
    00325     }
    00326
    00327   template<typename _CharT, typename _Traits>
    00328     basic_ostream<_CharT, _Traits>&
    00329     basic_ostream<_CharT, _Traits>::
    00330     put(char_type __c)
    00331     {
    00332       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00333       // DR 60. What is a formatted input function?
    00334       // basic_ostream::put(char_type) is an unformatted output function.
    00335       // DR 63. Exception-handling policy for unformatted output.
    00336       // Unformatted output functions should catch exceptions thrown
    00337       // from streambuf members.
    00338       sentry __cerb(*this);
    00339       if (__cerb)
    00340     {
    00341       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00342       try
    00343         {
    00344           const int_type __put = this->rdbuf()->sputc(__c);
    00345           if (traits_type::eq_int_type(__put, traits_type::eof()))
    00346         __err |= ios_base::badbit;
    00347         }
    00348       catch (...)
    00349         { this->_M_setstate(ios_base::badbit); }
    00350       if (__err)
    00351         this->setstate(__err);
    00352     }
    00353       return *this;
    00354     }
    00355
    00356   template<typename _CharT, typename _Traits>
    00357     basic_ostream<_CharT, _Traits>&
    00358     basic_ostream<_CharT, _Traits>::
    00359     write(const _CharT* __s, streamsize __n)
    00360     {
    00361       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00362       // DR 60. What is a formatted input function?
    00363       // basic_ostream::write(const char_type*, streamsize) is an
    00364       // unformatted output function.
    00365       // DR 63. Exception-handling policy for unformatted output.
    00366       // Unformatted output functions should catch exceptions thrown
    00367       // from streambuf members.
    00368       sentry __cerb(*this);
    00369       if (__cerb)
    00370     {
    00371       try
    00372         { _M_write(__s, __n); }
    00373       catch (...)
    00374         { this->_M_setstate(ios_base::badbit); }
    00375     }
    00376       return *this;
    00377     }
    00378
    00379   template<typename _CharT, typename _Traits>
    00380     basic_ostream<_CharT, _Traits>&
    00381     basic_ostream<_CharT, _Traits>::
    00382     flush()
    00383     {
    00384       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00385       // DR 60. What is a formatted input function?
    00386       // basic_ostream::flush() is *not* an unformatted output function.
    00387       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00388       try
    00389     {
    00390       if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
    00391         __err |= ios_base::badbit;
    00392     }
    00393       catch(...)
    00394     { this->_M_setstate(ios_base::badbit); }
    00395       if (__err)
    00396     this->setstate(__err);
    00397       return *this;
    00398     }
    00399
    00400   template<typename _CharT, typename _Traits>
    00401     typename basic_ostream<_CharT, _Traits>::pos_type
    00402     basic_ostream<_CharT, _Traits>::
    00403     tellp()
    00404     {
    00405       pos_type __ret = pos_type(-1);
    00406       try
    00407     {
    00408       if (!this->fail())
    00409         __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
    00410     }
    00411       catch(...)
    00412     { this->_M_setstate(ios_base::badbit); }
    00413       return __ret;
    00414     }
    00415
    00416   template<typename _CharT, typename _Traits>
    00417     basic_ostream<_CharT, _Traits>&
    00418     basic_ostream<_CharT, _Traits>::
    00419     seekp(pos_type __pos)
    00420     {
    00421       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00422       try
    00423     {
    00424       if (!this->fail())
    00425         {
    00426           // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00427           // 136.  seekp, seekg setting wrong streams?
    00428           const pos_type __p = this->rdbuf()->pubseekpos(__pos,
    00429                                  ios_base::out);
    00430
    00431           // 129. Need error indication from seekp() and seekg()
    00432           if (__p == pos_type(off_type(-1)))
    00433         __err |= ios_base::failbit;
    00434         }
    00435     }
    00436       catch(...)
    00437     { this->_M_setstate(ios_base::badbit); }
    00438       if (__err)
    00439     this->setstate(__err);
    00440       return *this;
    00441     }
    00442
    00443   template<typename _CharT, typename _Traits>
    00444     basic_ostream<_CharT, _Traits>&
    00445     basic_ostream<_CharT, _Traits>::
    00446     seekp(off_type __off, ios_base::seekdir __dir)
    00447     {
    00448       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00449       try
    00450     {
    00451       if (!this->fail())
    00452         {
    00453           // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00454           // 136.  seekp, seekg setting wrong streams?
    00455           const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
    00456                                  ios_base::out);
    00457
    00458           // 129. Need error indication from seekp() and seekg()
    00459           if (__p == pos_type(off_type(-1)))
    00460         __err |= ios_base::failbit;
    00461         }
    00462     }
    00463       catch(...)
    00464     { this->_M_setstate(ios_base::badbit); }
    00465       if (__err)
    00466     this->setstate(__err);
    00467       return *this;
    00468     }
    00469
    00470   // 27.6.2.5.4 Character inserters.
    00471   template<typename _CharT, typename _Traits>
    00472     basic_ostream<_CharT, _Traits>&
    00473     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
    00474     {
    00475       typedef basic_ostream<_CharT, _Traits> __ostream_type;
    00476       typename __ostream_type::sentry __cerb(__out);
    00477       if (__cerb)
    00478     {
    00479       try
    00480         {
    00481           const streamsize __w = __out.width();
    00482           streamsize __len = 1;
    00483           _CharT* __cs = &__c;
    00484           if (__w > __len)
    00485         {
    00486           __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
    00487                                    * __w));
    00488           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
    00489                          &__c, __w, __len, false);
    00490           __len = __w;
    00491         }
    00492           __out._M_write(__cs, __len);
    00493           __out.width(0);
    00494         }
    00495       catch(...)
    00496         { __out._M_setstate(ios_base::badbit); }
    00497     }
    00498       return __out;
    00499     }
    00500
    00501   // Specializations.
    00502   template <class _Traits>
    00503     basic_ostream<char, _Traits>&
    00504     operator<<(basic_ostream<char, _Traits>& __out, char __c)
    00505     {
    00506       typedef basic_ostream<char, _Traits> __ostream_type;
    00507       typename __ostream_type::sentry __cerb(__out);
    00508       if (__cerb)
    00509     {
    00510       try
    00511         {
    00512           const streamsize __w = __out.width();
    00513           streamsize __len = 1;
    00514           char* __cs = &__c;
    00515           if (__w > __len)
    00516         {
    00517           __cs = static_cast<char*>(__builtin_alloca(__w));
    00518           __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs,
    00519                            &__c, __w, __len, false);
    00520           __len = __w;
    00521         }
    00522           __out._M_write(__cs, __len);
    00523           __out.width(0);
    00524         }
    00525       catch(...)
    00526         { __out._M_setstate(ios_base::badbit); }
    00527     }
    00528       return __out;
    00529      }
    00530
    00531   template<typename _CharT, typename _Traits>
    00532     basic_ostream<_CharT, _Traits>&
    00533     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
    00534     {
    00535       typedef basic_ostream<_CharT, _Traits> __ostream_type;
    00536       typename __ostream_type::sentry __cerb(__out);
    00537       if (__cerb && __s)
    00538     {
    00539       try
    00540         {
    00541           const streamsize __w = __out.width();
    00542           streamsize __len = static_cast<streamsize>(_Traits::length(__s));
    00543           if (__w > __len)
    00544         {
    00545           _CharT* __cs = (static_cast<
    00546                   _CharT*>(__builtin_alloca(sizeof(_CharT)
    00547                                 * __w)));
    00548           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
    00549                          __s, __w, __len, false);
    00550           __s = __cs;
    00551           __len = __w;
    00552         }
    00553           __out._M_write(__s, __len);
    00554           __out.width(0);
    00555         }
    00556       catch(...)
    00557         { __out._M_setstate(ios_base::badbit); }
    00558     }
    00559       else if (!__s)
    00560     __out.setstate(ios_base::badbit);
    00561       return __out;
    00562     }
    00563
    00564   template<typename _CharT, typename _Traits>
    00565     basic_ostream<_CharT, _Traits>&
    00566     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
    00567     {
    00568       typedef basic_ostream<_CharT, _Traits> __ostream_type;
    00569       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00570       // 167.  Improper use of traits_type::length()
    00571       // Note that this is only in 'Review' status.
    00572       typedef char_traits<char>          __traits_type;
    00573       typename __ostream_type::sentry __cerb(__out);
    00574       if (__cerb && __s)
    00575     {
    00576       size_t __clen = __traits_type::length(__s);
    00577       _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
    00578                                    * __clen));
    00579       for (size_t  __i = 0; __i < __clen; ++__i)
    00580         __ws[__i] = __out.widen(__s[__i]);
    00581       _CharT* __str = __ws;
    00582
    00583       try
    00584         {
    00585           const streamsize __w = __out.width();
    00586           streamsize __len = static_cast<streamsize>(__clen);
    00587           if (__w > __len)
    00588         {
    00589           _CharT* __cs = (static_cast<
    00590                   _CharT*>(__builtin_alloca(sizeof(_CharT)
    00591                                 * __w)));
    00592           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
    00593                          __ws, __w, __len, false);
    00594           __str = __cs;
    00595           __len = __w;
    00596         }
    00597           __out._M_write(__str, __len);
    00598           __out.width(0);
    00599         }
    00600       catch(...)
    00601         { __out._M_setstate(ios_base::badbit); }
    00602     }
    00603       else if (!__s)
    00604     __out.setstate(ios_base::badbit);
    00605       return __out;
    00606     }
    00607
    00608   // Partial specializations.
    00609   template<class _Traits>
    00610     basic_ostream<char, _Traits>&
    00611     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
    00612     {
    00613       typedef basic_ostream<char, _Traits> __ostream_type;
    00614       typename __ostream_type::sentry __cerb(__out);
    00615       if (__cerb && __s)
    00616     {
    00617       try
    00618         {
    00619           const streamsize __w = __out.width();
    00620           streamsize __len = static_cast<streamsize>(_Traits::length(__s));
    00621           if (__w > __len)
    00622         {
    00623           char* __cs = static_cast<char*>(__builtin_alloca(__w));
    00624           __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs,
    00625                          __s, __w, __len, false);
    00626           __s = __cs;
    00627           __len = __w;
    00628         }
    00629           __out._M_write(__s, __len);
    00630           __out.width(0);
    00631         }
    00632       catch(...)
    00633         { __out._M_setstate(ios_base::badbit); }
    00634     }
    00635       else if (!__s)
    00636     __out.setstate(ios_base::badbit);
    00637       return __out;
    00638     }
    00639
    00640   // 21.3.7.9 basic_string::operator<<
    00641   template<typename _CharT, typename _Traits, typename _Alloc>
    00642     basic_ostream<_CharT, _Traits>&
    00643     operator<<(basic_ostream<_CharT, _Traits>& __out,
    00644            const basic_string<_CharT, _Traits, _Alloc>& __str)
    00645     {
    00646       typedef basic_ostream<_CharT, _Traits> __ostream_type;
    00647       typename __ostream_type::sentry __cerb(__out);
    00648       if (__cerb)
    00649     {
    00650       const streamsize __w = __out.width();
    00651       streamsize __len = static_cast<streamsize>(__str.size());
    00652       const _CharT* __s = __str.data();
    00653
    00654       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00655       // 25. String operator<< uses width() value wrong
    00656       if (__w > __len)
    00657         {
    00658           _CharT* __cs = (static_cast<
    00659                   _CharT*>(__builtin_alloca(sizeof(_CharT) * __w)));
    00660           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s,
    00661                          __w, __len, false);
    00662           __s = __cs;
    00663           __len = __w;
    00664         }
    00665       __out._M_write(__s, __len);
    00666       __out.width(0);
    00667     }
    00668       return __out;
    00669     }
    00670
    00671   // Inhibit implicit instantiations for required instantiations,
    00672   // which are defined via explicit instantiations elsewhere.
    00673   // NB:  This syntax is a GNU extension.
    00674 #if _GLIBCXX_EXTERN_TEMPLATE
    00675   extern template class basic_ostream<char>;
    00676   extern template ostream& endl(ostream&);
    00677   extern template ostream& ends(ostream&);
    00678   extern template ostream& flush(ostream&);
    00679   extern template ostream& operator<<(ostream&, char);
    00680   extern template ostream& operator<<(ostream&, unsigned char);
    00681   extern template ostream& operator<<(ostream&, signed char);
    00682   extern template ostream& operator<<(ostream&, const char*);
    00683   extern template ostream& operator<<(ostream&, const unsigned char*);
    00684   extern template ostream& operator<<(ostream&, const signed char*);
    00685
    00686 #ifdef _GLIBCXX_USE_WCHAR_T
    00687   extern template class basic_ostream<wchar_t>;
    00688   extern template wostream& endl(wostream&);
    00689   extern template wostream& ends(wostream&);
    00690   extern template wostream& flush(wostream&);
    00691   extern template wostream& operator<<(wostream&, wchar_t);
    00692   extern template wostream& operator<<(wostream&, char);
    00693   extern template wostream& operator<<(wostream&, const wchar_t*);
    00694   extern template wostream& operator<<(wostream&, const char*);
    00695 #endif
    00696 #endif
    00697 } // namespace std
    00698
    00699 #endif