xref: /freebsd/contrib/llvm-project/libcxx/include/ios (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
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 <__utility/swap.h>
223#include <system_error>
224#include <version>
225
226// standard-mandated includes
227
228// [ios.syn]
229#include <iosfwd>
230
231#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
232#include <atomic>     // for __xindex_
233#endif
234
235#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
236#  pragma GCC system_header
237#endif
238
239_LIBCPP_BEGIN_NAMESPACE_STD
240
241typedef ptrdiff_t streamsize;
242
243class _LIBCPP_TYPE_VIS ios_base
244{
245public:
246    class _LIBCPP_EXCEPTION_ABI failure;
247
248    typedef unsigned int fmtflags;
249    static const fmtflags boolalpha   = 0x0001;
250    static const fmtflags dec         = 0x0002;
251    static const fmtflags fixed       = 0x0004;
252    static const fmtflags hex         = 0x0008;
253    static const fmtflags internal    = 0x0010;
254    static const fmtflags left        = 0x0020;
255    static const fmtflags oct         = 0x0040;
256    static const fmtflags right       = 0x0080;
257    static const fmtflags scientific  = 0x0100;
258    static const fmtflags showbase    = 0x0200;
259    static const fmtflags showpoint   = 0x0400;
260    static const fmtflags showpos     = 0x0800;
261    static const fmtflags skipws      = 0x1000;
262    static const fmtflags unitbuf     = 0x2000;
263    static const fmtflags uppercase   = 0x4000;
264    static const fmtflags adjustfield = left | right | internal;
265    static const fmtflags basefield   = dec | oct | hex;
266    static const fmtflags floatfield  = scientific | fixed;
267
268    typedef unsigned int iostate;
269    static const iostate badbit  = 0x1;
270    static const iostate eofbit  = 0x2;
271    static const iostate failbit = 0x4;
272    static const iostate goodbit = 0x0;
273
274    typedef unsigned int openmode;
275    static const openmode app    = 0x01;
276    static const openmode ate    = 0x02;
277    static const openmode binary = 0x04;
278    static const openmode in     = 0x08;
279    static const openmode out    = 0x10;
280    static const openmode trunc  = 0x20;
281
282    enum seekdir {beg, cur, end};
283
284#if _LIBCPP_STD_VER <= 14
285    typedef iostate      io_state;
286    typedef openmode     open_mode;
287    typedef seekdir      seek_dir;
288
289    typedef _VSTD::streamoff streamoff;
290    typedef _VSTD::streampos streampos;
291#endif
292
293    class _LIBCPP_TYPE_VIS Init;
294
295    // 27.5.2.2 fmtflags state:
296    _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
297    _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
298    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
299    _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
300    _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);
301
302    _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
303    _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
304    _LIBCPP_INLINE_VISIBILITY streamsize width() const;
305    _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);
306
307    // 27.5.2.3 locales:
308    locale imbue(const locale& __loc);
309    locale getloc() const;
310
311    // 27.5.2.5 storage:
312    static int xalloc();
313    long& iword(int __index);
314    void*& pword(int __index);
315
316    // destructor
317    virtual ~ios_base();
318
319    // 27.5.2.6 callbacks;
320    enum event { erase_event, imbue_event, copyfmt_event };
321    typedef void (*event_callback)(event, ios_base&, int __index);
322    void register_callback(event_callback __fn, int __index);
323
324    ios_base(const ios_base&) = delete;
325    ios_base& operator=(const ios_base&) = delete;
326
327    static bool sync_with_stdio(bool __sync = true);
328
329    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
330    void clear(iostate __state = goodbit);
331    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);
332
333    _LIBCPP_INLINE_VISIBILITY bool good() const;
334    _LIBCPP_INLINE_VISIBILITY bool eof() const;
335    _LIBCPP_INLINE_VISIBILITY bool fail() const;
336    _LIBCPP_INLINE_VISIBILITY bool bad() const;
337
338    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
339    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
340
341    void __set_badbit_and_consider_rethrow();
342    void __set_failbit_and_consider_rethrow();
343
344    _LIBCPP_INLINE_VISIBILITY
345    void __setstate_nothrow(iostate __state)
346    {
347        if (__rdbuf_)
348            __rdstate_ |= __state;
349        else
350            __rdstate_ |= __state | ios_base::badbit;
351    }
352
353protected:
354    _LIBCPP_INLINE_VISIBILITY
355    ios_base() {// purposefully does no initialization
356               }
357
358    void init(void* __sb);
359    _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;}
360
361    _LIBCPP_INLINE_VISIBILITY
362    void rdbuf(void* __sb)
363    {
364        __rdbuf_ = __sb;
365        clear();
366    }
367
368    void __call_callbacks(event);
369    void copyfmt(const ios_base&);
370    void move(ios_base&);
371    void swap(ios_base&) _NOEXCEPT;
372
373    _LIBCPP_INLINE_VISIBILITY
374    void set_rdbuf(void* __sb)
375    {
376        __rdbuf_ = __sb;
377    }
378
379private:
380    // All data members must be scalars
381    fmtflags        __fmtflags_;
382    streamsize      __precision_;
383    streamsize      __width_;
384    iostate         __rdstate_;
385    iostate         __exceptions_;
386    void*           __rdbuf_;
387    void*           __loc_;
388    event_callback* __fn_;
389    int*            __index_;
390    size_t          __event_size_;
391    size_t          __event_cap_;
392// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
393// enabled with clang.
394#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
395    static atomic<int> __xindex_;
396#else
397    static int      __xindex_;
398#endif
399    long*           __iarray_;
400    size_t          __iarray_size_;
401    size_t          __iarray_cap_;
402    void**          __parray_;
403    size_t          __parray_size_;
404    size_t          __parray_cap_;
405};
406
407//enum class io_errc
408_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
409{
410    stream = 1
411};
412_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
413
414template <>
415struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { };
416
417#ifdef _LIBCPP_CXX03_LANG
418template <>
419struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
420#endif
421
422_LIBCPP_FUNC_VIS
423const error_category& iostream_category() _NOEXCEPT;
424
425inline _LIBCPP_INLINE_VISIBILITY
426error_code
427make_error_code(io_errc __e) _NOEXCEPT
428{
429    return error_code(static_cast<int>(__e), iostream_category());
430}
431
432inline _LIBCPP_INLINE_VISIBILITY
433error_condition
434make_error_condition(io_errc __e) _NOEXCEPT
435{
436    return error_condition(static_cast<int>(__e), iostream_category());
437}
438
439class _LIBCPP_EXCEPTION_ABI ios_base::failure
440    : public system_error
441{
442public:
443    explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
444    explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
445    failure(const failure&) _NOEXCEPT = default;
446    ~failure() _NOEXCEPT override;
447};
448
449_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
450void __throw_failure(char const* __msg) {
451#ifndef _LIBCPP_NO_EXCEPTIONS
452    throw ios_base::failure(__msg);
453#else
454    ((void)__msg);
455    _VSTD::abort();
456#endif
457}
458
459class _LIBCPP_TYPE_VIS ios_base::Init
460{
461public:
462    Init();
463    ~Init();
464};
465
466// fmtflags
467
468inline _LIBCPP_INLINE_VISIBILITY
469ios_base::fmtflags
470ios_base::flags() const
471{
472    return __fmtflags_;
473}
474
475inline _LIBCPP_INLINE_VISIBILITY
476ios_base::fmtflags
477ios_base::flags(fmtflags __fmtfl)
478{
479    fmtflags __r = __fmtflags_;
480    __fmtflags_ = __fmtfl;
481    return __r;
482}
483
484inline _LIBCPP_INLINE_VISIBILITY
485ios_base::fmtflags
486ios_base::setf(fmtflags __fmtfl)
487{
488    fmtflags __r = __fmtflags_;
489    __fmtflags_ |= __fmtfl;
490    return __r;
491}
492
493inline _LIBCPP_INLINE_VISIBILITY
494void
495ios_base::unsetf(fmtflags __mask)
496{
497    __fmtflags_ &= ~__mask;
498}
499
500inline _LIBCPP_INLINE_VISIBILITY
501ios_base::fmtflags
502ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
503{
504    fmtflags __r = __fmtflags_;
505    unsetf(__mask);
506    __fmtflags_ |= __fmtfl & __mask;
507    return __r;
508}
509
510// precision
511
512inline _LIBCPP_INLINE_VISIBILITY
513streamsize
514ios_base::precision() const
515{
516    return __precision_;
517}
518
519inline _LIBCPP_INLINE_VISIBILITY
520streamsize
521ios_base::precision(streamsize __prec)
522{
523    streamsize __r = __precision_;
524    __precision_ = __prec;
525    return __r;
526}
527
528// width
529
530inline _LIBCPP_INLINE_VISIBILITY
531streamsize
532ios_base::width() const
533{
534    return __width_;
535}
536
537inline _LIBCPP_INLINE_VISIBILITY
538streamsize
539ios_base::width(streamsize __wide)
540{
541    streamsize __r = __width_;
542    __width_ = __wide;
543    return __r;
544}
545
546// iostate
547
548inline _LIBCPP_INLINE_VISIBILITY
549ios_base::iostate
550ios_base::rdstate() const
551{
552    return __rdstate_;
553}
554
555inline _LIBCPP_INLINE_VISIBILITY
556void
557ios_base::setstate(iostate __state)
558{
559    clear(__rdstate_ | __state);
560}
561
562inline _LIBCPP_INLINE_VISIBILITY
563bool
564ios_base::good() const
565{
566    return __rdstate_ == 0;
567}
568
569inline _LIBCPP_INLINE_VISIBILITY
570bool
571ios_base::eof() const
572{
573    return (__rdstate_ & eofbit) != 0;
574}
575
576inline _LIBCPP_INLINE_VISIBILITY
577bool
578ios_base::fail() const
579{
580    return (__rdstate_ & (failbit | badbit)) != 0;
581}
582
583inline _LIBCPP_INLINE_VISIBILITY
584bool
585ios_base::bad() const
586{
587    return (__rdstate_ & badbit) != 0;
588}
589
590inline _LIBCPP_INLINE_VISIBILITY
591ios_base::iostate
592ios_base::exceptions() const
593{
594    return __exceptions_;
595}
596
597inline _LIBCPP_INLINE_VISIBILITY
598void
599ios_base::exceptions(iostate __iostate)
600{
601    __exceptions_ = __iostate;
602    clear(__rdstate_);
603}
604
605template <class _CharT, class _Traits>
606class _LIBCPP_TEMPLATE_VIS basic_ios
607    : public ios_base
608{
609public:
610    // types:
611    typedef _CharT char_type;
612    typedef _Traits traits_type;
613
614    typedef typename traits_type::int_type int_type;
615    typedef typename traits_type::pos_type pos_type;
616    typedef typename traits_type::off_type off_type;
617
618    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
619                  "traits_type::char_type must be the same type as CharT");
620
621#ifdef _LIBCPP_CXX03_LANG
622    // Preserve the ability to compare with literal 0,
623    // and implicitly convert to bool, but not implicitly convert to int.
624    _LIBCPP_INLINE_VISIBILITY
625    operator void*() const {return fail() ? nullptr : (void*)this;}
626#else
627    _LIBCPP_INLINE_VISIBILITY
628    explicit operator bool() const {return !fail();}
629#endif
630
631    _LIBCPP_INLINE_VISIBILITY bool operator!() const    {return  fail();}
632    _LIBCPP_INLINE_VISIBILITY iostate rdstate() const   {return ios_base::rdstate();}
633    _LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);}
634    _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);}
635    _LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();}
636    _LIBCPP_INLINE_VISIBILITY bool eof() const  {return ios_base::eof();}
637    _LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();}
638    _LIBCPP_INLINE_VISIBILITY bool bad() const  {return ios_base::bad();}
639
640    _LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();}
641    _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);}
642
643    // 27.5.4.1 Constructor/destructor:
644    _LIBCPP_INLINE_VISIBILITY
645    explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
646    ~basic_ios() override;
647
648    // 27.5.4.2 Members:
649    _LIBCPP_INLINE_VISIBILITY
650    basic_ostream<char_type, traits_type>* tie() const;
651    _LIBCPP_INLINE_VISIBILITY
652    basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
653
654    _LIBCPP_INLINE_VISIBILITY
655    basic_streambuf<char_type, traits_type>* rdbuf() const;
656    _LIBCPP_INLINE_VISIBILITY
657    basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
658
659    basic_ios& copyfmt(const basic_ios& __rhs);
660
661    _LIBCPP_INLINE_VISIBILITY
662    char_type fill() const;
663    _LIBCPP_INLINE_VISIBILITY
664    char_type fill(char_type __ch);
665
666    _LIBCPP_INLINE_VISIBILITY
667    locale imbue(const locale& __loc);
668
669    _LIBCPP_INLINE_VISIBILITY
670    char narrow(char_type __c, char __dfault) const;
671    _LIBCPP_INLINE_VISIBILITY
672    char_type widen(char __c) const;
673
674protected:
675    _LIBCPP_INLINE_VISIBILITY
676    basic_ios() {// purposefully does no initialization
677                }
678    _LIBCPP_INLINE_VISIBILITY
679    void init(basic_streambuf<char_type, traits_type>* __sb);
680
681    _LIBCPP_INLINE_VISIBILITY
682    void move(basic_ios& __rhs);
683    _LIBCPP_INLINE_VISIBILITY
684    void move(basic_ios&& __rhs) {move(__rhs);}
685    _LIBCPP_INLINE_VISIBILITY
686    void swap(basic_ios& __rhs) _NOEXCEPT;
687    _LIBCPP_INLINE_VISIBILITY
688    void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
689private:
690    basic_ostream<char_type, traits_type>* __tie_;
691    mutable int_type __fill_;
692};
693
694template <class _CharT, class _Traits>
695inline _LIBCPP_INLINE_VISIBILITY
696basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
697{
698    init(__sb);
699}
700
701template <class _CharT, class _Traits>
702basic_ios<_CharT, _Traits>::~basic_ios()
703{
704}
705
706template <class _CharT, class _Traits>
707inline _LIBCPP_INLINE_VISIBILITY
708void
709basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
710{
711    ios_base::init(__sb);
712    __tie_ = nullptr;
713    __fill_ = traits_type::eof();
714}
715
716template <class _CharT, class _Traits>
717inline _LIBCPP_INLINE_VISIBILITY
718basic_ostream<_CharT, _Traits>*
719basic_ios<_CharT, _Traits>::tie() const
720{
721    return __tie_;
722}
723
724template <class _CharT, class _Traits>
725inline _LIBCPP_INLINE_VISIBILITY
726basic_ostream<_CharT, _Traits>*
727basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
728{
729    basic_ostream<char_type, traits_type>* __r = __tie_;
730    __tie_ = __tiestr;
731    return __r;
732}
733
734template <class _CharT, class _Traits>
735inline _LIBCPP_INLINE_VISIBILITY
736basic_streambuf<_CharT, _Traits>*
737basic_ios<_CharT, _Traits>::rdbuf() const
738{
739    return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
740}
741
742template <class _CharT, class _Traits>
743inline _LIBCPP_INLINE_VISIBILITY
744basic_streambuf<_CharT, _Traits>*
745basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
746{
747    basic_streambuf<char_type, traits_type>* __r = rdbuf();
748    ios_base::rdbuf(__sb);
749    return __r;
750}
751
752template <class _CharT, class _Traits>
753inline _LIBCPP_INLINE_VISIBILITY
754locale
755basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
756{
757    locale __r = getloc();
758    ios_base::imbue(__loc);
759    if (rdbuf())
760        rdbuf()->pubimbue(__loc);
761    return __r;
762}
763
764template <class _CharT, class _Traits>
765inline _LIBCPP_INLINE_VISIBILITY
766char
767basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
768{
769    return std::use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
770}
771
772template <class _CharT, class _Traits>
773inline _LIBCPP_INLINE_VISIBILITY
774_CharT
775basic_ios<_CharT, _Traits>::widen(char __c) const
776{
777    return std::use_facet<ctype<char_type> >(getloc()).widen(__c);
778}
779
780template <class _CharT, class _Traits>
781inline _LIBCPP_INLINE_VISIBILITY
782_CharT
783basic_ios<_CharT, _Traits>::fill() const
784{
785    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
786        __fill_ = widen(' ');
787    return __fill_;
788}
789
790template <class _CharT, class _Traits>
791inline _LIBCPP_INLINE_VISIBILITY
792_CharT
793basic_ios<_CharT, _Traits>::fill(char_type __ch)
794{
795    if (traits_type::eq_int_type(traits_type::eof(), __fill_))
796        __fill_ = widen(' ');
797    char_type __r = __fill_;
798    __fill_ = __ch;
799    return __r;
800}
801
802template <class _CharT, class _Traits>
803basic_ios<_CharT, _Traits>&
804basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
805{
806    if (this != &__rhs)
807    {
808        __call_callbacks(erase_event);
809        ios_base::copyfmt(__rhs);
810        __tie_ = __rhs.__tie_;
811        __fill_ = __rhs.__fill_;
812        __call_callbacks(copyfmt_event);
813        exceptions(__rhs.exceptions());
814    }
815    return *this;
816}
817
818template <class _CharT, class _Traits>
819inline _LIBCPP_INLINE_VISIBILITY
820void
821basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
822{
823    ios_base::move(__rhs);
824    __tie_ = __rhs.__tie_;
825    __rhs.__tie_ = nullptr;
826    __fill_ = __rhs.__fill_;
827}
828
829template <class _CharT, class _Traits>
830inline _LIBCPP_INLINE_VISIBILITY
831void
832basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
833{
834    ios_base::swap(__rhs);
835    _VSTD::swap(__tie_, __rhs.__tie_);
836    _VSTD::swap(__fill_, __rhs.__fill_);
837}
838
839template <class _CharT, class _Traits>
840inline _LIBCPP_INLINE_VISIBILITY
841void
842basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
843{
844    ios_base::set_rdbuf(__sb);
845}
846
847_LIBCPP_HIDE_FROM_ABI inline
848ios_base&
849boolalpha(ios_base& __str)
850{
851    __str.setf(ios_base::boolalpha);
852    return __str;
853}
854
855_LIBCPP_HIDE_FROM_ABI inline
856ios_base&
857noboolalpha(ios_base& __str)
858{
859    __str.unsetf(ios_base::boolalpha);
860    return __str;
861}
862
863_LIBCPP_HIDE_FROM_ABI inline
864ios_base&
865showbase(ios_base& __str)
866{
867    __str.setf(ios_base::showbase);
868    return __str;
869}
870
871_LIBCPP_HIDE_FROM_ABI inline
872ios_base&
873noshowbase(ios_base& __str)
874{
875    __str.unsetf(ios_base::showbase);
876    return __str;
877}
878
879_LIBCPP_HIDE_FROM_ABI inline
880ios_base&
881showpoint(ios_base& __str)
882{
883    __str.setf(ios_base::showpoint);
884    return __str;
885}
886
887_LIBCPP_HIDE_FROM_ABI inline
888ios_base&
889noshowpoint(ios_base& __str)
890{
891    __str.unsetf(ios_base::showpoint);
892    return __str;
893}
894
895_LIBCPP_HIDE_FROM_ABI inline
896ios_base&
897showpos(ios_base& __str)
898{
899    __str.setf(ios_base::showpos);
900    return __str;
901}
902
903_LIBCPP_HIDE_FROM_ABI inline
904ios_base&
905noshowpos(ios_base& __str)
906{
907    __str.unsetf(ios_base::showpos);
908    return __str;
909}
910
911_LIBCPP_HIDE_FROM_ABI inline
912ios_base&
913skipws(ios_base& __str)
914{
915    __str.setf(ios_base::skipws);
916    return __str;
917}
918
919_LIBCPP_HIDE_FROM_ABI inline
920ios_base&
921noskipws(ios_base& __str)
922{
923    __str.unsetf(ios_base::skipws);
924    return __str;
925}
926
927_LIBCPP_HIDE_FROM_ABI inline
928ios_base&
929uppercase(ios_base& __str)
930{
931    __str.setf(ios_base::uppercase);
932    return __str;
933}
934
935_LIBCPP_HIDE_FROM_ABI inline
936ios_base&
937nouppercase(ios_base& __str)
938{
939    __str.unsetf(ios_base::uppercase);
940    return __str;
941}
942
943_LIBCPP_HIDE_FROM_ABI inline
944ios_base&
945unitbuf(ios_base& __str)
946{
947    __str.setf(ios_base::unitbuf);
948    return __str;
949}
950
951_LIBCPP_HIDE_FROM_ABI inline
952ios_base&
953nounitbuf(ios_base& __str)
954{
955    __str.unsetf(ios_base::unitbuf);
956    return __str;
957}
958
959_LIBCPP_HIDE_FROM_ABI inline
960ios_base&
961internal(ios_base& __str)
962{
963    __str.setf(ios_base::internal, ios_base::adjustfield);
964    return __str;
965}
966
967_LIBCPP_HIDE_FROM_ABI inline
968ios_base&
969left(ios_base& __str)
970{
971    __str.setf(ios_base::left, ios_base::adjustfield);
972    return __str;
973}
974
975_LIBCPP_HIDE_FROM_ABI inline
976ios_base&
977right(ios_base& __str)
978{
979    __str.setf(ios_base::right, ios_base::adjustfield);
980    return __str;
981}
982
983_LIBCPP_HIDE_FROM_ABI inline
984ios_base&
985dec(ios_base& __str)
986{
987    __str.setf(ios_base::dec, ios_base::basefield);
988    return __str;
989}
990
991_LIBCPP_HIDE_FROM_ABI inline
992ios_base&
993hex(ios_base& __str)
994{
995    __str.setf(ios_base::hex, ios_base::basefield);
996    return __str;
997}
998
999_LIBCPP_HIDE_FROM_ABI inline
1000ios_base&
1001oct(ios_base& __str)
1002{
1003    __str.setf(ios_base::oct, ios_base::basefield);
1004    return __str;
1005}
1006
1007_LIBCPP_HIDE_FROM_ABI inline
1008ios_base&
1009fixed(ios_base& __str)
1010{
1011    __str.setf(ios_base::fixed, ios_base::floatfield);
1012    return __str;
1013}
1014
1015_LIBCPP_HIDE_FROM_ABI inline
1016ios_base&
1017scientific(ios_base& __str)
1018{
1019    __str.setf(ios_base::scientific, ios_base::floatfield);
1020    return __str;
1021}
1022
1023_LIBCPP_HIDE_FROM_ABI inline
1024ios_base&
1025hexfloat(ios_base& __str)
1026{
1027    __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
1028    return __str;
1029}
1030
1031_LIBCPP_HIDE_FROM_ABI inline
1032ios_base&
1033defaultfloat(ios_base& __str)
1034{
1035    __str.unsetf(ios_base::floatfield);
1036    return __str;
1037}
1038
1039_LIBCPP_END_NAMESPACE_STD
1040
1041#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1042#  include <concepts>
1043#  include <cstddef>
1044#  include <cstdlib>
1045#  include <cstring>
1046#  include <initializer_list>
1047#  include <limits>
1048#  include <new>
1049#  include <stdexcept>
1050#  include <type_traits>
1051#  include <typeinfo>
1052#endif
1053
1054#endif // _LIBCPP_IOS
1055