OSDN Git Service

2001-05-30 Benjamin Kosnik <bkoz@redat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / ostream.tcc
1 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
8
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
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING.  If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction.  Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License.  This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27
28 //
29 // ISO C++ 14882: 27.6.2  Output streams
30 //
31
32 #include <bits/std_locale.h>
33
34 namespace std 
35 {
36   template<typename _CharT, typename _Traits>
37     basic_ostream<_CharT, _Traits>::sentry::
38     sentry(basic_ostream<_CharT,_Traits>& __os)
39     : _M_ok(__os.good()), _M_os(__os)
40     {
41       // XXX MT 
42       if (_M_ok && __os.tie())
43         __os.tie()->flush();  
44     }
45   
46   template<typename _CharT, typename _Traits>
47     basic_ostream<_CharT, _Traits>& 
48     basic_ostream<_CharT, _Traits>::
49     operator<<(__ostream_type& (*__pf)(__ostream_type&))
50     {
51       sentry __cerb(*this);
52       if (__cerb)
53         { 
54           try 
55             { __pf(*this); }
56           catch(exception& __fail)
57             {
58               // 27.6.2.5.1 Common requirements.
59               // Turn this on without causing an ios::failure to be thrown.
60               this->setstate(ios_base::badbit);
61               if ((this->exceptions() & ios_base::badbit) != 0)
62                 __throw_exception_again;
63             }
64         }
65       return *this;
66     }
67   
68   template<typename _CharT, typename _Traits>
69     basic_ostream<_CharT, _Traits>& 
70     basic_ostream<_CharT, _Traits>::
71     operator<<(__ios_type& (*__pf)(__ios_type&))
72     {
73       sentry __cerb(*this);
74       if (__cerb)
75         { 
76           try 
77             { __pf(*this); }
78           catch(exception& __fail)
79             {
80               // 27.6.2.5.1 Common requirements.
81               // Turn this on without causing an ios::failure to be thrown.
82               this->setstate(ios_base::badbit);
83               if ((this->exceptions() & ios_base::badbit) != 0)
84                 __throw_exception_again;
85             }
86         }
87       return *this;
88     }
89
90   template<typename _CharT, typename _Traits>
91     basic_ostream<_CharT, _Traits>& 
92     basic_ostream<_CharT, _Traits>::
93     operator<<(ios_base& (*__pf)(ios_base&))
94     {
95       sentry __cerb(*this);
96       if (__cerb)
97         { 
98           try 
99             { __pf(*this); }
100           catch(exception& __fail)
101             {
102               // 27.6.2.5.1 Common requirements.
103               // Turn this on without causing an ios::failure to be thrown.
104               this->setstate(ios_base::badbit);
105               if ((this->exceptions() & ios_base::badbit) != 0)
106                 __throw_exception_again;
107             }
108         }
109       return *this;
110     }
111
112   template<typename _CharT, typename _Traits>
113     basic_ostream<_CharT, _Traits>& 
114     basic_ostream<_CharT, _Traits>::operator<<(bool __n)
115     {
116       sentry __cerb(*this);
117       if (__cerb) 
118         {
119           try 
120             {
121               if (_M_check_facet(_M_fnumput))
122                 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
123                   this->setstate(ios_base::badbit);
124             }
125           catch(exception& __fail)
126             {
127               // 27.6.1.2.1 Common requirements.
128               // Turn this on without causing an ios::failure to be thrown.
129               this->setstate(ios_base::badbit);
130               if ((this->exceptions() & ios_base::badbit) != 0)
131                 __throw_exception_again;
132             }
133         }
134       return *this;
135     }
136
137   template<typename _CharT, typename _Traits>
138     basic_ostream<_CharT, _Traits>& 
139     basic_ostream<_CharT, _Traits>::operator<<(long __n)
140     {
141       sentry __cerb(*this);
142       if (__cerb) 
143         {
144           try 
145             {
146               char_type __c = this->fill();
147               ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
148               if (_M_check_facet(_M_fnumput))
149                 {
150                   bool __b = false;
151                   if (__fmt & ios_base::oct || __fmt & ios_base::hex)
152                     {
153                       unsigned long __l = static_cast<unsigned long>(__n);
154                       __b = _M_fnumput->put(*this, *this, __c, __l).failed();
155                     }
156                   else
157                     __b = _M_fnumput->put(*this, *this, __c, __n).failed();
158                   if (__b)  
159                     this->setstate(ios_base::badbit);
160                 }
161             }
162           catch(exception& __fail)
163             {
164               // 27.6.1.2.1 Common requirements.
165               // Turn this on without causing an ios::failure to be thrown.
166               this->setstate(ios_base::badbit);
167               if ((this->exceptions() & ios_base::badbit) != 0)
168                 __throw_exception_again;
169             }
170         }
171       return *this;
172     }
173
174   template<typename _CharT, typename _Traits>
175     basic_ostream<_CharT, _Traits>& 
176     basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
177     {
178       sentry __cerb(*this);
179       if (__cerb) 
180         {
181           try 
182             {
183               if (_M_check_facet(_M_fnumput))
184                 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
185                   this->setstate(ios_base::badbit);
186             }
187           catch(exception& __fail)
188             {
189               // 27.6.1.2.1 Common requirements.
190               // Turn this on without causing an ios::failure to be thrown.
191               this->setstate(ios_base::badbit);
192               if ((this->exceptions() & ios_base::badbit) != 0)
193                 __throw_exception_again;
194             }
195         }
196       return *this;
197     }
198
199 #ifdef _GLIBCPP_USE_LONG_LONG
200   template<typename _CharT, typename _Traits>
201     basic_ostream<_CharT, _Traits>& 
202     basic_ostream<_CharT, _Traits>::operator<<(long long __n)
203     {
204       sentry __cerb(*this);
205       if (__cerb) 
206         {
207           try 
208             {
209               char_type __c = this->fill();
210               ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
211               if (_M_check_facet(_M_fnumput))
212                 {
213                   bool __b = false;
214                   if (__fmt & ios_base::oct || __fmt & ios_base::hex)
215                     {
216                       unsigned long long __l;
217                       __l = static_cast<unsigned long long>(__n);
218                       __b = _M_fnumput->put(*this, *this, __c, __l).failed();
219                     }
220                   else
221                     __b = _M_fnumput->put(*this, *this, __c, __n).failed();
222                   if (__b)  
223                     this->setstate(ios_base::badbit);
224                 }
225             }
226           catch(exception& __fail)
227             {
228               // 27.6.1.2.1 Common requirements.
229               // Turn this on without causing an ios::failure to be thrown.
230               this->setstate(ios_base::badbit);
231               if ((this->exceptions() & ios_base::badbit) != 0)
232                 __throw_exception_again;
233             }
234         }
235       return *this;
236     }
237
238   template<typename _CharT, typename _Traits>
239     basic_ostream<_CharT, _Traits>& 
240     basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
241     {
242       sentry __cerb(*this);
243       if (__cerb) 
244         {
245           try 
246             {
247               if (_M_check_facet(_M_fnumput))
248                 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
249                   this->setstate(ios_base::badbit);
250             }
251           catch(exception& __fail)
252             {
253               // 27.6.1.2.1 Common requirements.
254               // Turn this on without causing an ios::failure to be thrown.
255               this->setstate(ios_base::badbit);
256               if ((this->exceptions() & ios_base::badbit) != 0)
257                 __throw_exception_again;
258             }
259         }
260       return *this;
261     }
262 #endif
263   
264   template<typename _CharT, typename _Traits>
265     basic_ostream<_CharT, _Traits>& 
266     basic_ostream<_CharT, _Traits>::operator<<(double __n)
267     {
268       sentry __cerb(*this);
269       if (__cerb) 
270         {
271           try 
272             {
273               if (_M_check_facet(_M_fnumput))
274                 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
275                   this->setstate(ios_base::badbit);
276             }
277           catch(exception& __fail)
278             {
279               // 27.6.1.2.1 Common requirements.
280               // Turn this on without causing an ios::failure to be thrown.
281               this->setstate(ios_base::badbit);
282               if ((this->exceptions() & ios_base::badbit) != 0)
283                 __throw_exception_again;
284             }
285         }
286       return *this;
287     }
288   
289   template<typename _CharT, typename _Traits>
290     basic_ostream<_CharT, _Traits>& 
291     basic_ostream<_CharT, _Traits>::operator<<(long double __n)
292     {
293       sentry __cerb(*this);
294       if (__cerb) 
295         {
296           try 
297             {
298               if (_M_check_facet(_M_fnumput))
299                 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
300                   this->setstate(ios_base::badbit);
301             }
302           catch(exception& __fail)
303             {
304               // 27.6.1.2.1 Common requirements.
305               // Turn this on without causing an ios::failure to be thrown.
306               this->setstate(ios_base::badbit);
307               if ((this->exceptions() & ios_base::badbit) != 0)
308                 __throw_exception_again;
309             }
310         }
311       return *this;
312     }
313
314   template<typename _CharT, typename _Traits>
315     basic_ostream<_CharT, _Traits>& 
316     basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
317     {
318       sentry __cerb(*this);
319       if (__cerb) 
320         {
321           try 
322             {
323               if (_M_check_facet(_M_fnumput))
324                 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
325                   this->setstate(ios_base::badbit);
326             }
327           catch(exception& __fail)
328             {
329               // 27.6.1.2.1 Common requirements.
330               // Turn this on without causing an ios::failure to be thrown.
331               this->setstate(ios_base::badbit);
332               if ((this->exceptions() & ios_base::badbit) != 0)
333                 __throw_exception_again;
334             }
335         }
336       return *this;
337     }
338
339   template<typename _CharT, typename _Traits>
340     basic_ostream<_CharT, _Traits>& 
341     basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
342     {
343       streamsize __xtrct = 0;
344       __streambuf_type* __sbout = this->rdbuf();
345       sentry __cerb(*this);
346       if (__sbin && __cerb)
347         __xtrct = __copy_streambufs(*this, __sbin, __sbout);
348       if (!__sbin || !__xtrct)
349         this->setstate(ios_base::failbit);
350       return *this;
351     }
352
353   template<typename _CharT, typename _Traits>
354     basic_ostream<_CharT, _Traits>&
355     basic_ostream<_CharT, _Traits>::put(char_type __c)
356     { 
357       sentry __cerb(*this);
358       if (__cerb) 
359         {
360           int_type __put = rdbuf()->sputc(__c); 
361           if (__put != traits_type::to_int_type(__c))
362             this->setstate(ios_base::badbit);
363         }
364       return *this;
365     }
366
367   template<typename _CharT, typename _Traits>
368     basic_ostream<_CharT, _Traits>&
369     basic_ostream<_CharT, _Traits>::write(const _CharT* __s, streamsize __n)
370     {
371       sentry __cerb(*this);
372       if (__cerb)
373         {
374           streamsize __put = this->rdbuf()->sputn(__s, __n);
375           if ( __put != __n)
376             this->setstate(ios_base::badbit);
377         }
378       return *this;
379     }
380
381   template<typename _CharT, typename _Traits>
382     basic_ostream<_CharT, _Traits>&
383     basic_ostream<_CharT, _Traits>::flush()
384     {
385       sentry __cerb(*this);
386       if (__cerb) 
387         {
388           if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
389             this->setstate(ios_base::badbit);
390         }
391       return *this;
392     }
393   
394   template<typename _CharT, typename _Traits>
395     typename basic_ostream<_CharT, _Traits>::pos_type
396     basic_ostream<_CharT, _Traits>::tellp()
397     {
398       pos_type __ret = pos_type(-1);
399       bool __testok = this->fail() != true;
400       
401       if (__testok)
402         __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
403       return __ret;
404     }
405
406
407   template<typename _CharT, typename _Traits>
408     basic_ostream<_CharT, _Traits>&
409     basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
410     {
411       bool __testok = this->fail() != true;
412       
413       if (__testok)
414 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
415 // 136.  seekp, seekg setting wrong streams?
416         this->rdbuf()->pubseekpos(__pos, ios_base::out);
417 #endif
418       return *this;
419     }
420
421   template<typename _CharT, typename _Traits>
422     basic_ostream<_CharT, _Traits>&
423     basic_ostream<_CharT, _Traits>::
424     seekp(off_type __off, ios_base::seekdir __d)
425     {
426       bool __testok = this->fail() != true;
427       
428       if (__testok)
429 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
430 // 136.  seekp, seekg setting wrong streams?
431         this->rdbuf()->pubseekoff(__off, __d, ios_base::out);
432 #endif
433       return *this;
434     }
435
436   // 27.6.2.5.4 Character inserters
437
438   // Construct correctly padded string, as per 22.2.2.2.2
439   // Similar in theory to __pad_numeric, from num_put, but it doesn't
440   // use _S_fill: perhaps it should.
441   // Assumes 
442   // __newlen > __oldlen
443   // __news is allocated for __newlen size
444   template<typename _CharT, typename _Traits>
445     void
446     __pad_char(basic_ios<_CharT, _Traits>& __ios, 
447                _CharT* __news, const _CharT* __olds,
448                const streamsize __newlen, const streamsize __oldlen)
449     {
450       typedef _CharT    char_type;
451       typedef _Traits   traits_type;
452       typedef typename traits_type::int_type int_type;
453       
454       int_type __plen = static_cast<size_t>(__newlen - __oldlen); 
455       char_type* __pads = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __plen));
456       traits_type::assign(__pads, __plen, __ios.fill()); 
457
458       char_type* __beg;
459       char_type* __end;
460       size_t __mod = 0;
461       size_t __beglen; //either __plen or __oldlen
462       ios_base::fmtflags __fmt = __ios.flags() & ios_base::adjustfield;
463
464       if (__fmt == ios_base::left)
465         {
466           // Padding last.
467           __beg = const_cast<char_type*>(__olds);
468           __beglen = __oldlen;
469           __end = __pads;
470         }
471       else if (__fmt == ios_base::internal)
472         {
473           // Pad after the sign, if there is one.
474           // Pad after 0[xX], if there is one.
475           // Who came up with these rules, anyway? Jeeze.
476           typedef _Format_cache<_CharT> __cache_type;
477           __cache_type const* __fmt = __cache_type::_S_get(__ios);
478           const char_type* __minus = traits_type::find(__olds, __oldlen, 
479                                                        __fmt->_S_minus);
480           const char_type* __plus = traits_type::find(__olds, __oldlen, 
481                                                       __fmt->_S_plus);
482           bool __testsign = __minus || __plus;
483           bool __testhex = __olds[0] == '0' 
484                            && (__olds[1] == 'x' || __olds[1] == 'X');
485
486           if (__testhex)
487             {
488               __news[0] = __olds[0]; 
489               __news[1] = __olds[1];
490               __mod += 2;
491               __beg = const_cast<char_type*>(__olds + __mod);
492               __beglen = __oldlen - __mod;
493               __end = __pads;
494             }
495           else if (__testsign)
496             {
497               __mod += __plen;
498               const char_type* __sign = __minus ? __minus + 1: __plus + 1;
499               __beg = const_cast<char_type*>(__olds);
500               __beglen = __sign - __olds;
501               __end = const_cast<char_type*>(__sign + __plen);
502               traits_type::copy(__news + __beglen, __pads, __plen);
503             }
504           else
505             {
506               // Padding first.
507               __beg = __pads;
508               __beglen = __plen;
509               __end = const_cast<char_type*>(__olds);
510             }
511         }
512       else
513         {
514           // Padding first.
515           __beg = __pads;
516           __beglen = __plen;
517           __end = const_cast<char_type*>(__olds);
518         }
519
520       traits_type::copy(__news, __beg, __beglen);
521       traits_type::copy(__news + __beglen, __end, __newlen - __beglen - __mod);
522     }
523
524   template<typename _CharT, typename _Traits>
525     basic_ostream<_CharT, _Traits>&
526     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
527     {
528       typedef basic_ostream<_CharT, _Traits> __ostream_type;
529       typename __ostream_type::sentry __cerb(__out);
530       if (__cerb)
531         {
532           try 
533             {
534               streamsize __w = __out.width();
535               _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
536               __pads[0] = __c;
537               streamsize __len = 1;
538               if (__w > __len)
539                 {
540                   __pad_char(__out, __pads, &__c, __w, __len);
541                   __len = __w;
542                 }
543               __out.write(__pads, __len);
544               __out.width(0);
545             }
546           catch(exception& __fail)
547             {
548               // 27.6.1.2.1 Common requirements.
549               // Turn this on without causing an ios::failure to be thrown.
550               __out.setstate(ios_base::badbit);
551               if ((__out.exceptions() & ios_base::badbit) != 0)
552                 __throw_exception_again;
553             }
554         }
555       return __out;
556     }
557   
558   // Specialization
559   template <class _Traits> 
560     basic_ostream<char, _Traits>&
561     operator<<(basic_ostream<char, _Traits>& __out, char __c)
562     {
563       typedef basic_ostream<char, _Traits> __ostream_type;
564       typename __ostream_type::sentry __cerb(__out);
565       if (__cerb)
566         {
567           try 
568             {
569               streamsize __w = __out.width();
570               char* __pads = static_cast<char*>(__builtin_alloca(__w + 1));
571               __pads[0] = __c;
572               streamsize __len = 1;
573               if (__w > __len)
574                 {
575                   __pad_char(__out, __pads, &__c, __w, __len);
576                   __len = __w;
577                 }
578               __out.write(__pads, __len);
579               __out.width(0);
580             }
581           catch(exception& __fail)
582             {
583               // 27.6.1.2.1 Common requirements.
584               // Turn this on without causing an ios::failure to be thrown.
585               __out.setstate(ios_base::badbit);
586               if ((__out.exceptions() & ios_base::badbit) != 0)
587                 __throw_exception_again;
588             }
589         }
590       return __out;
591      }
592
593   template<typename _CharT, typename _Traits>
594     basic_ostream<_CharT, _Traits>&
595     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
596     {
597       typedef basic_ostream<_CharT, _Traits> __ostream_type;
598       typename __ostream_type::sentry __cerb(__out);
599       if (__cerb)
600         {
601           try 
602             {
603               streamsize __w = __out.width();
604               _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
605               streamsize __len = static_cast<streamsize>(_Traits::length(__s));
606               if (__w > __len)
607                 {
608                   __pad_char(__out, __pads, __s, __w, __len);
609                   __s = __pads;
610                   __len = __w;
611                 }
612               __out.write(__s, __len);
613               __out.width(0);
614             }
615           catch(exception& __fail)
616             {
617               // 27.6.1.2.1 Common requirements.
618               // Turn this on without causing an ios::failure to be thrown.
619               __out.setstate(ios_base::badbit);
620               if ((__out.exceptions() & ios_base::badbit) != 0)
621                 __throw_exception_again;
622             }
623         }
624       return __out;
625     }
626
627   template<typename _CharT, typename _Traits>
628     basic_ostream<_CharT, _Traits>&
629     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
630     {
631       typedef basic_ostream<_CharT, _Traits> __ostream_type;
632 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
633 // 167.  Improper use of traits_type::length()
634       typedef char_traits<char>              __ctraits_type;
635 #endif
636       typename __ostream_type::sentry __cerb(__out);
637       if (__cerb)
638         {
639           size_t __clen = __ctraits_type::length(__s);
640           _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
641           for (size_t  __i = 0; __i <= __clen; ++__i)
642             __ws[__i] = __out.widen(__s[__i]);
643           _CharT* __str = __ws;
644           
645           try 
646             {
647               streamsize __len = static_cast<streamsize>(__clen);
648               streamsize __w = __out.width();
649               _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
650               
651               if (__w > __len)
652                 {
653                   __pad_char(__out, __pads, __ws, __w, __len);
654                   __str = __pads;
655                   __len = __w;
656                 }
657               __out.write(__str, __len);
658               __out.width(0);
659             }
660           catch(exception& __fail)
661             {
662               // 27.6.1.2.1 Common requirements.
663               // Turn this on without causing an ios::failure to be thrown.
664               __out.setstate(ios_base::badbit);
665               if ((__out.exceptions() & ios_base::badbit) != 0)
666                 __throw_exception_again;
667             }
668         }
669       return __out;
670     }
671
672   // Partial specializationss
673   template<class _Traits>
674     basic_ostream<char, _Traits>&
675     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
676     {
677       typedef basic_ostream<char, _Traits> __ostream_type;
678       typename __ostream_type::sentry __cerb(__out);
679       if (__cerb)
680         {
681           try 
682             {
683               streamsize __w = __out.width();
684               char* __pads = static_cast<char*>(__builtin_alloca(__w));
685               streamsize __len = static_cast<streamsize>(_Traits::length(__s));
686               if (__w > __len)
687                 {
688                   __pad_char(__out, __pads, __s, __w, __len);
689                   __s = __pads;
690                   __len = __w;
691                 }
692               __out.write(__s, __len);
693               __out.width(0);
694             }
695           catch(exception& __fail)
696             {
697               // 27.6.1.2.1 Common requirements.
698               // Turn this on without causing an ios::failure to be thrown.
699               __out.setstate(ios_base::badbit);
700               if ((__out.exceptions() & ios_base::badbit) != 0)
701                 __throw_exception_again;
702             }
703         }
704       return __out;
705     }
706
707   // 21.3.7.9 basic_string::operator<<
708   template<typename _CharT, typename _Traits, typename _Alloc>
709     basic_ostream<_CharT, _Traits>&
710     operator<<(basic_ostream<_CharT, _Traits>& __out,
711                const basic_string<_CharT, _Traits, _Alloc>& __str)
712     { 
713       typedef basic_ostream<_CharT, _Traits> __ostream_type;
714       typename __ostream_type::sentry __cerb(__out);
715       if (__cerb)
716         {
717           const _CharT* __s = __str.data();
718           streamsize __w = __out.width();
719           _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
720           streamsize __len = static_cast<streamsize>(__str.size());
721 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
722           // 25. String operator<< uses width() value wrong
723 #endif
724           if (__w > __len)
725             {
726               __pad_char(__out, __pads, __s, __w, __len);
727               __s = __pads;
728               __len = __w;
729             }
730           streamsize __res = __out.rdbuf()->sputn(__s, __len);
731           __out.width(0);
732           if (__res != __len)
733             __out.setstate(ios_base::failbit);
734         }
735       return __out;
736     }
737 } // namespace std
738  
739 // Local Variables:
740 // mode:C++
741 // End:
742