• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_IOS
11#define _LIBCPP_IOS
12
13/*
14    ios synopsis
15
16#include <iosfwd>
17
18namespace std
19{
20
21typedef OFF_T streamoff;
22typedef SZ_T streamsize;
23template <class stateT> class fpos;
24
25class ios_base
26{
27public:
28    class failure;
29
30    typedef T1 fmtflags;
31    static constexpr fmtflags boolalpha;
32    static constexpr fmtflags dec;
33    static constexpr fmtflags fixed;
34    static constexpr fmtflags hex;
35    static constexpr fmtflags internal;
36    static constexpr fmtflags left;
37    static constexpr fmtflags oct;
38    static constexpr fmtflags right;
39    static constexpr fmtflags scientific;
40    static constexpr fmtflags showbase;
41    static constexpr fmtflags showpoint;
42    static constexpr fmtflags showpos;
43    static constexpr fmtflags skipws;
44    static constexpr fmtflags unitbuf;
45    static constexpr fmtflags uppercase;
46    static constexpr fmtflags adjustfield;
47    static constexpr fmtflags basefield;
48    static constexpr fmtflags floatfield;
49
50    typedef T2 iostate;
51    static constexpr iostate badbit;
52    static constexpr iostate eofbit;
53    static constexpr iostate failbit;
54    static constexpr iostate goodbit;
55
56    typedef T3 openmode;
57    static constexpr openmode app;
58    static constexpr openmode ate;
59    static constexpr openmode binary;
60    static constexpr openmode in;
61    static constexpr openmode out;
62    static constexpr openmode trunc;
63
64    typedef T4 seekdir;
65    static constexpr seekdir beg;
66    static constexpr seekdir cur;
67    static constexpr seekdir end;
68
69    class Init;
70
71    // 27.5.2.2 fmtflags state:
72    fmtflags flags() const;
73    fmtflags flags(fmtflags fmtfl);
74    fmtflags setf(fmtflags fmtfl);
75    fmtflags setf(fmtflags fmtfl, fmtflags mask);
76    void unsetf(fmtflags mask);
77
78    streamsize precision() const;
79    streamsize precision(streamsize prec);
80    streamsize width() const;
81    streamsize width(streamsize wide);
82
83    // 27.5.2.3 locales:
84    locale imbue(const locale& loc);
85    locale getloc() const;
86
87    // 27.5.2.5 storage:
88    static int xalloc();
89    long& iword(int index);
90    void*& pword(int index);
91
92    // destructor
93    virtual ~ios_base();
94
95    // 27.5.2.6 callbacks;
96    enum event { erase_event, imbue_event, copyfmt_event };
97    typedef void (*event_callback)(event, ios_base&, int index);
98    void register_callback(event_callback fn, int index);
99
100    ios_base(const ios_base&) = delete;
101    ios_base& operator=(const ios_base&) = delete;
102
103    static bool sync_with_stdio(bool sync = true);
104
105protected:
106    ios_base();
107};
108
109template <class charT, class traits = char_traits<charT> >
110class basic_ios
111    : public ios_base
112{
113public:
114    // types:
115    typedef charT char_type;
116    typedef typename traits::int_type int_type;  // removed in C++17
117    typedef typename traits::pos_type pos_type;  // removed in C++17
118    typedef typename traits::off_type off_type;  // removed in C++17
119    typedef traits traits_type;
120
121    operator unspecified-bool-type() const;
122    bool operator!() const;
123    iostate rdstate() const;
124    void clear(iostate state = goodbit);
125    void setstate(iostate state);
126    bool good() const;
127    bool eof() const;
128    bool fail() const;
129    bool bad() const;
130
131    iostate exceptions() const;
132    void exceptions(iostate except);
133
134    // 27.5.4.1 Constructor/destructor:
135    explicit basic_ios(basic_streambuf<charT,traits>* sb);
136    virtual ~basic_ios();
137
138    // 27.5.4.2 Members:
139    basic_ostream<charT,traits>* tie() const;
140    basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
141
142    basic_streambuf<charT,traits>* rdbuf() const;
143    basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
144
145    basic_ios& copyfmt(const basic_ios& rhs);
146
147    char_type fill() const;
148    char_type fill(char_type ch);
149
150    locale imbue(const locale& loc);
151
152    char narrow(char_type c, char dfault) const;
153    char_type widen(char c) const;
154
155    basic_ios(const basic_ios& ) = delete;
156    basic_ios& operator=(const basic_ios&) = delete;
157
158protected:
159    basic_ios();
160    void init(basic_streambuf<charT,traits>* sb);
161    void move(basic_ios& rhs);
162    void swap(basic_ios& rhs) noexcept;
163    void set_rdbuf(basic_streambuf<charT, traits>* sb);
164};
165
166// 27.5.5, manipulators:
167ios_base& boolalpha (ios_base& str);
168ios_base& noboolalpha(ios_base& str);
169ios_base& showbase (ios_base& str);
170ios_base& noshowbase (ios_base& str);
171ios_base& showpoint (ios_base& str);
172ios_base& noshowpoint(ios_base& str);
173ios_base& showpos (ios_base& str);
174ios_base& noshowpos (ios_base& str);
175ios_base& skipws (ios_base& str);
176ios_base& noskipws (ios_base& str);
177ios_base& uppercase (ios_base& str);
178ios_base& nouppercase(ios_base& str);
179ios_base& unitbuf (ios_base& str);
180ios_base& nounitbuf (ios_base& str);
181
182// 27.5.5.2 adjustfield:
183ios_base& internal (ios_base& str);
184ios_base& left (ios_base& str);
185ios_base& right (ios_base& str);
186
187// 27.5.5.3 basefield:
188ios_base& dec (ios_base& str);
189ios_base& hex (ios_base& str);
190ios_base& oct (ios_base& str);
191
192// 27.5.5.4 floatfield:
193ios_base& fixed (ios_base& str);
194ios_base& scientific (ios_base& str);
195ios_base& hexfloat (ios_base& str);
196ios_base& defaultfloat(ios_base& str);
197
198// 27.5.5.5 error reporting:
199enum class io_errc
200{
201    stream = 1
202};
203
204concept_map ErrorCodeEnum<io_errc> { };
205error_code make_error_code(io_errc e) noexcept;
206error_condition make_error_condition(io_errc e) noexcept;
207storage-class-specifier const error_category& iostream_category() noexcept;
208
209}  // std
210
211*/
212
213#include <__config>
214
215#if defined(_LIBCPP_HAS_NO_LOCALIZATION)
216#   error "The iostreams library is not supported since libc++ has been configured without support for localization."
217#endif
218
219#include <__assert> // all public C++ headers provide the assertion handler
220#include <__ios/fpos.h>
221#include <__locale>
222#include <__system_error/error_category.h>
223#include <__system_error/error_code.h>
224#include <__system_error/error_condition.h>
225#include <__system_error/system_error.h>
226#include <__utility/swap.h>
227#include <__verbose_abort>
228#include <version>
229
230// standard-mandated includes
231
232// [ios.syn]
233#include <iosfwd>
234
235#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
236#  include <__atomic/atomic.h> // for __xindex_
237#endif
238
239#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
240#  pragma GCC system_header
241#endif
242
243_LIBCPP_BEGIN_NAMESPACE_STD
244
245typedef ptrdiff_t streamsize;
246
247class _LIBCPP_TYPE_VIS ios_base
248{
249public:
250    class _LIBCPP_EXCEPTION_ABI failure;
251
252    typedef unsigned int fmtflags;
253    static const fmtflags boolalpha   = 0x0001;
254    static const fmtflags dec         = 0x0002;
255    static const fmtflags fixed       = 0x0004;
256    static const fmtflags hex         = 0x0008;
257    static const fmtflags internal    = 0x0010;
258    static const fmtflags left        = 0x0020;
259    static const fmtflags oct         = 0x0040;
260    static const fmtflags right       = 0x0080;
261    static const fmtflags scientific  = 0x0100;
262    static const fmtflags showbase    = 0x0200;
263    static const fmtflags showpoint   = 0x0400;
264    static const fmtflags showpos     = 0x0800;
265    static const fmtflags skipws      = 0x1000;
266    static const fmtflags unitbuf     = 0x2000;
267    static const fmtflags uppercase   = 0x4000;
268    static const fmtflags adjustfield = left | right | internal;
269    static const fmtflags basefield   = dec | oct | hex;
270    static const fmtflags floatfield  = scientific | fixed;
271
272    typedef unsigned int iostate;
273    static const iostate badbit  = 0x1;
274    static const iostate eofbit  = 0x2;
275    static const iostate failbit = 0x4;
276    static const iostate goodbit = 0x0;
277
278    typedef unsigned int openmode;
279    static const openmode app    = 0x01;
280    static const openmode ate    = 0x02;
281    static const openmode binary = 0x04;
282    static const openmode in     = 0x08;
283    static const openmode out    = 0x10;
284    static const openmode trunc  = 0x20;
285
286    enum seekdir {beg, cur, end};
287
288#if _LIBCPP_STD_VER <= 14
289    typedef iostate      io_state;
290    typedef openmode     open_mode;
291    typedef seekdir      seek_dir;
292
293    typedef _VSTD::streamoff streamoff;
294    typedef _VSTD::streampos streampos;
295#endif
296
297    class _LIBCPP_TYPE_VIS Init;
298
299    // 27.5.2.2 fmtflags state:
300    _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
301    _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
302    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
303    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
304    _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);
305
306    _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
307    _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
308    _LIBCPP_INLINE_VISIBILITY streamsize width() const;
309    _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);
310
311    // 27.5.2.3 locales:
312    locale imbue(const locale& __loc);
313    locale getloc() const;
314
315    // 27.5.2.5 storage:
316    static int xalloc();
317    long& iword(int __index);
318    void*& pword(int __index);
319
320    // destructor
321    virtual ~ios_base();
322
323    // 27.5.2.6 callbacks;
324    enum event { erase_event, imbue_event, copyfmt_event };
325    typedef void (*event_callback)(event, ios_base&, int __index);
326    void register_callback(event_callback __fn, int __index);
327
328    ios_base(const ios_base&) = delete;
329    ios_base& operator=(const ios_base&) = delete;
330
331    static bool sync_with_stdio(bool __sync = true);
332
333    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
334    void clear(iostate __state = goodbit);
335    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);
336
337    _LIBCPP_INLINE_VISIBILITY bool good() const;
338    _LIBCPP_INLINE_VISIBILITY bool eof() const;
339    _LIBCPP_INLINE_VISIBILITY bool fail() const;
340    _LIBCPP_INLINE_VISIBILITY bool bad() const;
341
342    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
343    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
344
345    void __set_badbit_and_consider_rethrow();
346    void __set_failbit_and_consider_rethrow();
347
348    _LIBCPP_INLINE_VISIBILITY
349    void __setstate_nothrow(iostate __state)
350    {
351        if (__rdbuf_)
352            __rdstate_ |= __state;
353        else
354            __rdstate_ |= __state | ios_base::badbit;
355    }
356
357protected:
358    _LIBCPP_INLINE_VISIBILITY
359    ios_base() {// purposefully does no initialization
360               }
361
362    void init(void* __sb);
363    _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;}
364
365    _LIBCPP_INLINE_VISIBILITY
366    void rdbuf(void* __sb)
367    {
368        __rdbuf_ = __sb;
369        clear();
370    }
371
372    void __call_callbacks(event);
373    void copyfmt(const ios_base&);
374    void move(ios_base&);
375    void swap(ios_base&) _NOEXCEPT;
376
377    _LIBCPP_INLINE_VISIBILITY
378    void set_rdbuf(void* __sb)
379    {
380        __rdbuf_ = __sb;
381    }
382
383private:
384    // All data members must be scalars
385    fmtflags        __fmtflags_;
386    streamsize      __precision_;
387    streamsize      __width_;
388    iostate         __rdstate_;
389    iostate         __exceptions_;
390    void*           __rdbuf_;
391    void*           __loc_;
392    event_callback* __fn_;
393    int*            __index_;
394    size_t          __event_size_;
395    size_t          __event_cap_;
396// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
397// enabled with clang.
398#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
399    static atomic<int> __xindex_;
400#else
401    static int      __xindex_;
402#endif
403    long*           __iarray_;
404    size_t          __iarray_size_;
405    size_t          __iarray_cap_;
406    void**          __parray_;
407    size_t          __parray_size_;
408    size_t          __parray_cap_;
409};
410
411//enum class io_errc
412_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
413{
414    stream = 1
415};
416_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
417
418template <>
419struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { };
420
421#ifdef _LIBCPP_CXX03_LANG
422template <>
423struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
424#endif
425
426_LIBCPP_FUNC_VIS
427const error_category& iostream_category() _NOEXCEPT;
428
429inline _LIBCPP_INLINE_VISIBILITY
430error_code
431make_error_code(io_errc __e) _NOEXCEPT
432{
433    return error_code(static_cast<int>(__e), iostream_category());
434}
435
436inline _LIBCPP_INLINE_VISIBILITY
437error_condition
438make_error_condition(io_errc __e) _NOEXCEPT
439{
440    return error_condition(static_cast<int>(__e), iostream_category());
441}
442
443class _LIBCPP_EXCEPTION_ABI ios_base::failure
444    : public system_error
445{
446public:
447    explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
448    explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
449    _LIBCPP_HIDE_FROM_ABI failure(const failure&) _NOEXCEPT = default;
450    ~failure() _NOEXCEPT override;
451};
452
453_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
454void __throw_failure(char const* __msg) {
455#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
456    throw ios_base::failure(__msg);
457#else
458    _LIBCPP_VERBOSE_ABORT("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"", __msg);
459#endif
460}
461
462class _LIBCPP_TYPE_VIS ios_base::Init
463{
464public:
465    Init();
466    ~Init();
467};
468
469// fmtflags
470
471inline _LIBCPP_INLINE_VISIBILITY
472ios_base::fmtflags
473ios_base::flags() const
474{
475    return __fmtflags_;
476}
477
478inline _LIBCPP_INLINE_VISIBILITY
479ios_base::fmtflags
480ios_base::flags(fmtflags __fmtfl)
481{
482    fmtflags __r = __fmtflags_;
483    __fmtflags_ = __fmtfl;
484    return __r;
485}
486
487inline _LIBCPP_INLINE_VISIBILITY
488ios_base::fmtflags
489ios_base::setf(fmtflags __fmtfl)
490{
491    fmtflags __r = __fmtflags_;
492    __fmtflags_ |= __fmtfl;
493    return __r;
494}
495
496inline _LIBCPP_INLINE_VISIBILITY
497void
498ios_base::unsetf(fmtflags __mask)
499{
500    __fmtflags_ &= ~__mask;
501}
502
503inline _LIBCPP_INLINE_VISIBILITY
504ios_base::fmtflags
505ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
506{
507    fmtflags __r = __fmtflags_;
508    unsetf(__mask);
509    __fmtflags_ |= __fmtfl & __mask;
510    return __r;
511}
512
513// precision
514
515inline _LIBCPP_INLINE_VISIBILITY
516streamsize
517ios_base::precision() const
518{
519    return __precision_;
520}
521
522inline _LIBCPP_INLINE_VISIBILITY
523streamsize
524ios_base::precision(streamsize __prec)
525{
526    streamsize __r = __precision_;
527    __precision_ = __prec;
528    return __r;
529}
530
531// width
532
533inline _LIBCPP_INLINE_VISIBILITY
534streamsize
535ios_base::width() const
536{
537    return __width_;
538}
539
540inline _LIBCPP_INLINE_VISIBILITY
541streamsize
542ios_base::width(streamsize __wide)
543{
544    streamsize __r = __width_;
545    __width_ = __wide;
546    return __r;
547}
548
549// iostate
550
551inline _LIBCPP_INLINE_VISIBILITY
552ios_base::iostate
553ios_base::rdstate() const
554{
555    return __rdstate_;
556}
557
558inline _LIBCPP_INLINE_VISIBILITY
559void
560ios_base::setstate(iostate __state)
561{
562    clear(__rdstate_ | __state);
563}
564
565inline _LIBCPP_INLINE_VISIBILITY
566bool
567ios_base::good() const
568{
569    return __rdstate_ == 0;
570}
571
572inline _LIBCPP_INLINE_VISIBILITY
573bool
574ios_base::eof() const
575{
576    return (__rdstate_ & eofbit) != 0;
577}
578
579inline _LIBCPP_INLINE_VISIBILITY
580bool
581ios_base::fail() const
582{
583    return (__rdstate_ & (failbit | badbit)) != 0;
584}
585
586inline _LIBCPP_INLINE_VISIBILITY
587bool
588ios_base::bad() const
589{
590    return (__rdstate_ & badbit) != 0;
591}
592
593inline _LIBCPP_INLINE_VISIBILITY
594ios_base::iostate
595ios_base::exceptions() const
596{
597    return __exceptions_;
598}
599
600inline _LIBCPP_INLINE_VISIBILITY
601void
602ios_base::exceptions(iostate __iostate)
603{
604    __exceptions_ = __iostate;
605    clear(__rdstate_);
606}
607
608template <class _CharT, class _Traits>
609class _LIBCPP_TEMPLATE_VIS basic_ios
610    : public ios_base
611{
612public:
613    // types:
614    typedef _CharT char_type;
615    typedef _Traits traits_type;
616
617    typedef typename traits_type::int_type int_type;
618    typedef typename traits_type::pos_type pos_type;
619    typedef typename traits_type::off_type off_type;
620
621    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
622                  "traits_type::char_type must be the same type as CharT");
623
624#ifdef _LIBCPP_CXX03_LANG
625    // Preserve the ability to compare with literal 0,
626    // and implicitly convert to bool, but not implicitly convert to int.
627    _LIBCPP_INLINE_VISIBILITY
628    operator void*() const {return fail() ? nullptr : (void*)this;}
629#else
630    _LIBCPP_INLINE_VISIBILITY
631    explicit operator bool() const {return !fail();}
632#endif
633
634    _LIBCPP_INLINE_VISIBILITY bool operator!() const    {return  fail();}
635    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const   {return ios_base::rdstate();}
636    _LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);}
637    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);}
638    _LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();}
639    _LIBCPP_INLINE_VISIBILITY bool eof() const  {return ios_base::eof();}
640    _LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();}
641    _LIBCPP_INLINE_VISIBILITY bool bad() const  {return ios_base::bad();}
642
643    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();}
644    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);}
645
646    // 27.5.4.1 Constructor/destructor:
647    _LIBCPP_INLINE_VISIBILITY
648    explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
649    ~basic_ios() override;
650
651    // 27.5.4.2 Members:
652    _LIBCPP_INLINE_VISIBILITY
653    basic_ostream<char_type, traits_type>* tie() const;
654    _LIBCPP_INLINE_VISIBILITY
655    basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
656
657    _LIBCPP_INLINE_VISIBILITY
658    basic_streambuf<char_type, traits_type>* rdbuf() const;
659    _LIBCPP_INLINE_VISIBILITY
660    basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
661
662    basic_ios& copyfmt(const basic_ios& __rhs);
663
664    _LIBCPP_INLINE_VISIBILITY
665    char_type fill() const;
666    _LIBCPP_INLINE_VISIBILITY
667    char_type fill(char_type __ch);
668
669    _LIBCPP_INLINE_VISIBILITY
670    locale imbue(const locale& __loc);
671
672    _LIBCPP_INLINE_VISIBILITY
673    char narrow(char_type __c, char __dfault) const;
674    _LIBCPP_INLINE_VISIBILITY
675    char_type widen(char __c) const;
676
677protected:
678    _LIBCPP_INLINE_VISIBILITY
679    basic_ios() {// purposefully does no initialization
680                }
681    _LIBCPP_INLINE_VISIBILITY
682    void init(basic_streambuf<char_type, traits_type>* __sb);
683
684    _LIBCPP_INLINE_VISIBILITY
685    void move(basic_ios& __rhs);
686    _LIBCPP_INLINE_VISIBILITY
687    void move(basic_ios&& __rhs) {move(__rhs);}
688    _LIBCPP_INLINE_VISIBILITY
689    void swap(basic_ios& __rhs) _NOEXCEPT;
690    _LIBCPP_INLINE_VISIBILITY
691    void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
692private:
693    basic_ostream<char_type, traits_type>* __tie_;
694    mutable int_type __fill_;
695};
696
697template <class _CharT, class _Traits>
698inline _LIBCPP_INLINE_VISIBILITY
699basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
700{
701    init(__sb);
702}
703
704template <class _CharT, class _Traits>
705basic_ios<_CharT, _Traits>::~basic_ios()
706{
707}
708
709template <class _CharT, class _Traits>
710inline _LIBCPP_INLINE_VISIBILITY
711void
712basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
713{
714    ios_base::init(__sb);
715    __tie_ = nullptr;
716    __fill_ = traits_type::eof();
717}
718
719template <class _CharT, class _Traits>
720inline _LIBCPP_INLINE_VISIBILITY
721basic_ostream<_CharT, _Traits>*
722basic_ios<_CharT, _Traits>::tie() const
723{
724    return __tie_;
725}
726
727template <class _CharT, class _Traits>
728inline _LIBCPP_INLINE_VISIBILITY
729basic_ostream<_CharT, _Traits>*
730basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
731{
732    basic_ostream<char_type, traits_type>* __r = __tie_;
733    __tie_ = __tiestr;
734    return __r;
735}
736
737template <class _CharT, class _Traits>
738inline _LIBCPP_INLINE_VISIBILITY
739basic_streambuf<_CharT, _Traits>*
740basic_ios<_CharT, _Traits>::rdbuf() const
741{
742    return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
743}
744
745template <class _CharT, class _Traits>
746inline _LIBCPP_INLINE_VISIBILITY
747basic_streambuf<_CharT, _Traits>*
748basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
749{
750    basic_streambuf<char_type, traits_type>* __r = rdbuf();
751    ios_base::rdbuf(__sb);
752    return __r;
753}
754
755template <class _CharT, class _Traits>
756inline _LIBCPP_INLINE_VISIBILITY
757locale
758basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
759{
760    locale __r = getloc();
761    ios_base::imbue(__loc);
762    if (rdbuf())
763        rdbuf()->pubimbue(__loc);
764    return __r;
765}
766
767template <class _CharT, class _Traits>
768inline _LIBCPP_INLINE_VISIBILITY
769char
770basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
771{
772    return std::use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
773}
774
775template <class _CharT, class _Traits>
776inline _LIBCPP_INLINE_VISIBILITY
777_CharT
778basic_ios<_CharT, _Traits>::widen(char __c) const
779{
780    return std::use_facet<ctype<char_type> >(getloc()).widen(__c);
781}
782
783template <class _CharT, class _Traits>
784inline _LIBCPP_INLINE_VISIBILITY
785_CharT
786basic_ios<_CharT, _Traits>::fill() const
787{
788    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
789        __fill_ = widen(' ');
790    return __fill_;
791}
792
793template <class _CharT, class _Traits>
794inline _LIBCPP_INLINE_VISIBILITY
795_CharT
796basic_ios<_CharT, _Traits>::fill(char_type __ch)
797{
798    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
799        __fill_ = widen(' ');
800    char_type __r = __fill_;
801    __fill_ = __ch;
802    return __r;
803}
804
805template <class _CharT, class _Traits>
806basic_ios<_CharT, _Traits>&
807basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
808{
809    if (this != &__rhs)
810    {
811        __call_callbacks(erase_event);
812        ios_base::copyfmt(__rhs);
813        __tie_ = __rhs.__tie_;
814        __fill_ = __rhs.__fill_;
815        __call_callbacks(copyfmt_event);
816        exceptions(__rhs.exceptions());
817    }
818    return *this;
819}
820
821template <class _CharT, class _Traits>
822inline _LIBCPP_INLINE_VISIBILITY
823void
824basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
825{
826    ios_base::move(__rhs);
827    __tie_ = __rhs.__tie_;
828    __rhs.__tie_ = nullptr;
829    __fill_ = __rhs.__fill_;
830}
831
832template <class _CharT, class _Traits>
833inline _LIBCPP_INLINE_VISIBILITY
834void
835basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
836{
837    ios_base::swap(__rhs);
838    _VSTD::swap(__tie_, __rhs.__tie_);
839    _VSTD::swap(__fill_, __rhs.__fill_);
840}
841
842template <class _CharT, class _Traits>
843inline _LIBCPP_INLINE_VISIBILITY
844void
845basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
846{
847    ios_base::set_rdbuf(__sb);
848}
849
850_LIBCPP_HIDE_FROM_ABI inline
851ios_base&
852boolalpha(ios_base& __str)
853{
854    __str.setf(ios_base::boolalpha);
855    return __str;
856}
857
858_LIBCPP_HIDE_FROM_ABI inline
859ios_base&
860noboolalpha(ios_base& __str)
861{
862    __str.unsetf(ios_base::boolalpha);
863    return __str;
864}
865
866_LIBCPP_HIDE_FROM_ABI inline
867ios_base&
868showbase(ios_base& __str)
869{
870    __str.setf(ios_base::showbase);
871    return __str;
872}
873
874_LIBCPP_HIDE_FROM_ABI inline
875ios_base&
876noshowbase(ios_base& __str)
877{
878    __str.unsetf(ios_base::showbase);
879    return __str;
880}
881
882_LIBCPP_HIDE_FROM_ABI inline
883ios_base&
884showpoint(ios_base& __str)
885{
886    __str.setf(ios_base::showpoint);
887    return __str;
888}
889
890_LIBCPP_HIDE_FROM_ABI inline
891ios_base&
892noshowpoint(ios_base& __str)
893{
894    __str.unsetf(ios_base::showpoint);
895    return __str;
896}
897
898_LIBCPP_HIDE_FROM_ABI inline
899ios_base&
900showpos(ios_base& __str)
901{
902    __str.setf(ios_base::showpos);
903    return __str;
904}
905
906_LIBCPP_HIDE_FROM_ABI inline
907ios_base&
908noshowpos(ios_base& __str)
909{
910    __str.unsetf(ios_base::showpos);
911    return __str;
912}
913
914_LIBCPP_HIDE_FROM_ABI inline
915ios_base&
916skipws(ios_base& __str)
917{
918    __str.setf(ios_base::skipws);
919    return __str;
920}
921
922_LIBCPP_HIDE_FROM_ABI inline
923ios_base&
924noskipws(ios_base& __str)
925{
926    __str.unsetf(ios_base::skipws);
927    return __str;
928}
929
930_LIBCPP_HIDE_FROM_ABI inline
931ios_base&
932uppercase(ios_base& __str)
933{
934    __str.setf(ios_base::uppercase);
935    return __str;
936}
937
938_LIBCPP_HIDE_FROM_ABI inline
939ios_base&
940nouppercase(ios_base& __str)
941{
942    __str.unsetf(ios_base::uppercase);
943    return __str;
944}
945
946_LIBCPP_HIDE_FROM_ABI inline
947ios_base&
948unitbuf(ios_base& __str)
949{
950    __str.setf(ios_base::unitbuf);
951    return __str;
952}
953
954_LIBCPP_HIDE_FROM_ABI inline
955ios_base&
956nounitbuf(ios_base& __str)
957{
958    __str.unsetf(ios_base::unitbuf);
959    return __str;
960}
961
962_LIBCPP_HIDE_FROM_ABI inline
963ios_base&
964internal(ios_base& __str)
965{
966    __str.setf(ios_base::internal, ios_base::adjustfield);
967    return __str;
968}
969
970_LIBCPP_HIDE_FROM_ABI inline
971ios_base&
972left(ios_base& __str)
973{
974    __str.setf(ios_base::left, ios_base::adjustfield);
975    return __str;
976}
977
978_LIBCPP_HIDE_FROM_ABI inline
979ios_base&
980right(ios_base& __str)
981{
982    __str.setf(ios_base::right, ios_base::adjustfield);
983    return __str;
984}
985
986_LIBCPP_HIDE_FROM_ABI inline
987ios_base&
988dec(ios_base& __str)
989{
990    __str.setf(ios_base::dec, ios_base::basefield);
991    return __str;
992}
993
994_LIBCPP_HIDE_FROM_ABI inline
995ios_base&
996hex(ios_base& __str)
997{
998    __str.setf(ios_base::hex, ios_base::basefield);
999    return __str;
1000}
1001
1002_LIBCPP_HIDE_FROM_ABI inline
1003ios_base&
1004oct(ios_base& __str)
1005{
1006    __str.setf(ios_base::oct, ios_base::basefield);
1007    return __str;
1008}
1009
1010_LIBCPP_HIDE_FROM_ABI inline
1011ios_base&
1012fixed(ios_base& __str)
1013{
1014    __str.setf(ios_base::fixed, ios_base::floatfield);
1015    return __str;
1016}
1017
1018_LIBCPP_HIDE_FROM_ABI inline
1019ios_base&
1020scientific(ios_base& __str)
1021{
1022    __str.setf(ios_base::scientific, ios_base::floatfield);
1023    return __str;
1024}
1025
1026_LIBCPP_HIDE_FROM_ABI inline
1027ios_base&
1028hexfloat(ios_base& __str)
1029{
1030    __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
1031    return __str;
1032}
1033
1034_LIBCPP_HIDE_FROM_ABI inline
1035ios_base&
1036defaultfloat(ios_base& __str)
1037{
1038    __str.unsetf(ios_base::floatfield);
1039    return __str;
1040}
1041
1042_LIBCPP_END_NAMESPACE_STD
1043
1044#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1045#  include <atomic>
1046#  include <concepts>
1047#  include <cstddef>
1048#  include <cstdlib>
1049#  include <cstring>
1050#  include <initializer_list>
1051#  include <limits>
1052#  include <new>
1053#  include <stdexcept>
1054#  include <system_error>
1055#  include <type_traits>
1056#  include <typeinfo>
1057#endif
1058
1059#endif // _LIBCPP_IOS
1060