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