1227825Stheraven// -*- C++ -*-
2227825Stheraven//===-------------------------- ostream -----------------------------------===//
3227825Stheraven//
4353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5353358Sdim// See https://llvm.org/LICENSE.txt for license information.
6353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7227825Stheraven//
8227825Stheraven//===----------------------------------------------------------------------===//
9227825Stheraven
10227825Stheraven#ifndef _LIBCPP_OSTREAM
11227825Stheraven#define _LIBCPP_OSTREAM
12227825Stheraven
13227825Stheraven/*
14227825Stheraven    ostream synopsis
15227825Stheraven
16227825Stheraventemplate <class charT, class traits = char_traits<charT> >
17227825Stheravenclass basic_ostream
18227825Stheraven    : virtual public basic_ios<charT,traits>
19227825Stheraven{
20227825Stheravenpublic:
21227825Stheraven    // types (inherited from basic_ios (27.5.4)):
22227825Stheraven    typedef charT                          char_type;
23227825Stheraven    typedef traits                         traits_type;
24227825Stheraven    typedef typename traits_type::int_type int_type;
25227825Stheraven    typedef typename traits_type::pos_type pos_type;
26227825Stheraven    typedef typename traits_type::off_type off_type;
27227825Stheraven
28227825Stheraven    // 27.7.2.2 Constructor/destructor:
29227825Stheraven    explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
30227825Stheraven    basic_ostream(basic_ostream&& rhs);
31227825Stheraven    virtual ~basic_ostream();
32227825Stheraven
33227825Stheraven    // 27.7.2.3 Assign/swap
34261272Sdim    basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
35227825Stheraven    basic_ostream& operator=(basic_ostream&& rhs);
36227825Stheraven    void swap(basic_ostream& rhs);
37227825Stheraven
38227825Stheraven    // 27.7.2.4 Prefix/suffix:
39227825Stheraven    class sentry;
40227825Stheraven
41227825Stheraven    // 27.7.2.6 Formatted output:
42227825Stheraven    basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
43227825Stheraven    basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
44227825Stheraven    basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
45227825Stheraven    basic_ostream& operator<<(bool n);
46227825Stheraven    basic_ostream& operator<<(short n);
47227825Stheraven    basic_ostream& operator<<(unsigned short n);
48227825Stheraven    basic_ostream& operator<<(int n);
49227825Stheraven    basic_ostream& operator<<(unsigned int n);
50227825Stheraven    basic_ostream& operator<<(long n);
51227825Stheraven    basic_ostream& operator<<(unsigned long n);
52227825Stheraven    basic_ostream& operator<<(long long n);
53227825Stheraven    basic_ostream& operator<<(unsigned long long n);
54227825Stheraven    basic_ostream& operator<<(float f);
55227825Stheraven    basic_ostream& operator<<(double f);
56227825Stheraven    basic_ostream& operator<<(long double f);
57227825Stheraven    basic_ostream& operator<<(const void* p);
58227825Stheraven    basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
59353358Sdim    basic_ostream& operator<<(nullptr_t);
60227825Stheraven
61227825Stheraven    // 27.7.2.7 Unformatted output:
62227825Stheraven    basic_ostream& put(char_type c);
63227825Stheraven    basic_ostream& write(const char_type* s, streamsize n);
64227825Stheraven    basic_ostream& flush();
65227825Stheraven
66227825Stheraven    // 27.7.2.5 seeks:
67227825Stheraven    pos_type tellp();
68227825Stheraven    basic_ostream& seekp(pos_type);
69227825Stheraven    basic_ostream& seekp(off_type, ios_base::seekdir);
70276792Sdimprotected:
71276792Sdim    basic_ostream(const basic_ostream& rhs) = delete;
72276792Sdim    basic_ostream(basic_ostream&& rhs);
73276792Sdim    // 27.7.3.3 Assign/swap
74276792Sdim    basic_ostream& operator=(basic_ostream& rhs) = delete;
75276792Sdim    basic_ostream& operator=(const basic_ostream&& rhs);
76276792Sdim    void swap(basic_ostream& rhs);
77227825Stheraven};
78227825Stheraven
79227825Stheraven// 27.7.2.6.4 character inserters
80227825Stheraven
81227825Stheraventemplate<class charT, class traits>
82227825Stheraven  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
83227825Stheraven
84227825Stheraventemplate<class charT, class traits>
85227825Stheraven  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
86227825Stheraven
87227825Stheraventemplate<class traits>
88227825Stheraven  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
89227825Stheraven
90227825Stheraven// signed and unsigned
91227825Stheraven
92227825Stheraventemplate<class traits>
93227825Stheraven  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
94227825Stheraven
95227825Stheraventemplate<class traits>
96227825Stheraven  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
97227825Stheraven
98227825Stheraven// NTBS
99227825Stheraventemplate<class charT, class traits>
100227825Stheraven  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
101227825Stheraven
102227825Stheraventemplate<class charT, class traits>
103227825Stheraven  basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
104227825Stheraven
105227825Stheraventemplate<class traits>
106227825Stheraven  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
107227825Stheraven
108227825Stheraven// signed and unsigned
109227825Stheraventemplate<class traits>
110227825Stheravenbasic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
111227825Stheraven
112227825Stheraventemplate<class traits>
113227825Stheraven  basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
114227825Stheraven
115227825Stheraven// swap:
116227825Stheraventemplate <class charT, class traits>
117227825Stheraven  void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
118227825Stheraven
119227825Stheraventemplate <class charT, class traits>
120227825Stheraven  basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
121227825Stheraven
122227825Stheraventemplate <class charT, class traits>
123227825Stheraven  basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
124227825Stheraven
125227825Stheraventemplate <class charT, class traits>
126227825Stheraven  basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
127227825Stheraven
128227825Stheraven// rvalue stream insertion
129227825Stheraventemplate <class charT, class traits, class T>
130227825Stheraven  basic_ostream<charT, traits>&
131227825Stheraven  operator<<(basic_ostream<charT, traits>&& os, const T& x);
132227825Stheraven
133227825Stheraven}  // std
134227825Stheraven
135227825Stheraven*/
136227825Stheraven
137227825Stheraven#include <__config>
138227825Stheraven#include <ios>
139227825Stheraven#include <streambuf>
140227825Stheraven#include <locale>
141227825Stheraven#include <iterator>
142227825Stheraven#include <bitset>
143344779Sdim#include <version>
144227825Stheraven
145227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
146227825Stheraven#pragma GCC system_header
147227825Stheraven#endif
148227825Stheraven
149227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
150227825Stheraven
151227825Stheraventemplate <class _CharT, class _Traits>
152314564Sdimclass _LIBCPP_TEMPLATE_VIS basic_ostream
153227825Stheraven    : virtual public basic_ios<_CharT, _Traits>
154227825Stheraven{
155227825Stheravenpublic:
156227825Stheraven    // types (inherited from basic_ios (27.5.4)):
157227825Stheraven    typedef _CharT                         char_type;
158227825Stheraven    typedef _Traits                        traits_type;
159227825Stheraven    typedef typename traits_type::int_type int_type;
160227825Stheraven    typedef typename traits_type::pos_type pos_type;
161227825Stheraven    typedef typename traits_type::off_type off_type;
162227825Stheraven
163227825Stheraven    // 27.7.2.2 Constructor/destructor:
164344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
165314564Sdim    explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
166314564Sdim    { this->init(__sb); }
167227825Stheraven    virtual ~basic_ostream();
168227825Stheravenprotected:
169321369Sdim#ifndef _LIBCPP_CXX03_LANG
170314564Sdim    inline _LIBCPP_INLINE_VISIBILITY
171227825Stheraven    basic_ostream(basic_ostream&& __rhs);
172227825Stheraven
173227825Stheraven    // 27.7.2.3 Assign/swap
174314564Sdim    inline _LIBCPP_INLINE_VISIBILITY
175227825Stheraven    basic_ostream& operator=(basic_ostream&& __rhs);
176227825Stheraven#endif
177344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
178314564Sdim    void swap(basic_ostream& __rhs)
179314564Sdim    { basic_ios<char_type, traits_type>::swap(__rhs); }
180276792Sdim
181314564Sdim#ifndef _LIBCPP_CXX03_LANG
182276792Sdim    basic_ostream           (const basic_ostream& __rhs) = delete;
183276792Sdim    basic_ostream& operator=(const basic_ostream& __rhs) = delete;
184276792Sdim#else
185276792Sdim    basic_ostream           (const basic_ostream& __rhs); // not defined
186276792Sdim    basic_ostream& operator=(const basic_ostream& __rhs); // not defined
187276792Sdim#endif
188227825Stheravenpublic:
189227825Stheraven
190227825Stheraven    // 27.7.2.4 Prefix/suffix:
191314564Sdim    class _LIBCPP_TEMPLATE_VIS sentry;
192227825Stheraven
193227825Stheraven    // 27.7.2.6 Formatted output:
194344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
195314564Sdim    basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
196314564Sdim    { return __pf(*this); }
197314564Sdim
198344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
199227825Stheraven    basic_ostream& operator<<(basic_ios<char_type, traits_type>&
200314564Sdim                              (*__pf)(basic_ios<char_type,traits_type>&))
201314564Sdim    { __pf(*this); return *this; }
202314564Sdim
203344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
204314564Sdim    basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
205314564Sdim    { __pf(*this); return *this; }
206314564Sdim
207227825Stheraven    basic_ostream& operator<<(bool __n);
208227825Stheraven    basic_ostream& operator<<(short __n);
209227825Stheraven    basic_ostream& operator<<(unsigned short __n);
210227825Stheraven    basic_ostream& operator<<(int __n);
211227825Stheraven    basic_ostream& operator<<(unsigned int __n);
212227825Stheraven    basic_ostream& operator<<(long __n);
213227825Stheraven    basic_ostream& operator<<(unsigned long __n);
214227825Stheraven    basic_ostream& operator<<(long long __n);
215227825Stheraven    basic_ostream& operator<<(unsigned long long __n);
216227825Stheraven    basic_ostream& operator<<(float __f);
217227825Stheraven    basic_ostream& operator<<(double __f);
218227825Stheraven    basic_ostream& operator<<(long double __f);
219227825Stheraven    basic_ostream& operator<<(const void* __p);
220227825Stheraven    basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
221227825Stheraven
222353358Sdim    _LIBCPP_INLINE_VISIBILITY
223353358Sdim    basic_ostream& operator<<(nullptr_t)
224353358Sdim    { return *this << "nullptr"; }
225353358Sdim
226227825Stheraven    // 27.7.2.7 Unformatted output:
227227825Stheraven    basic_ostream& put(char_type __c);
228227825Stheraven    basic_ostream& write(const char_type* __s, streamsize __n);
229227825Stheraven    basic_ostream& flush();
230227825Stheraven
231227825Stheraven    // 27.7.2.5 seeks:
232344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
233227825Stheraven    pos_type tellp();
234344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
235227825Stheraven    basic_ostream& seekp(pos_type __pos);
236344779Sdim    inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
237227825Stheraven    basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
238227825Stheraven
239227825Stheravenprotected:
240341825Sdim    _LIBCPP_INLINE_VISIBILITY
241227825Stheraven    basic_ostream() {}  // extension, intentially does not initialize
242227825Stheraven};
243227825Stheraven
244227825Stheraventemplate <class _CharT, class _Traits>
245314564Sdimclass _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
246227825Stheraven{
247227825Stheraven    bool __ok_;
248227825Stheraven    basic_ostream<_CharT, _Traits>& __os_;
249227825Stheraven
250227825Stheraven    sentry(const sentry&); // = delete;
251227825Stheraven    sentry& operator=(const sentry&); // = delete;
252227825Stheraven
253227825Stheravenpublic:
254227825Stheraven    explicit sentry(basic_ostream<_CharT, _Traits>& __os);
255227825Stheraven    ~sentry();
256227825Stheraven
257341825Sdim    _LIBCPP_INLINE_VISIBILITY
258232924Stheraven        _LIBCPP_EXPLICIT
259227825Stheraven        operator bool() const {return __ok_;}
260227825Stheraven};
261227825Stheraven
262227825Stheraventemplate <class _CharT, class _Traits>
263227825Stheravenbasic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
264227825Stheraven    : __ok_(false),
265227825Stheraven      __os_(__os)
266227825Stheraven{
267227825Stheraven    if (__os.good())
268227825Stheraven    {
269227825Stheraven        if (__os.tie())
270227825Stheraven            __os.tie()->flush();
271227825Stheraven        __ok_ = true;
272227825Stheraven    }
273227825Stheraven}
274227825Stheraven
275227825Stheraventemplate <class _CharT, class _Traits>
276227825Stheravenbasic_ostream<_CharT, _Traits>::sentry::~sentry()
277227825Stheraven{
278227825Stheraven    if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
279227825Stheraven                      && !uncaught_exception())
280227825Stheraven    {
281227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
282227825Stheraven        try
283227825Stheraven        {
284227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
285227825Stheraven            if (__os_.rdbuf()->pubsync() == -1)
286227825Stheraven                __os_.setstate(ios_base::badbit);
287227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
288227825Stheraven        }
289227825Stheraven        catch (...)
290227825Stheraven        {
291227825Stheraven        }
292227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
293227825Stheraven    }
294227825Stheraven}
295227825Stheraven
296321369Sdim#ifndef _LIBCPP_CXX03_LANG
297227825Stheraven
298227825Stheraventemplate <class _CharT, class _Traits>
299227825Stheravenbasic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
300227825Stheraven{
301227825Stheraven    this->move(__rhs);
302227825Stheraven}
303227825Stheraven
304227825Stheraventemplate <class _CharT, class _Traits>
305227825Stheravenbasic_ostream<_CharT, _Traits>&
306227825Stheravenbasic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
307227825Stheraven{
308227825Stheraven    swap(__rhs);
309227825Stheraven    return *this;
310227825Stheraven}
311227825Stheraven
312321369Sdim#endif  // _LIBCPP_CXX03_LANG
313227825Stheraven
314227825Stheraventemplate <class _CharT, class _Traits>
315227825Stheravenbasic_ostream<_CharT, _Traits>::~basic_ostream()
316227825Stheraven{
317227825Stheraven}
318227825Stheraven
319227825Stheraventemplate <class _CharT, class _Traits>
320227825Stheravenbasic_ostream<_CharT, _Traits>&
321227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
322227825Stheraven{
323227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
324227825Stheraven    try
325227825Stheraven    {
326227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
327227825Stheraven        sentry __s(*this);
328227825Stheraven        if (__s)
329227825Stheraven        {
330227825Stheraven            if (__sb)
331227825Stheraven            {
332227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
333227825Stheraven                try
334227825Stheraven                {
335227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
336232924Stheraven                    typedef istreambuf_iterator<_CharT, _Traits> _Ip;
337232924Stheraven                    typedef ostreambuf_iterator<_CharT, _Traits> _Op;
338232924Stheraven                    _Ip __i(__sb);
339232924Stheraven                    _Ip __eof;
340232924Stheraven                    _Op __o(*this);
341227825Stheraven                    size_t __c = 0;
342227825Stheraven                    for (; __i != __eof; ++__i, ++__o, ++__c)
343227825Stheraven                    {
344227825Stheraven                        *__o = *__i;
345227825Stheraven                        if (__o.failed())
346227825Stheraven                            break;
347227825Stheraven                    }
348227825Stheraven                    if (__c == 0)
349227825Stheraven                        this->setstate(ios_base::failbit);
350227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
351227825Stheraven                }
352227825Stheraven                catch (...)
353227825Stheraven                {
354227825Stheraven                    this->__set_failbit_and_consider_rethrow();
355227825Stheraven                }
356227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
357227825Stheraven            }
358227825Stheraven            else
359227825Stheraven                this->setstate(ios_base::badbit);
360227825Stheraven        }
361227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
362227825Stheraven    }
363227825Stheraven    catch (...)
364227825Stheraven    {
365227825Stheraven        this->__set_badbit_and_consider_rethrow();
366227825Stheraven    }
367227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
368227825Stheraven    return *this;
369227825Stheraven}
370227825Stheraven
371227825Stheraventemplate <class _CharT, class _Traits>
372227825Stheravenbasic_ostream<_CharT, _Traits>&
373227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(bool __n)
374227825Stheraven{
375227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
376227825Stheraven    try
377227825Stheraven    {
378227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
379227825Stheraven        sentry __s(*this);
380227825Stheraven        if (__s)
381227825Stheraven        {
382232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
383232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
384227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
385227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
386227825Stheraven        }
387227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
388227825Stheraven    }
389227825Stheraven    catch (...)
390227825Stheraven    {
391227825Stheraven        this->__set_badbit_and_consider_rethrow();
392227825Stheraven    }
393227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
394227825Stheraven    return *this;
395227825Stheraven}
396227825Stheraven
397227825Stheraventemplate <class _CharT, class _Traits>
398227825Stheravenbasic_ostream<_CharT, _Traits>&
399227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(short __n)
400227825Stheraven{
401227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
402227825Stheraven    try
403227825Stheraven    {
404227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
405227825Stheraven        sentry __s(*this);
406227825Stheraven        if (__s)
407227825Stheraven        {
408227825Stheraven            ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
409232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
410232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
411227825Stheraven            if (__f.put(*this, *this, this->fill(),
412227825Stheraven                        __flags == ios_base::oct || __flags == ios_base::hex ?
413227825Stheraven                        static_cast<long>(static_cast<unsigned short>(__n))  :
414227825Stheraven                        static_cast<long>(__n)).failed())
415227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
416227825Stheraven        }
417227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
418227825Stheraven    }
419227825Stheraven    catch (...)
420227825Stheraven    {
421227825Stheraven        this->__set_badbit_and_consider_rethrow();
422227825Stheraven    }
423227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
424227825Stheraven    return *this;
425227825Stheraven}
426227825Stheraven
427227825Stheraventemplate <class _CharT, class _Traits>
428227825Stheravenbasic_ostream<_CharT, _Traits>&
429227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
430227825Stheraven{
431227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
432227825Stheraven    try
433227825Stheraven    {
434227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
435227825Stheraven        sentry __s(*this);
436227825Stheraven        if (__s)
437227825Stheraven        {
438232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
439232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
440227825Stheraven            if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
441227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
442227825Stheraven        }
443227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
444227825Stheraven    }
445227825Stheraven    catch (...)
446227825Stheraven    {
447227825Stheraven        this->__set_badbit_and_consider_rethrow();
448227825Stheraven    }
449227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
450227825Stheraven    return *this;
451227825Stheraven}
452227825Stheraven
453227825Stheraventemplate <class _CharT, class _Traits>
454227825Stheravenbasic_ostream<_CharT, _Traits>&
455227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(int __n)
456227825Stheraven{
457227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
458227825Stheraven    try
459227825Stheraven    {
460227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
461227825Stheraven        sentry __s(*this);
462227825Stheraven        if (__s)
463227825Stheraven        {
464227825Stheraven            ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
465232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
466232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
467227825Stheraven            if (__f.put(*this, *this, this->fill(),
468227825Stheraven                        __flags == ios_base::oct || __flags == ios_base::hex ?
469227825Stheraven                        static_cast<long>(static_cast<unsigned int>(__n))  :
470227825Stheraven                        static_cast<long>(__n)).failed())
471227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
472227825Stheraven        }
473227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
474227825Stheraven    }
475227825Stheraven    catch (...)
476227825Stheraven    {
477227825Stheraven        this->__set_badbit_and_consider_rethrow();
478227825Stheraven    }
479227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
480227825Stheraven    return *this;
481227825Stheraven}
482227825Stheraven
483227825Stheraventemplate <class _CharT, class _Traits>
484227825Stheravenbasic_ostream<_CharT, _Traits>&
485227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
486227825Stheraven{
487227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
488227825Stheraven    try
489227825Stheraven    {
490227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
491227825Stheraven        sentry __s(*this);
492227825Stheraven        if (__s)
493227825Stheraven        {
494232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
495232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
496227825Stheraven            if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
497227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
498227825Stheraven        }
499227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
500227825Stheraven    }
501227825Stheraven    catch (...)
502227825Stheraven    {
503227825Stheraven        this->__set_badbit_and_consider_rethrow();
504227825Stheraven    }
505227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
506227825Stheraven    return *this;
507227825Stheraven}
508227825Stheraven
509227825Stheraventemplate <class _CharT, class _Traits>
510227825Stheravenbasic_ostream<_CharT, _Traits>&
511227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(long __n)
512227825Stheraven{
513227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
514227825Stheraven    try
515227825Stheraven    {
516227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
517227825Stheraven        sentry __s(*this);
518227825Stheraven        if (__s)
519227825Stheraven        {
520232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
521232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
522227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
523227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
524227825Stheraven        }
525227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
526227825Stheraven    }
527227825Stheraven    catch (...)
528227825Stheraven    {
529227825Stheraven        this->__set_badbit_and_consider_rethrow();
530227825Stheraven    }
531227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
532227825Stheraven    return *this;
533227825Stheraven}
534227825Stheraven
535227825Stheraventemplate <class _CharT, class _Traits>
536227825Stheravenbasic_ostream<_CharT, _Traits>&
537227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
538227825Stheraven{
539227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
540227825Stheraven    try
541227825Stheraven    {
542227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
543227825Stheraven        sentry __s(*this);
544227825Stheraven        if (__s)
545227825Stheraven        {
546232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
547232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
548227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
549227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
550227825Stheraven        }
551227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
552227825Stheraven    }
553227825Stheraven    catch (...)
554227825Stheraven    {
555227825Stheraven        this->__set_badbit_and_consider_rethrow();
556227825Stheraven    }
557227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
558227825Stheraven    return *this;
559227825Stheraven}
560227825Stheraven
561227825Stheraventemplate <class _CharT, class _Traits>
562227825Stheravenbasic_ostream<_CharT, _Traits>&
563227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(long long __n)
564227825Stheraven{
565227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
566227825Stheraven    try
567227825Stheraven    {
568227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
569227825Stheraven        sentry __s(*this);
570227825Stheraven        if (__s)
571227825Stheraven        {
572232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
573232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
574227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
575227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
576227825Stheraven        }
577227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
578227825Stheraven    }
579227825Stheraven    catch (...)
580227825Stheraven    {
581227825Stheraven        this->__set_badbit_and_consider_rethrow();
582227825Stheraven    }
583227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
584227825Stheraven    return *this;
585227825Stheraven}
586227825Stheraven
587227825Stheraventemplate <class _CharT, class _Traits>
588227825Stheravenbasic_ostream<_CharT, _Traits>&
589227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
590227825Stheraven{
591227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
592227825Stheraven    try
593227825Stheraven    {
594227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
595227825Stheraven        sentry __s(*this);
596227825Stheraven        if (__s)
597227825Stheraven        {
598232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
599232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
600227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
601227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
602227825Stheraven        }
603227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
604227825Stheraven    }
605227825Stheraven    catch (...)
606227825Stheraven    {
607227825Stheraven        this->__set_badbit_and_consider_rethrow();
608227825Stheraven    }
609227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
610227825Stheraven    return *this;
611227825Stheraven}
612227825Stheraven
613227825Stheraventemplate <class _CharT, class _Traits>
614227825Stheravenbasic_ostream<_CharT, _Traits>&
615227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(float __n)
616227825Stheraven{
617227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
618227825Stheraven    try
619227825Stheraven    {
620227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
621227825Stheraven        sentry __s(*this);
622227825Stheraven        if (__s)
623227825Stheraven        {
624232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
625232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
626227825Stheraven            if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
627227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
628227825Stheraven        }
629227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
630227825Stheraven    }
631227825Stheraven    catch (...)
632227825Stheraven    {
633227825Stheraven        this->__set_badbit_and_consider_rethrow();
634227825Stheraven    }
635227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
636227825Stheraven    return *this;
637227825Stheraven}
638227825Stheraven
639227825Stheraventemplate <class _CharT, class _Traits>
640227825Stheravenbasic_ostream<_CharT, _Traits>&
641227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(double __n)
642227825Stheraven{
643227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
644227825Stheraven    try
645227825Stheraven    {
646227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
647227825Stheraven        sentry __s(*this);
648227825Stheraven        if (__s)
649227825Stheraven        {
650232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
651232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
652227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
653227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
654227825Stheraven        }
655227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
656227825Stheraven    }
657227825Stheraven    catch (...)
658227825Stheraven    {
659227825Stheraven        this->__set_badbit_and_consider_rethrow();
660227825Stheraven    }
661227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
662227825Stheraven    return *this;
663227825Stheraven}
664227825Stheraven
665227825Stheraventemplate <class _CharT, class _Traits>
666227825Stheravenbasic_ostream<_CharT, _Traits>&
667227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(long double __n)
668227825Stheraven{
669227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
670227825Stheraven    try
671227825Stheraven    {
672227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
673227825Stheraven        sentry __s(*this);
674227825Stheraven        if (__s)
675227825Stheraven        {
676232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
677232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
678227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
679227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
680227825Stheraven        }
681227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
682227825Stheraven    }
683227825Stheraven    catch (...)
684227825Stheraven    {
685227825Stheraven        this->__set_badbit_and_consider_rethrow();
686227825Stheraven    }
687227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
688227825Stheraven    return *this;
689227825Stheraven}
690227825Stheraven
691227825Stheraventemplate <class _CharT, class _Traits>
692227825Stheravenbasic_ostream<_CharT, _Traits>&
693227825Stheravenbasic_ostream<_CharT, _Traits>::operator<<(const void* __n)
694227825Stheraven{
695227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
696227825Stheraven    try
697227825Stheraven    {
698227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
699227825Stheraven        sentry __s(*this);
700227825Stheraven        if (__s)
701227825Stheraven        {
702232924Stheraven            typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
703232924Stheraven            const _Fp& __f = use_facet<_Fp>(this->getloc());
704227825Stheraven            if (__f.put(*this, *this, this->fill(), __n).failed())
705227825Stheraven                this->setstate(ios_base::badbit | ios_base::failbit);
706227825Stheraven        }
707227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
708227825Stheraven    }
709227825Stheraven    catch (...)
710227825Stheraven    {
711227825Stheraven        this->__set_badbit_and_consider_rethrow();
712227825Stheraven    }
713227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
714227825Stheraven    return *this;
715227825Stheraven}
716227825Stheraven
717227825Stheraventemplate<class _CharT, class _Traits>
718227825Stheravenbasic_ostream<_CharT, _Traits>&
719276792Sdim__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
720276792Sdim                          const _CharT* __str, size_t __len)
721227825Stheraven{
722227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
723227825Stheraven    try
724227825Stheraven    {
725227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
726227825Stheraven        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
727227825Stheraven        if (__s)
728227825Stheraven        {
729232924Stheraven            typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
730232924Stheraven            if (__pad_and_output(_Ip(__os),
731276792Sdim                                 __str,
732227825Stheraven                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
733276792Sdim                                     __str + __len :
734276792Sdim                                     __str,
735276792Sdim                                 __str + __len,
736227825Stheraven                                 __os,
737227825Stheraven                                 __os.fill()).failed())
738227825Stheraven                __os.setstate(ios_base::badbit | ios_base::failbit);
739227825Stheraven        }
740227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
741227825Stheraven    }
742227825Stheraven    catch (...)
743227825Stheraven    {
744227825Stheraven        __os.__set_badbit_and_consider_rethrow();
745227825Stheraven    }
746227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
747227825Stheraven    return __os;
748227825Stheraven}
749227825Stheraven
750276792Sdim
751227825Stheraventemplate<class _CharT, class _Traits>
752227825Stheravenbasic_ostream<_CharT, _Traits>&
753276792Sdimoperator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
754276792Sdim{
755276792Sdim    return _VSTD::__put_character_sequence(__os, &__c, 1);
756276792Sdim}
757276792Sdim
758276792Sdimtemplate<class _CharT, class _Traits>
759276792Sdimbasic_ostream<_CharT, _Traits>&
760227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
761227825Stheraven{
762227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
763227825Stheraven    try
764227825Stheraven    {
765227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
766227825Stheraven        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
767227825Stheraven        if (__s)
768227825Stheraven        {
769227825Stheraven            _CharT __c = __os.widen(__cn);
770232924Stheraven            typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
771232924Stheraven            if (__pad_and_output(_Ip(__os),
772227825Stheraven                                 &__c,
773227825Stheraven                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
774227825Stheraven                                     &__c + 1 :
775227825Stheraven                                     &__c,
776227825Stheraven                                 &__c + 1,
777227825Stheraven                                 __os,
778227825Stheraven                                 __os.fill()).failed())
779227825Stheraven                __os.setstate(ios_base::badbit | ios_base::failbit);
780227825Stheraven        }
781227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
782227825Stheraven    }
783227825Stheraven    catch (...)
784227825Stheraven    {
785227825Stheraven        __os.__set_badbit_and_consider_rethrow();
786227825Stheraven    }
787227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
788227825Stheraven    return __os;
789227825Stheraven}
790227825Stheraven
791227825Stheraventemplate<class _Traits>
792227825Stheravenbasic_ostream<char, _Traits>&
793227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, char __c)
794227825Stheraven{
795276792Sdim    return _VSTD::__put_character_sequence(__os, &__c, 1);
796227825Stheraven}
797227825Stheraven
798227825Stheraventemplate<class _Traits>
799227825Stheravenbasic_ostream<char, _Traits>&
800227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, signed char __c)
801227825Stheraven{
802276792Sdim    return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
803227825Stheraven}
804227825Stheraven
805227825Stheraventemplate<class _Traits>
806227825Stheravenbasic_ostream<char, _Traits>&
807227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
808227825Stheraven{
809276792Sdim    return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
810227825Stheraven}
811227825Stheraven
812227825Stheraventemplate<class _CharT, class _Traits>
813227825Stheravenbasic_ostream<_CharT, _Traits>&
814227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
815227825Stheraven{
816276792Sdim    return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
817227825Stheraven}
818227825Stheraven
819227825Stheraventemplate<class _CharT, class _Traits>
820227825Stheravenbasic_ostream<_CharT, _Traits>&
821227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
822227825Stheraven{
823227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
824227825Stheraven    try
825227825Stheraven    {
826227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
827227825Stheraven        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
828227825Stheraven        if (__s)
829227825Stheraven        {
830232924Stheraven            typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
831227825Stheraven            size_t __len = char_traits<char>::length(__strn);
832227825Stheraven            const int __bs = 100;
833227825Stheraven            _CharT __wbb[__bs];
834227825Stheraven            _CharT* __wb = __wbb;
835227825Stheraven            unique_ptr<_CharT, void(*)(void*)> __h(0, free);
836227825Stheraven            if (__len > __bs)
837227825Stheraven            {
838227825Stheraven                __wb = (_CharT*)malloc(__len*sizeof(_CharT));
839227825Stheraven                if (__wb == 0)
840227825Stheraven                    __throw_bad_alloc();
841227825Stheraven                __h.reset(__wb);
842227825Stheraven            }
843227825Stheraven            for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
844227825Stheraven                *__p = __os.widen(*__strn);
845232924Stheraven            if (__pad_and_output(_Ip(__os),
846227825Stheraven                                 __wb,
847227825Stheraven                                 (__os.flags() & ios_base::adjustfield) == ios_base::left ?
848227825Stheraven                                     __wb + __len :
849227825Stheraven                                     __wb,
850227825Stheraven                                 __wb + __len,
851227825Stheraven                                 __os,
852227825Stheraven                                 __os.fill()).failed())
853227825Stheraven                __os.setstate(ios_base::badbit | ios_base::failbit);
854227825Stheraven        }
855227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
856227825Stheraven    }
857227825Stheraven    catch (...)
858227825Stheraven    {
859227825Stheraven        __os.__set_badbit_and_consider_rethrow();
860227825Stheraven    }
861227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
862227825Stheraven    return __os;
863227825Stheraven}
864227825Stheraven
865227825Stheraventemplate<class _Traits>
866227825Stheravenbasic_ostream<char, _Traits>&
867227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, const char* __str)
868227825Stheraven{
869276792Sdim    return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
870227825Stheraven}
871227825Stheraven
872227825Stheraventemplate<class _Traits>
873227825Stheravenbasic_ostream<char, _Traits>&
874227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
875227825Stheraven{
876276792Sdim    const char *__s = (const char *) __str;
877276792Sdim    return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
878227825Stheraven}
879227825Stheraven
880227825Stheraventemplate<class _Traits>
881227825Stheravenbasic_ostream<char, _Traits>&
882227825Stheravenoperator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
883227825Stheraven{
884276792Sdim    const char *__s = (const char *) __str;
885276792Sdim    return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
886227825Stheraven}
887227825Stheraven
888227825Stheraventemplate <class _CharT, class _Traits>
889227825Stheravenbasic_ostream<_CharT, _Traits>&
890227825Stheravenbasic_ostream<_CharT, _Traits>::put(char_type __c)
891227825Stheraven{
892227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
893227825Stheraven    try
894227825Stheraven    {
895227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
896227825Stheraven        sentry __s(*this);
897227825Stheraven        if (__s)
898227825Stheraven        {
899232924Stheraven            typedef ostreambuf_iterator<_CharT, _Traits> _Op;
900232924Stheraven            _Op __o(*this);
901227825Stheraven            *__o = __c;
902227825Stheraven            if (__o.failed())
903227825Stheraven                this->setstate(ios_base::badbit);
904227825Stheraven        }
905227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
906227825Stheraven    }
907227825Stheraven    catch (...)
908227825Stheraven    {
909227825Stheraven        this->__set_badbit_and_consider_rethrow();
910227825Stheraven    }
911227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
912227825Stheraven    return *this;
913227825Stheraven}
914227825Stheraven
915227825Stheraventemplate <class _CharT, class _Traits>
916227825Stheravenbasic_ostream<_CharT, _Traits>&
917227825Stheravenbasic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
918227825Stheraven{
919227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
920227825Stheraven    try
921227825Stheraven    {
922227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
923227825Stheraven        sentry __sen(*this);
924227825Stheraven        if (__sen && __n)
925227825Stheraven        {
926246468Stheraven            if (this->rdbuf()->sputn(__s, __n) != __n)
927246468Stheraven                this->setstate(ios_base::badbit);
928227825Stheraven        }
929227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
930227825Stheraven    }
931227825Stheraven    catch (...)
932227825Stheraven    {
933227825Stheraven        this->__set_badbit_and_consider_rethrow();
934227825Stheraven    }
935227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
936227825Stheraven    return *this;
937227825Stheraven}
938227825Stheraven
939227825Stheraventemplate <class _CharT, class _Traits>
940227825Stheravenbasic_ostream<_CharT, _Traits>&
941227825Stheravenbasic_ostream<_CharT, _Traits>::flush()
942227825Stheraven{
943227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
944227825Stheraven    try
945227825Stheraven    {
946227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
947227825Stheraven        if (this->rdbuf())
948227825Stheraven        {
949227825Stheraven            sentry __s(*this);
950227825Stheraven            if (__s)
951227825Stheraven            {
952227825Stheraven                if (this->rdbuf()->pubsync() == -1)
953227825Stheraven                    this->setstate(ios_base::badbit);
954227825Stheraven            }
955227825Stheraven        }
956227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
957227825Stheraven    }
958227825Stheraven    catch (...)
959227825Stheraven    {
960227825Stheraven        this->__set_badbit_and_consider_rethrow();
961227825Stheraven    }
962227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
963227825Stheraven    return *this;
964227825Stheraven}
965227825Stheraven
966227825Stheraventemplate <class _CharT, class _Traits>
967227825Stheraventypename basic_ostream<_CharT, _Traits>::pos_type
968227825Stheravenbasic_ostream<_CharT, _Traits>::tellp()
969227825Stheraven{
970227825Stheraven    if (this->fail())
971227825Stheraven        return pos_type(-1);
972227825Stheraven    return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
973227825Stheraven}
974227825Stheraven
975227825Stheraventemplate <class _CharT, class _Traits>
976227825Stheravenbasic_ostream<_CharT, _Traits>&
977227825Stheravenbasic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
978227825Stheraven{
979261272Sdim    sentry __s(*this);
980288943Sdim    if (!this->fail())
981227825Stheraven    {
982227825Stheraven        if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
983227825Stheraven            this->setstate(ios_base::failbit);
984227825Stheraven    }
985227825Stheraven    return *this;
986227825Stheraven}
987227825Stheraven
988227825Stheraventemplate <class _CharT, class _Traits>
989227825Stheravenbasic_ostream<_CharT, _Traits>&
990227825Stheravenbasic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
991227825Stheraven{
992261272Sdim    sentry __s(*this);
993288943Sdim    if (!this->fail())
994261272Sdim    {
995261272Sdim        if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
996261272Sdim            this->setstate(ios_base::failbit);
997261272Sdim    }
998227825Stheraven    return *this;
999227825Stheraven}
1000227825Stheraven
1001227825Stheraventemplate <class _CharT, class _Traits>
1002227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1003227825Stheravenbasic_ostream<_CharT, _Traits>&
1004227825Stheravenendl(basic_ostream<_CharT, _Traits>& __os)
1005227825Stheraven{
1006227825Stheraven    __os.put(__os.widen('\n'));
1007227825Stheraven    __os.flush();
1008227825Stheraven    return __os;
1009227825Stheraven}
1010227825Stheraven
1011227825Stheraventemplate <class _CharT, class _Traits>
1012227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1013227825Stheravenbasic_ostream<_CharT, _Traits>&
1014227825Stheravenends(basic_ostream<_CharT, _Traits>& __os)
1015227825Stheraven{
1016227825Stheraven    __os.put(_CharT());
1017227825Stheraven    return __os;
1018227825Stheraven}
1019227825Stheraven
1020227825Stheraventemplate <class _CharT, class _Traits>
1021227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1022227825Stheravenbasic_ostream<_CharT, _Traits>&
1023227825Stheravenflush(basic_ostream<_CharT, _Traits>& __os)
1024227825Stheraven{
1025227825Stheraven    __os.flush();
1026227825Stheraven    return __os;
1027227825Stheraven}
1028227825Stheraven
1029321369Sdim#ifndef _LIBCPP_CXX03_LANG
1030227825Stheraven
1031227825Stheraventemplate <class _Stream, class _Tp>
1032227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1033227825Stheraventypename enable_if
1034227825Stheraven<
1035227825Stheraven    !is_lvalue_reference<_Stream>::value &&
1036227825Stheraven    is_base_of<ios_base, _Stream>::value,
1037232924Stheraven    _Stream&&
1038227825Stheraven>::type
1039227825Stheravenoperator<<(_Stream&& __os, const _Tp& __x)
1040227825Stheraven{
1041227825Stheraven    __os << __x;
1042232924Stheraven    return _VSTD::move(__os);
1043227825Stheraven}
1044227825Stheraven
1045321369Sdim#endif  // _LIBCPP_CXX03_LANG
1046227825Stheraven
1047227825Stheraventemplate<class _CharT, class _Traits, class _Allocator>
1048227825Stheravenbasic_ostream<_CharT, _Traits>&
1049227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os,
1050227825Stheraven           const basic_string<_CharT, _Traits, _Allocator>& __str)
1051227825Stheraven{
1052276792Sdim    return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
1053227825Stheraven}
1054227825Stheraven
1055314564Sdimtemplate<class _CharT, class _Traits>
1056314564Sdimbasic_ostream<_CharT, _Traits>&
1057314564Sdimoperator<<(basic_ostream<_CharT, _Traits>& __os,
1058360784Sdim           basic_string_view<_CharT, _Traits> __sv)
1059314564Sdim{
1060314564Sdim    return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
1061314564Sdim}
1062314564Sdim
1063227825Stheraventemplate <class _CharT, class _Traits>
1064227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1065227825Stheravenbasic_ostream<_CharT, _Traits>&
1066227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
1067227825Stheraven{
1068227825Stheraven    return __os << __ec.category().name() << ':' << __ec.value();
1069227825Stheraven}
1070227825Stheraven
1071232924Stheraventemplate<class _CharT, class _Traits, class _Yp>
1072227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1073227825Stheravenbasic_ostream<_CharT, _Traits>&
1074232924Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
1075227825Stheraven{
1076227825Stheraven    return __os << __p.get();
1077227825Stheraven}
1078227825Stheraven
1079327952Sdimtemplate<class _CharT, class _Traits, class _Yp, class _Dp>
1080327952Sdiminline _LIBCPP_INLINE_VISIBILITY
1081327952Sdimtypename enable_if
1082327952Sdim<
1083341825Sdim    is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value,
1084327952Sdim    basic_ostream<_CharT, _Traits>&
1085327952Sdim>::type
1086327952Sdimoperator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
1087327952Sdim{
1088327952Sdim    return __os << __p.get();
1089327952Sdim}
1090327952Sdim
1091227825Stheraventemplate <class _CharT, class _Traits, size_t _Size>
1092227825Stheravenbasic_ostream<_CharT, _Traits>&
1093227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
1094227825Stheraven{
1095227825Stheraven    return __os << __x.template to_string<_CharT, _Traits>
1096227825Stheraven                        (use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
1097227825Stheraven                         use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
1098227825Stheraven}
1099227825Stheraven
1100344779Sdim#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
1101314564Sdim_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
1102314564Sdim_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
1103321369Sdim#endif
1104227825Stheraven
1105227825Stheraven_LIBCPP_END_NAMESPACE_STD
1106227825Stheraven
1107227825Stheraven#endif  // _LIBCPP_OSTREAM
1108