• 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 noreplace; // since C++23
62    static constexpr openmode out;
63    static constexpr openmode trunc;
64
65    typedef T4 seekdir;
66    static constexpr seekdir beg;
67    static constexpr seekdir cur;
68    static constexpr seekdir end;
69
70    class Init;
71
72    // 27.5.2.2 fmtflags state:
73    fmtflags flags() const;
74    fmtflags flags(fmtflags fmtfl);
75    fmtflags setf(fmtflags fmtfl);
76    fmtflags setf(fmtflags fmtfl, fmtflags mask);
77    void unsetf(fmtflags mask);
78
79    streamsize precision() const;
80    streamsize precision(streamsize prec);
81    streamsize width() const;
82    streamsize width(streamsize wide);
83
84    // 27.5.2.3 locales:
85    locale imbue(const locale& loc);
86    locale getloc() const;
87
88    // 27.5.2.5 storage:
89    static int xalloc();
90    long& iword(int index);
91    void*& pword(int index);
92
93    // destructor
94    virtual ~ios_base();
95
96    // 27.5.2.6 callbacks;
97    enum event { erase_event, imbue_event, copyfmt_event };
98    typedef void (*event_callback)(event, ios_base&, int index);
99    void register_callback(event_callback fn, int index);
100
101    ios_base(const ios_base&) = delete;
102    ios_base& operator=(const ios_base&) = delete;
103
104    static bool sync_with_stdio(bool sync = true);
105
106protected:
107    ios_base();
108};
109
110template <class charT, class traits = char_traits<charT> >
111class basic_ios
112    : public ios_base
113{
114public:
115    // types:
116    typedef charT char_type;
117    typedef typename traits::int_type int_type;  // removed in C++17
118    typedef typename traits::pos_type pos_type;  // removed in C++17
119    typedef typename traits::off_type off_type;  // removed in C++17
120    typedef traits traits_type;
121
122    operator unspecified-bool-type() const;
123    bool operator!() const;
124    iostate rdstate() const;
125    void clear(iostate state = goodbit);
126    void setstate(iostate state);
127    bool good() const;
128    bool eof() const;
129    bool fail() const;
130    bool bad() const;
131
132    iostate exceptions() const;
133    void exceptions(iostate except);
134
135    // 27.5.4.1 Constructor/destructor:
136    explicit basic_ios(basic_streambuf<charT,traits>* sb);
137    virtual ~basic_ios();
138
139    // 27.5.4.2 Members:
140    basic_ostream<charT,traits>* tie() const;
141    basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
142
143    basic_streambuf<charT,traits>* rdbuf() const;
144    basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
145
146    basic_ios& copyfmt(const basic_ios& rhs);
147
148    char_type fill() const;
149    char_type fill(char_type ch);
150
151    locale imbue(const locale& loc);
152
153    char narrow(char_type c, char dfault) const;
154    char_type widen(char c) const;
155
156    basic_ios(const basic_ios& ) = delete;
157    basic_ios& operator=(const basic_ios&) = delete;
158
159protected:
160    basic_ios();
161    void init(basic_streambuf<charT,traits>* sb);
162    void move(basic_ios& rhs);
163    void swap(basic_ios& rhs) noexcept;
164    void set_rdbuf(basic_streambuf<charT, traits>* sb);
165};
166
167// 27.5.5, manipulators:
168ios_base& boolalpha (ios_base& str);
169ios_base& noboolalpha(ios_base& str);
170ios_base& showbase (ios_base& str);
171ios_base& noshowbase (ios_base& str);
172ios_base& showpoint (ios_base& str);
173ios_base& noshowpoint(ios_base& str);
174ios_base& showpos (ios_base& str);
175ios_base& noshowpos (ios_base& str);
176ios_base& skipws (ios_base& str);
177ios_base& noskipws (ios_base& str);
178ios_base& uppercase (ios_base& str);
179ios_base& nouppercase(ios_base& str);
180ios_base& unitbuf (ios_base& str);
181ios_base& nounitbuf (ios_base& str);
182
183// 27.5.5.2 adjustfield:
184ios_base& internal (ios_base& str);
185ios_base& left (ios_base& str);
186ios_base& right (ios_base& str);
187
188// 27.5.5.3 basefield:
189ios_base& dec (ios_base& str);
190ios_base& hex (ios_base& str);
191ios_base& oct (ios_base& str);
192
193// 27.5.5.4 floatfield:
194ios_base& fixed (ios_base& str);
195ios_base& scientific (ios_base& str);
196ios_base& hexfloat (ios_base& str);
197ios_base& defaultfloat(ios_base& str);
198
199// 27.5.5.5 error reporting:
200enum class io_errc
201{
202    stream = 1
203};
204
205concept_map ErrorCodeEnum<io_errc> { };
206error_code make_error_code(io_errc e) noexcept;
207error_condition make_error_condition(io_errc e) noexcept;
208storage-class-specifier const error_category& iostream_category() noexcept;
209
210}  // std
211
212*/
213
214#include <__config>
215
216#if _LIBCPP_HAS_LOCALIZATION
217
218#  include <__fwd/ios.h>
219#  include <__ios/fpos.h>
220#  include <__locale>
221#  include <__memory/addressof.h>
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 _LIBCPP_HAS_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_PUSH_MACROS
244#  include <__undef_macros>
245
246_LIBCPP_BEGIN_NAMESPACE_STD
247
248typedef ptrdiff_t streamsize;
249
250class _LIBCPP_EXPORTED_FROM_ABI ios_base {
251public:
252  class _LIBCPP_EXPORTED_FROM_ABI failure;
253
254  typedef unsigned int fmtflags;
255  static const fmtflags boolalpha   = 0x0001;
256  static const fmtflags dec         = 0x0002;
257  static const fmtflags fixed       = 0x0004;
258  static const fmtflags hex         = 0x0008;
259  static const fmtflags internal    = 0x0010;
260  static const fmtflags left        = 0x0020;
261  static const fmtflags oct         = 0x0040;
262  static const fmtflags right       = 0x0080;
263  static const fmtflags scientific  = 0x0100;
264  static const fmtflags showbase    = 0x0200;
265  static const fmtflags showpoint   = 0x0400;
266  static const fmtflags showpos     = 0x0800;
267  static const fmtflags skipws      = 0x1000;
268  static const fmtflags unitbuf     = 0x2000;
269  static const fmtflags uppercase   = 0x4000;
270  static const fmtflags adjustfield = left | right | internal;
271  static const fmtflags basefield   = dec | oct | hex;
272  static const fmtflags floatfield  = scientific | fixed;
273
274  typedef unsigned int iostate;
275  static const iostate badbit  = 0x1;
276  static const iostate eofbit  = 0x2;
277  static const iostate failbit = 0x4;
278  static const iostate goodbit = 0x0;
279
280  typedef unsigned int openmode;
281  static const openmode app    = 0x01;
282  static const openmode ate    = 0x02;
283  static const openmode binary = 0x04;
284  static const openmode in     = 0x08;
285  static const openmode out    = 0x10;
286  static const openmode trunc  = 0x20;
287#  if _LIBCPP_STD_VER >= 23
288  static const openmode noreplace = 0x40;
289#  endif
290
291  enum seekdir { beg, cur, end };
292
293#  if _LIBCPP_STD_VER <= 14
294  typedef iostate io_state;
295  typedef openmode open_mode;
296  typedef seekdir seek_dir;
297
298  typedef std::streamoff streamoff;
299  typedef std::streampos streampos;
300#  endif
301
302  class _LIBCPP_EXPORTED_FROM_ABI Init;
303
304  // 27.5.2.2 fmtflags state:
305  _LIBCPP_HIDE_FROM_ABI fmtflags flags() const;
306  _LIBCPP_HIDE_FROM_ABI fmtflags flags(fmtflags __fmtfl);
307  _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl);
308  _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
309  _LIBCPP_HIDE_FROM_ABI void unsetf(fmtflags __mask);
310
311  _LIBCPP_HIDE_FROM_ABI streamsize precision() const;
312  _LIBCPP_HIDE_FROM_ABI streamsize precision(streamsize __prec);
313  _LIBCPP_HIDE_FROM_ABI streamsize width() const;
314  _LIBCPP_HIDE_FROM_ABI streamsize width(streamsize __wide);
315
316  // 27.5.2.3 locales:
317  locale imbue(const locale& __loc);
318  locale getloc() const;
319
320  // 27.5.2.5 storage:
321  static int xalloc();
322  long& iword(int __index);
323  void*& pword(int __index);
324
325  // destructor
326  virtual ~ios_base();
327
328  // 27.5.2.6 callbacks;
329  enum event { erase_event, imbue_event, copyfmt_event };
330  typedef void (*event_callback)(event, ios_base&, int __index);
331  void register_callback(event_callback __fn, int __index);
332
333  ios_base(const ios_base&)            = delete;
334  ios_base& operator=(const ios_base&) = delete;
335
336  static bool sync_with_stdio(bool __sync = true);
337
338  _LIBCPP_HIDE_FROM_ABI iostate rdstate() const;
339  void clear(iostate __state = goodbit);
340  _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state);
341
342  _LIBCPP_HIDE_FROM_ABI bool good() const;
343  _LIBCPP_HIDE_FROM_ABI bool eof() const;
344  _LIBCPP_HIDE_FROM_ABI bool fail() const;
345  _LIBCPP_HIDE_FROM_ABI bool bad() const;
346
347  _LIBCPP_HIDE_FROM_ABI iostate exceptions() const;
348  _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate);
349
350  void __set_badbit_and_consider_rethrow();
351  void __set_failbit_and_consider_rethrow();
352
353  _LIBCPP_HIDE_FROM_ABI void __setstate_nothrow(iostate __state) {
354    if (__rdbuf_)
355      __rdstate_ |= __state;
356    else
357      __rdstate_ |= __state | ios_base::badbit;
358  }
359
360protected:
361  _LIBCPP_HIDE_FROM_ABI ios_base() : __loc_(nullptr) {
362    // Purposefully does no initialization
363    //
364    // Except for the locale, this is a sentinel to avoid destroying
365    // an uninitialized object. See
366    // test/libcxx/input.output/iostreams.base/ios.base/ios.base.cons/dtor.uninitialized.pass.cpp
367    // for the details.
368  }
369
370  void init(void* __sb);
371  _LIBCPP_HIDE_FROM_ABI void* rdbuf() const { return __rdbuf_; }
372
373  _LIBCPP_HIDE_FROM_ABI void rdbuf(void* __sb) {
374    __rdbuf_ = __sb;
375    clear();
376  }
377
378  void __call_callbacks(event);
379  void copyfmt(const ios_base&);
380  void move(ios_base&);
381  void swap(ios_base&) _NOEXCEPT;
382
383  _LIBCPP_HIDE_FROM_ABI void set_rdbuf(void* __sb) { __rdbuf_ = __sb; }
384
385private:
386  // All data members must be scalars
387  fmtflags __fmtflags_;
388  streamsize __precision_;
389  streamsize __width_;
390  iostate __rdstate_;
391  iostate __exceptions_;
392  void* __rdbuf_;
393  void* __loc_;
394  event_callback* __fn_;
395  int* __index_;
396  size_t __event_size_;
397  size_t __event_cap_;
398// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
399// enabled with clang.
400#  if _LIBCPP_HAS_C_ATOMIC_IMP && _LIBCPP_HAS_THREADS
401  static atomic<int> __xindex_;
402#  else
403  static int __xindex_;
404#  endif
405  long* __iarray_;
406  size_t __iarray_size_;
407  size_t __iarray_cap_;
408  void** __parray_;
409  size_t __parray_size_;
410  size_t __parray_cap_;
411};
412
413// enum class io_errc
414_LIBCPP_DECLARE_STRONG_ENUM(io_errc){stream = 1};
415_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
416
417template <>
418struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type {};
419
420#  ifdef _LIBCPP_CXX03_LANG
421template <>
422struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type {};
423#  endif
424
425_LIBCPP_EXPORTED_FROM_ABI const error_category& iostream_category() _NOEXCEPT;
426
427inline _LIBCPP_HIDE_FROM_ABI error_code make_error_code(io_errc __e) _NOEXCEPT {
428  return error_code(static_cast<int>(__e), iostream_category());
429}
430
431inline _LIBCPP_HIDE_FROM_ABI error_condition make_error_condition(io_errc __e) _NOEXCEPT {
432  return error_condition(static_cast<int>(__e), iostream_category());
433}
434
435class _LIBCPP_EXPORTED_FROM_ABI ios_base::failure : public system_error {
436public:
437  explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
438  explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
439  _LIBCPP_HIDE_FROM_ABI failure(const failure&) _NOEXCEPT = default;
440  ~failure() _NOEXCEPT override;
441};
442
443[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_failure(char const* __msg) {
444#  if _LIBCPP_HAS_EXCEPTIONS
445  throw ios_base::failure(__msg);
446#  else
447  _LIBCPP_VERBOSE_ABORT("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"", __msg);
448#  endif
449}
450
451class _LIBCPP_EXPORTED_FROM_ABI ios_base::Init {
452public:
453  Init();
454  ~Init();
455};
456
457// fmtflags
458
459inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::flags() const { return __fmtflags_; }
460
461inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::flags(fmtflags __fmtfl) {
462  fmtflags __r = __fmtflags_;
463  __fmtflags_  = __fmtfl;
464  return __r;
465}
466
467inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::setf(fmtflags __fmtfl) {
468  fmtflags __r = __fmtflags_;
469  __fmtflags_ |= __fmtfl;
470  return __r;
471}
472
473inline _LIBCPP_HIDE_FROM_ABI void ios_base::unsetf(fmtflags __mask) { __fmtflags_ &= ~__mask; }
474
475inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::setf(fmtflags __fmtfl, fmtflags __mask) {
476  fmtflags __r = __fmtflags_;
477  unsetf(__mask);
478  __fmtflags_ |= __fmtfl & __mask;
479  return __r;
480}
481
482// precision
483
484inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::precision() const { return __precision_; }
485
486inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::precision(streamsize __prec) {
487  streamsize __r = __precision_;
488  __precision_   = __prec;
489  return __r;
490}
491
492// width
493
494inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::width() const { return __width_; }
495
496inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::width(streamsize __wide) {
497  streamsize __r = __width_;
498  __width_       = __wide;
499  return __r;
500}
501
502// iostate
503
504inline _LIBCPP_HIDE_FROM_ABI ios_base::iostate ios_base::rdstate() const { return __rdstate_; }
505
506inline _LIBCPP_HIDE_FROM_ABI void ios_base::setstate(iostate __state) { clear(__rdstate_ | __state); }
507
508inline _LIBCPP_HIDE_FROM_ABI bool ios_base::good() const { return __rdstate_ == 0; }
509
510inline _LIBCPP_HIDE_FROM_ABI bool ios_base::eof() const { return (__rdstate_ & eofbit) != 0; }
511
512inline _LIBCPP_HIDE_FROM_ABI bool ios_base::fail() const { return (__rdstate_ & (failbit | badbit)) != 0; }
513
514inline _LIBCPP_HIDE_FROM_ABI bool ios_base::bad() const { return (__rdstate_ & badbit) != 0; }
515
516inline _LIBCPP_HIDE_FROM_ABI ios_base::iostate ios_base::exceptions() const { return __exceptions_; }
517
518inline _LIBCPP_HIDE_FROM_ABI void ios_base::exceptions(iostate __iostate) {
519  __exceptions_ = __iostate;
520  clear(__rdstate_);
521}
522
523template <class _Traits>
524// Attribute 'packed' is used to keep the layout compatible with the previous
525// definition of the '__fill_' and '_set_' pair in basic_ios on AIX & z/OS.
526struct _LIBCPP_PACKED _FillHelper {
527  _LIBCPP_HIDE_FROM_ABI void __init() {
528    __set_      = false;
529    __fill_val_ = _Traits::eof();
530  }
531  _LIBCPP_HIDE_FROM_ABI _FillHelper& operator=(typename _Traits::int_type __x) {
532    __set_      = true;
533    __fill_val_ = __x;
534    return *this;
535  }
536  _LIBCPP_HIDE_FROM_ABI bool __is_set() const { return __set_; }
537  _LIBCPP_HIDE_FROM_ABI typename _Traits::int_type __get() const { return __fill_val_; }
538
539private:
540  typename _Traits::int_type __fill_val_;
541  bool __set_;
542};
543
544template <class _Traits>
545struct _LIBCPP_PACKED _SentinelValueFill {
546  _LIBCPP_HIDE_FROM_ABI void __init() { __fill_val_ = _Traits::eof(); }
547  _LIBCPP_HIDE_FROM_ABI _SentinelValueFill& operator=(typename _Traits::int_type __x) {
548    __fill_val_ = __x;
549    return *this;
550  }
551  _LIBCPP_HIDE_FROM_ABI bool __is_set() const { return __fill_val_ != _Traits::eof(); }
552  _LIBCPP_HIDE_FROM_ABI typename _Traits::int_type __get() const { return __fill_val_; }
553
554private:
555  typename _Traits::int_type __fill_val_;
556};
557
558template <class _CharT, class _Traits>
559class _LIBCPP_TEMPLATE_VIS basic_ios : public ios_base {
560public:
561  // types:
562  typedef _CharT char_type;
563  typedef _Traits traits_type;
564
565  typedef typename traits_type::int_type int_type;
566  typedef typename traits_type::pos_type pos_type;
567  typedef typename traits_type::off_type off_type;
568
569  static_assert(is_same<_CharT, typename traits_type::char_type>::value,
570                "traits_type::char_type must be the same type as CharT");
571
572#  ifdef _LIBCPP_CXX03_LANG
573  // Preserve the ability to compare with literal 0,
574  // and implicitly convert to bool, but not implicitly convert to int.
575  _LIBCPP_HIDE_FROM_ABI operator void*() const { return fail() ? nullptr : (void*)this; }
576#  else
577  _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return !fail(); }
578#  endif
579
580  _LIBCPP_HIDE_FROM_ABI bool operator!() const { return fail(); }
581  _LIBCPP_HIDE_FROM_ABI iostate rdstate() const { return ios_base::rdstate(); }
582  _LIBCPP_HIDE_FROM_ABI void clear(iostate __state = goodbit) { ios_base::clear(__state); }
583  _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state) { ios_base::setstate(__state); }
584  _LIBCPP_HIDE_FROM_ABI bool good() const { return ios_base::good(); }
585  _LIBCPP_HIDE_FROM_ABI bool eof() const { return ios_base::eof(); }
586  _LIBCPP_HIDE_FROM_ABI bool fail() const { return ios_base::fail(); }
587  _LIBCPP_HIDE_FROM_ABI bool bad() const { return ios_base::bad(); }
588
589  _LIBCPP_HIDE_FROM_ABI iostate exceptions() const { return ios_base::exceptions(); }
590  _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate) { ios_base::exceptions(__iostate); }
591
592  // 27.5.4.1 Constructor/destructor:
593  _LIBCPP_HIDE_FROM_ABI explicit basic_ios(basic_streambuf<char_type, traits_type>* __sb);
594  ~basic_ios() override;
595
596  // 27.5.4.2 Members:
597  _LIBCPP_HIDE_FROM_ABI basic_ostream<char_type, traits_type>* tie() const;
598  _LIBCPP_HIDE_FROM_ABI basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
599
600  _LIBCPP_HIDE_FROM_ABI basic_streambuf<char_type, traits_type>* rdbuf() const;
601  _LIBCPP_HIDE_FROM_ABI basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
602
603  basic_ios& copyfmt(const basic_ios& __rhs);
604
605  _LIBCPP_HIDE_FROM_ABI char_type fill() const;
606  _LIBCPP_HIDE_FROM_ABI char_type fill(char_type __ch);
607
608  _LIBCPP_HIDE_FROM_ABI locale imbue(const locale& __loc);
609
610  _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const;
611  _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const;
612
613protected:
614  _LIBCPP_HIDE_FROM_ABI basic_ios() {
615    // purposefully does no initialization
616    // since the destructor does nothing this does not have ios_base issues.
617  }
618  _LIBCPP_HIDE_FROM_ABI void init(basic_streambuf<char_type, traits_type>* __sb);
619
620  _LIBCPP_HIDE_FROM_ABI void move(basic_ios& __rhs);
621  _LIBCPP_HIDE_FROM_ABI void move(basic_ios&& __rhs) { move(__rhs); }
622  _LIBCPP_HIDE_FROM_ABI void swap(basic_ios& __rhs) _NOEXCEPT;
623  _LIBCPP_HIDE_FROM_ABI void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
624
625private:
626  basic_ostream<char_type, traits_type>* __tie_;
627
628#  if defined(_LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE)
629  using _FillType = _FillHelper<traits_type>;
630#  else
631  using _FillType = _SentinelValueFill<traits_type>;
632#  endif
633  mutable _FillType __fill_;
634};
635
636template <class _CharT, class _Traits>
637inline _LIBCPP_HIDE_FROM_ABI basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type, traits_type>* __sb) {
638  init(__sb);
639}
640
641template <class _CharT, class _Traits>
642basic_ios<_CharT, _Traits>::~basic_ios() {}
643
644template <class _CharT, class _Traits>
645inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) {
646  ios_base::init(__sb);
647  __tie_ = nullptr;
648  __fill_.__init();
649}
650
651template <class _CharT, class _Traits>
652inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>* basic_ios<_CharT, _Traits>::tie() const {
653  return __tie_;
654}
655
656template <class _CharT, class _Traits>
657inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>*
658basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) {
659  basic_ostream<char_type, traits_type>* __r = __tie_;
660  __tie_                                     = __tiestr;
661  return __r;
662}
663
664template <class _CharT, class _Traits>
665inline _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>* basic_ios<_CharT, _Traits>::rdbuf() const {
666  return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
667}
668
669template <class _CharT, class _Traits>
670inline _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>*
671basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) {
672  basic_streambuf<char_type, traits_type>* __r = rdbuf();
673  ios_base::rdbuf(__sb);
674  return __r;
675}
676
677template <class _CharT, class _Traits>
678inline _LIBCPP_HIDE_FROM_ABI locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) {
679  locale __r = getloc();
680  ios_base::imbue(__loc);
681  if (rdbuf())
682    rdbuf()->pubimbue(__loc);
683  return __r;
684}
685
686template <class _CharT, class _Traits>
687inline _LIBCPP_HIDE_FROM_ABI char basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const {
688  return std::use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
689}
690
691template <class _CharT, class _Traits>
692inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::widen(char __c) const {
693  return std::use_facet<ctype<char_type> >(getloc()).widen(__c);
694}
695
696template <class _CharT, class _Traits>
697inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill() const {
698  if (!__fill_.__is_set())
699    __fill_ = widen(' ');
700  return __fill_.__get();
701}
702
703template <class _CharT, class _Traits>
704inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill(char_type __ch) {
705  if (!__fill_.__is_set())
706    __fill_ = widen(' ');
707  char_type __r = __fill_.__get();
708  __fill_       = __ch;
709  return __r;
710}
711
712template <class _CharT, class _Traits>
713basic_ios<_CharT, _Traits>& basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) {
714  if (this != std::addressof(__rhs)) {
715    __call_callbacks(erase_event);
716    ios_base::copyfmt(__rhs);
717    __tie_  = __rhs.__tie_;
718    __fill_ = __rhs.__fill_;
719    __call_callbacks(copyfmt_event);
720    exceptions(__rhs.exceptions());
721  }
722  return *this;
723}
724
725template <class _CharT, class _Traits>
726inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) {
727  ios_base::move(__rhs);
728  __tie_       = __rhs.__tie_;
729  __rhs.__tie_ = nullptr;
730  __fill_      = __rhs.__fill_;
731}
732
733template <class _CharT, class _Traits>
734inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT {
735  ios_base::swap(__rhs);
736  std::swap(__tie_, __rhs.__tie_);
737  std::swap(__fill_, __rhs.__fill_);
738}
739
740template <class _CharT, class _Traits>
741inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) {
742  ios_base::set_rdbuf(__sb);
743}
744
745extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>;
746
747#  if _LIBCPP_HAS_WIDE_CHARACTERS
748extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>;
749#  endif
750
751_LIBCPP_HIDE_FROM_ABI inline ios_base& boolalpha(ios_base& __str) {
752  __str.setf(ios_base::boolalpha);
753  return __str;
754}
755
756_LIBCPP_HIDE_FROM_ABI inline ios_base& noboolalpha(ios_base& __str) {
757  __str.unsetf(ios_base::boolalpha);
758  return __str;
759}
760
761_LIBCPP_HIDE_FROM_ABI inline ios_base& showbase(ios_base& __str) {
762  __str.setf(ios_base::showbase);
763  return __str;
764}
765
766_LIBCPP_HIDE_FROM_ABI inline ios_base& noshowbase(ios_base& __str) {
767  __str.unsetf(ios_base::showbase);
768  return __str;
769}
770
771_LIBCPP_HIDE_FROM_ABI inline ios_base& showpoint(ios_base& __str) {
772  __str.setf(ios_base::showpoint);
773  return __str;
774}
775
776_LIBCPP_HIDE_FROM_ABI inline ios_base& noshowpoint(ios_base& __str) {
777  __str.unsetf(ios_base::showpoint);
778  return __str;
779}
780
781_LIBCPP_HIDE_FROM_ABI inline ios_base& showpos(ios_base& __str) {
782  __str.setf(ios_base::showpos);
783  return __str;
784}
785
786_LIBCPP_HIDE_FROM_ABI inline ios_base& noshowpos(ios_base& __str) {
787  __str.unsetf(ios_base::showpos);
788  return __str;
789}
790
791_LIBCPP_HIDE_FROM_ABI inline ios_base& skipws(ios_base& __str) {
792  __str.setf(ios_base::skipws);
793  return __str;
794}
795
796_LIBCPP_HIDE_FROM_ABI inline ios_base& noskipws(ios_base& __str) {
797  __str.unsetf(ios_base::skipws);
798  return __str;
799}
800
801_LIBCPP_HIDE_FROM_ABI inline ios_base& uppercase(ios_base& __str) {
802  __str.setf(ios_base::uppercase);
803  return __str;
804}
805
806_LIBCPP_HIDE_FROM_ABI inline ios_base& nouppercase(ios_base& __str) {
807  __str.unsetf(ios_base::uppercase);
808  return __str;
809}
810
811_LIBCPP_HIDE_FROM_ABI inline ios_base& unitbuf(ios_base& __str) {
812  __str.setf(ios_base::unitbuf);
813  return __str;
814}
815
816_LIBCPP_HIDE_FROM_ABI inline ios_base& nounitbuf(ios_base& __str) {
817  __str.unsetf(ios_base::unitbuf);
818  return __str;
819}
820
821_LIBCPP_HIDE_FROM_ABI inline ios_base& internal(ios_base& __str) {
822  __str.setf(ios_base::internal, ios_base::adjustfield);
823  return __str;
824}
825
826_LIBCPP_HIDE_FROM_ABI inline ios_base& left(ios_base& __str) {
827  __str.setf(ios_base::left, ios_base::adjustfield);
828  return __str;
829}
830
831_LIBCPP_HIDE_FROM_ABI inline ios_base& right(ios_base& __str) {
832  __str.setf(ios_base::right, ios_base::adjustfield);
833  return __str;
834}
835
836_LIBCPP_HIDE_FROM_ABI inline ios_base& dec(ios_base& __str) {
837  __str.setf(ios_base::dec, ios_base::basefield);
838  return __str;
839}
840
841_LIBCPP_HIDE_FROM_ABI inline ios_base& hex(ios_base& __str) {
842  __str.setf(ios_base::hex, ios_base::basefield);
843  return __str;
844}
845
846_LIBCPP_HIDE_FROM_ABI inline ios_base& oct(ios_base& __str) {
847  __str.setf(ios_base::oct, ios_base::basefield);
848  return __str;
849}
850
851_LIBCPP_HIDE_FROM_ABI inline ios_base& fixed(ios_base& __str) {
852  __str.setf(ios_base::fixed, ios_base::floatfield);
853  return __str;
854}
855
856_LIBCPP_HIDE_FROM_ABI inline ios_base& scientific(ios_base& __str) {
857  __str.setf(ios_base::scientific, ios_base::floatfield);
858  return __str;
859}
860
861_LIBCPP_HIDE_FROM_ABI inline ios_base& hexfloat(ios_base& __str) {
862  __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
863  return __str;
864}
865
866_LIBCPP_HIDE_FROM_ABI inline ios_base& defaultfloat(ios_base& __str) {
867  __str.unsetf(ios_base::floatfield);
868  return __str;
869}
870
871_LIBCPP_END_NAMESPACE_STD
872
873_LIBCPP_POP_MACROS
874
875#endif // _LIBCPP_HAS_LOCALIZATION
876
877#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
878#  include <atomic>
879#  include <concepts>
880#  include <cstddef>
881#  include <cstdlib>
882#  include <cstring>
883#  include <initializer_list>
884#  include <limits>
885#  include <mutex>
886#  include <new>
887#  include <stdexcept>
888#  include <system_error>
889#  include <type_traits>
890#  include <typeinfo>
891#endif
892
893#endif // _LIBCPP_IOS
894