xref: /freebsd/contrib/llvm-project/libcxx/include/ios (revision 9286d46a794f25482880d29864a8901ef6666fae)
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 <__fwd/ios.h>
221#include <__ios/fpos.h>
222#include <__locale>
223#include <__system_error/error_category.h>
224#include <__system_error/error_code.h>
225#include <__system_error/error_condition.h>
226#include <__system_error/system_error.h>
227#include <__utility/swap.h>
228#include <__verbose_abort>
229#include <version>
230
231// standard-mandated includes
232
233// [ios.syn]
234#include <iosfwd>
235
236#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
237#  include <__atomic/atomic.h> // for __xindex_
238#endif
239
240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241#  pragma GCC system_header
242#endif
243
244_LIBCPP_BEGIN_NAMESPACE_STD
245
246typedef ptrdiff_t streamsize;
247
248class _LIBCPP_EXPORTED_FROM_ABI ios_base
249{
250public:
251    class _LIBCPP_EXPORTED_FROM_ABI failure;
252
253    typedef unsigned int fmtflags;
254    static const fmtflags boolalpha   = 0x0001;
255    static const fmtflags dec         = 0x0002;
256    static const fmtflags fixed       = 0x0004;
257    static const fmtflags hex         = 0x0008;
258    static const fmtflags internal    = 0x0010;
259    static const fmtflags left        = 0x0020;
260    static const fmtflags oct         = 0x0040;
261    static const fmtflags right       = 0x0080;
262    static const fmtflags scientific  = 0x0100;
263    static const fmtflags showbase    = 0x0200;
264    static const fmtflags showpoint   = 0x0400;
265    static const fmtflags showpos     = 0x0800;
266    static const fmtflags skipws      = 0x1000;
267    static const fmtflags unitbuf     = 0x2000;
268    static const fmtflags uppercase   = 0x4000;
269    static const fmtflags adjustfield = left | right | internal;
270    static const fmtflags basefield   = dec | oct | hex;
271    static const fmtflags floatfield  = scientific | fixed;
272
273    typedef unsigned int iostate;
274    static const iostate badbit  = 0x1;
275    static const iostate eofbit  = 0x2;
276    static const iostate failbit = 0x4;
277    static const iostate goodbit = 0x0;
278
279    typedef unsigned int openmode;
280    static const openmode app    = 0x01;
281    static const openmode ate    = 0x02;
282    static const openmode binary = 0x04;
283    static const openmode in     = 0x08;
284    static const openmode out    = 0x10;
285    static const openmode trunc  = 0x20;
286
287    enum seekdir {beg, cur, end};
288
289#if _LIBCPP_STD_VER <= 14
290    typedef iostate      io_state;
291    typedef openmode     open_mode;
292    typedef seekdir      seek_dir;
293
294    typedef _VSTD::streamoff streamoff;
295    typedef _VSTD::streampos streampos;
296#endif
297
298    class _LIBCPP_EXPORTED_FROM_ABI Init;
299
300    // 27.5.2.2 fmtflags state:
301    _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
302    _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
303    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
304    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
305    _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);
306
307    _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
308    _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
309    _LIBCPP_INLINE_VISIBILITY streamsize width() const;
310    _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);
311
312    // 27.5.2.3 locales:
313    locale imbue(const locale& __loc);
314    locale getloc() const;
315
316    // 27.5.2.5 storage:
317    static int xalloc();
318    long& iword(int __index);
319    void*& pword(int __index);
320
321    // destructor
322    virtual ~ios_base();
323
324    // 27.5.2.6 callbacks;
325    enum event { erase_event, imbue_event, copyfmt_event };
326    typedef void (*event_callback)(event, ios_base&, int __index);
327    void register_callback(event_callback __fn, int __index);
328
329    ios_base(const ios_base&) = delete;
330    ios_base& operator=(const ios_base&) = delete;
331
332    static bool sync_with_stdio(bool __sync = true);
333
334    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
335    void clear(iostate __state = goodbit);
336    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);
337
338    _LIBCPP_INLINE_VISIBILITY bool good() const;
339    _LIBCPP_INLINE_VISIBILITY bool eof() const;
340    _LIBCPP_INLINE_VISIBILITY bool fail() const;
341    _LIBCPP_INLINE_VISIBILITY bool bad() const;
342
343    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
344    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
345
346    void __set_badbit_and_consider_rethrow();
347    void __set_failbit_and_consider_rethrow();
348
349    _LIBCPP_INLINE_VISIBILITY
350    void __setstate_nothrow(iostate __state)
351    {
352        if (__rdbuf_)
353            __rdstate_ |= __state;
354        else
355            __rdstate_ |= __state | ios_base::badbit;
356    }
357
358protected:
359    _LIBCPP_INLINE_VISIBILITY
360    ios_base() {// purposefully does no initialization
361               }
362
363    void init(void* __sb);
364    _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;}
365
366    _LIBCPP_INLINE_VISIBILITY
367    void rdbuf(void* __sb)
368    {
369        __rdbuf_ = __sb;
370        clear();
371    }
372
373    void __call_callbacks(event);
374    void copyfmt(const ios_base&);
375    void move(ios_base&);
376    void swap(ios_base&) _NOEXCEPT;
377
378    _LIBCPP_INLINE_VISIBILITY
379    void set_rdbuf(void* __sb)
380    {
381        __rdbuf_ = __sb;
382    }
383
384private:
385    // All data members must be scalars
386    fmtflags        __fmtflags_;
387    streamsize      __precision_;
388    streamsize      __width_;
389    iostate         __rdstate_;
390    iostate         __exceptions_;
391    void*           __rdbuf_;
392    void*           __loc_;
393    event_callback* __fn_;
394    int*            __index_;
395    size_t          __event_size_;
396    size_t          __event_cap_;
397// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
398// enabled with clang.
399#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
400    static atomic<int> __xindex_;
401#else
402    static int      __xindex_;
403#endif
404    long*           __iarray_;
405    size_t          __iarray_size_;
406    size_t          __iarray_cap_;
407    void**          __parray_;
408    size_t          __parray_size_;
409    size_t          __parray_cap_;
410};
411
412//enum class io_errc
413_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
414{
415    stream = 1
416};
417_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
418
419template <>
420struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { };
421
422#ifdef _LIBCPP_CXX03_LANG
423template <>
424struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
425#endif
426
427_LIBCPP_EXPORTED_FROM_ABI const 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_EXPORTED_FROM_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_EXPORTED_FROM_ABI 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
850extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>;
851
852#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
853extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>;
854#endif
855
856_LIBCPP_HIDE_FROM_ABI inline
857ios_base&
858boolalpha(ios_base& __str)
859{
860    __str.setf(ios_base::boolalpha);
861    return __str;
862}
863
864_LIBCPP_HIDE_FROM_ABI inline
865ios_base&
866noboolalpha(ios_base& __str)
867{
868    __str.unsetf(ios_base::boolalpha);
869    return __str;
870}
871
872_LIBCPP_HIDE_FROM_ABI inline
873ios_base&
874showbase(ios_base& __str)
875{
876    __str.setf(ios_base::showbase);
877    return __str;
878}
879
880_LIBCPP_HIDE_FROM_ABI inline
881ios_base&
882noshowbase(ios_base& __str)
883{
884    __str.unsetf(ios_base::showbase);
885    return __str;
886}
887
888_LIBCPP_HIDE_FROM_ABI inline
889ios_base&
890showpoint(ios_base& __str)
891{
892    __str.setf(ios_base::showpoint);
893    return __str;
894}
895
896_LIBCPP_HIDE_FROM_ABI inline
897ios_base&
898noshowpoint(ios_base& __str)
899{
900    __str.unsetf(ios_base::showpoint);
901    return __str;
902}
903
904_LIBCPP_HIDE_FROM_ABI inline
905ios_base&
906showpos(ios_base& __str)
907{
908    __str.setf(ios_base::showpos);
909    return __str;
910}
911
912_LIBCPP_HIDE_FROM_ABI inline
913ios_base&
914noshowpos(ios_base& __str)
915{
916    __str.unsetf(ios_base::showpos);
917    return __str;
918}
919
920_LIBCPP_HIDE_FROM_ABI inline
921ios_base&
922skipws(ios_base& __str)
923{
924    __str.setf(ios_base::skipws);
925    return __str;
926}
927
928_LIBCPP_HIDE_FROM_ABI inline
929ios_base&
930noskipws(ios_base& __str)
931{
932    __str.unsetf(ios_base::skipws);
933    return __str;
934}
935
936_LIBCPP_HIDE_FROM_ABI inline
937ios_base&
938uppercase(ios_base& __str)
939{
940    __str.setf(ios_base::uppercase);
941    return __str;
942}
943
944_LIBCPP_HIDE_FROM_ABI inline
945ios_base&
946nouppercase(ios_base& __str)
947{
948    __str.unsetf(ios_base::uppercase);
949    return __str;
950}
951
952_LIBCPP_HIDE_FROM_ABI inline
953ios_base&
954unitbuf(ios_base& __str)
955{
956    __str.setf(ios_base::unitbuf);
957    return __str;
958}
959
960_LIBCPP_HIDE_FROM_ABI inline
961ios_base&
962nounitbuf(ios_base& __str)
963{
964    __str.unsetf(ios_base::unitbuf);
965    return __str;
966}
967
968_LIBCPP_HIDE_FROM_ABI inline
969ios_base&
970internal(ios_base& __str)
971{
972    __str.setf(ios_base::internal, ios_base::adjustfield);
973    return __str;
974}
975
976_LIBCPP_HIDE_FROM_ABI inline
977ios_base&
978left(ios_base& __str)
979{
980    __str.setf(ios_base::left, ios_base::adjustfield);
981    return __str;
982}
983
984_LIBCPP_HIDE_FROM_ABI inline
985ios_base&
986right(ios_base& __str)
987{
988    __str.setf(ios_base::right, ios_base::adjustfield);
989    return __str;
990}
991
992_LIBCPP_HIDE_FROM_ABI inline
993ios_base&
994dec(ios_base& __str)
995{
996    __str.setf(ios_base::dec, ios_base::basefield);
997    return __str;
998}
999
1000_LIBCPP_HIDE_FROM_ABI inline
1001ios_base&
1002hex(ios_base& __str)
1003{
1004    __str.setf(ios_base::hex, ios_base::basefield);
1005    return __str;
1006}
1007
1008_LIBCPP_HIDE_FROM_ABI inline
1009ios_base&
1010oct(ios_base& __str)
1011{
1012    __str.setf(ios_base::oct, ios_base::basefield);
1013    return __str;
1014}
1015
1016_LIBCPP_HIDE_FROM_ABI inline
1017ios_base&
1018fixed(ios_base& __str)
1019{
1020    __str.setf(ios_base::fixed, ios_base::floatfield);
1021    return __str;
1022}
1023
1024_LIBCPP_HIDE_FROM_ABI inline
1025ios_base&
1026scientific(ios_base& __str)
1027{
1028    __str.setf(ios_base::scientific, ios_base::floatfield);
1029    return __str;
1030}
1031
1032_LIBCPP_HIDE_FROM_ABI inline
1033ios_base&
1034hexfloat(ios_base& __str)
1035{
1036    __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
1037    return __str;
1038}
1039
1040_LIBCPP_HIDE_FROM_ABI inline
1041ios_base&
1042defaultfloat(ios_base& __str)
1043{
1044    __str.unsetf(ios_base::floatfield);
1045    return __str;
1046}
1047
1048_LIBCPP_END_NAMESPACE_STD
1049
1050#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1051#  include <atomic>
1052#  include <concepts>
1053#  include <cstddef>
1054#  include <cstdlib>
1055#  include <cstring>
1056#  include <initializer_list>
1057#  include <limits>
1058#  include <new>
1059#  include <stdexcept>
1060#  include <system_error>
1061#  include <type_traits>
1062#  include <typeinfo>
1063#endif
1064
1065#endif // _LIBCPP_IOS
1066