• 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_FSTREAM
11#define _LIBCPP_FSTREAM
12
13/*
14    fstream synopsis
15
16template <class charT, class traits = char_traits<charT> >
17class basic_filebuf
18    : public basic_streambuf<charT, traits>
19{
20public:
21    typedef charT                          char_type;
22    typedef traits                         traits_type;
23    typedef typename traits_type::int_type int_type;
24    typedef typename traits_type::pos_type pos_type;
25    typedef typename traits_type::off_type off_type;
26
27    // 27.9.1.2 Constructors/destructor:
28    basic_filebuf();
29    basic_filebuf(basic_filebuf&& rhs);
30    virtual ~basic_filebuf();
31
32    // 27.9.1.3 Assign/swap:
33    basic_filebuf& operator=(basic_filebuf&& rhs);
34    void swap(basic_filebuf& rhs);
35
36    // 27.9.1.4 Members:
37    bool is_open() const;
38    basic_filebuf* open(const char* s, ios_base::openmode mode);
39    basic_filebuf* open(const string& s, ios_base::openmode mode);
40    basic_filebuf* open(const filesystem::path& p, ios_base::openmode mode); // C++17
41    basic_filebuf* close();
42
43protected:
44    // 27.9.1.5 Overridden virtual functions:
45    virtual streamsize showmanyc();
46    virtual int_type underflow();
47    virtual int_type uflow();
48    virtual int_type pbackfail(int_type c = traits_type::eof());
49    virtual int_type overflow (int_type c = traits_type::eof());
50    virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n);
51    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
52                             ios_base::openmode which = ios_base::in | ios_base::out);
53    virtual pos_type seekpos(pos_type sp,
54                             ios_base::openmode which = ios_base::in | ios_base::out);
55    virtual int sync();
56    virtual void imbue(const locale& loc);
57};
58
59template <class charT, class traits>
60  void
61  swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
62
63typedef basic_filebuf<char>    filebuf;
64typedef basic_filebuf<wchar_t> wfilebuf;
65
66template <class charT, class traits = char_traits<charT> >
67class basic_ifstream
68    : public basic_istream<charT,traits>
69{
70public:
71    typedef charT                          char_type;
72    typedef traits                         traits_type;
73    typedef typename traits_type::int_type int_type;
74    typedef typename traits_type::pos_type pos_type;
75    typedef typename traits_type::off_type off_type;
76    using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type; // Since C++26
77
78    basic_ifstream();
79    explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in);
80    explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in);
81    template<class T>
82    explicit basic_ifstream(const T& s, ios_base::openmode mode = ios_base::in); // Since C++17
83    basic_ifstream(basic_ifstream&& rhs);
84
85    basic_ifstream& operator=(basic_ifstream&& rhs);
86    void swap(basic_ifstream& rhs);
87
88    basic_filebuf<char_type, traits_type>* rdbuf() const;
89    native_handle_type native_handle() const noexcept; // Since C++26
90    bool is_open() const;
91    void open(const char* s, ios_base::openmode mode = ios_base::in);
92    void open(const string& s, ios_base::openmode mode = ios_base::in);
93    void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in); // C++17
94
95    void close();
96};
97
98template <class charT, class traits>
99  void
100  swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y);
101
102typedef basic_ifstream<char>    ifstream;
103typedef basic_ifstream<wchar_t> wifstream;
104
105template <class charT, class traits = char_traits<charT> >
106class basic_ofstream
107    : public basic_ostream<charT,traits>
108{
109public:
110    typedef charT                          char_type;
111    typedef traits                         traits_type;
112    typedef typename traits_type::int_type int_type;
113    typedef typename traits_type::pos_type pos_type;
114    typedef typename traits_type::off_type off_type;
115    using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type; // Since C++26
116
117    basic_ofstream();
118    explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out);
119    explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out);
120    template<class T>
121    explicit basic_ofstream(const T& s, ios_base::openmode mode = ios_base::out); // Since C++17
122    basic_ofstream(basic_ofstream&& rhs);
123
124    basic_ofstream& operator=(basic_ofstream&& rhs);
125    void swap(basic_ofstream& rhs);
126
127    basic_filebuf<char_type, traits_type>* rdbuf() const;
128    native_handle_type native_handle() const noexcept; // Since C++26
129
130    bool is_open() const;
131    void open(const char* s, ios_base::openmode mode = ios_base::out);
132    void open(const string& s, ios_base::openmode mode = ios_base::out);
133    void open(const filesystem::path& p,
134              ios_base::openmode mode = ios_base::out); // C++17
135
136    void close();
137};
138
139template <class charT, class traits>
140  void
141  swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y);
142
143typedef basic_ofstream<char>    ofstream;
144typedef basic_ofstream<wchar_t> wofstream;
145
146template <class charT, class traits=char_traits<charT> >
147class basic_fstream
148    : public basic_iostream<charT,traits>
149{
150public:
151    typedef charT                          char_type;
152    typedef traits                         traits_type;
153    typedef typename traits_type::int_type int_type;
154    typedef typename traits_type::pos_type pos_type;
155    typedef typename traits_type::off_type off_type;
156    using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type; // Since C++26
157
158    basic_fstream();
159    explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
160    explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
161    template<class T>
162    explicit basic_fstream(const T& s, ios_base::openmode mode = ios_base::in | ios_base::out); // Since C++17
163    basic_fstream(basic_fstream&& rhs);
164
165    basic_fstream& operator=(basic_fstream&& rhs);
166    void swap(basic_fstream& rhs);
167
168    basic_filebuf<char_type, traits_type>* rdbuf() const;
169    native_handle_type native_handle() const noexcept; // Since C++26
170    bool is_open() const;
171    void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
172    void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
173    void open(const filesystem::path& s,
174              ios_base::openmode mode = ios_base::in|ios_base::out); // C++17
175
176    void close();
177};
178
179template <class charT, class traits>
180  void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y);
181
182typedef basic_fstream<char>    fstream;
183typedef basic_fstream<wchar_t> wfstream;
184
185}  // std
186
187*/
188
189#include <__algorithm/max.h>
190#include <__assert>
191#include <__config>
192#include <__filesystem/path.h>
193#include <__fwd/fstream.h>
194#include <__locale>
195#include <__memory/addressof.h>
196#include <__memory/unique_ptr.h>
197#include <__ostream/basic_ostream.h>
198#include <__type_traits/enable_if.h>
199#include <__type_traits/is_same.h>
200#include <__utility/move.h>
201#include <__utility/swap.h>
202#include <__utility/unreachable.h>
203#include <cstdio>
204#include <istream>
205#include <streambuf>
206#include <typeinfo>
207#include <version>
208
209#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
210#  pragma GCC system_header
211#endif
212
213_LIBCPP_PUSH_MACROS
214#include <__undef_macros>
215
216#if !defined(_LIBCPP_MSVCRT) && !defined(_NEWLIB_VERSION)
217#  define _LIBCPP_HAS_OFF_T_FUNCTIONS 1
218#else
219#  define _LIBCPP_HAS_OFF_T_FUNCTIONS 0
220#endif
221
222#if _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
223
224_LIBCPP_BEGIN_NAMESPACE_STD
225
226#  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
227_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept;
228#  endif
229
230template <class _CharT, class _Traits>
231class _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> {
232public:
233  typedef _CharT char_type;
234  typedef _Traits traits_type;
235  typedef typename traits_type::int_type int_type;
236  typedef typename traits_type::pos_type pos_type;
237  typedef typename traits_type::off_type off_type;
238  typedef typename traits_type::state_type state_type;
239#  if _LIBCPP_STD_VER >= 26
240#    if defined(_LIBCPP_WIN32API)
241  using native_handle_type = void*; // HANDLE
242#    elif __has_include(<unistd.h>)
243  using native_handle_type = int; // POSIX file descriptor
244#    else
245#      error "Provide a native file handle!"
246#    endif
247#  endif
248
249  // 27.9.1.2 Constructors/destructor:
250  basic_filebuf();
251  basic_filebuf(basic_filebuf&& __rhs);
252  ~basic_filebuf() override;
253
254  // 27.9.1.3 Assign/swap:
255  _LIBCPP_HIDE_FROM_ABI basic_filebuf& operator=(basic_filebuf&& __rhs);
256  void swap(basic_filebuf& __rhs);
257
258  // 27.9.1.4 Members:
259  _LIBCPP_HIDE_FROM_ABI bool is_open() const;
260  basic_filebuf* open(const char* __s, ios_base::openmode __mode);
261#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
262  basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode);
263#  endif
264  _LIBCPP_HIDE_FROM_ABI basic_filebuf* open(const string& __s, ios_base::openmode __mode);
265
266#  if _LIBCPP_STD_VER >= 17
267  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI basic_filebuf*
268  open(const filesystem::path& __p, ios_base::openmode __mode) {
269    return open(__p.c_str(), __mode);
270  }
271#  endif
272  _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode __mode);
273  basic_filebuf* close();
274#  if _LIBCPP_STD_VER >= 26
275  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
276    _LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");
277#    if defined(_LIBCPP_WIN32API)
278    return std::__filebuf_windows_native_handle(__file_);
279#    elif __has_include(<unistd.h>)
280    return fileno(__file_);
281#    else
282#      error "Provide a way to determine the file native handle!"
283#    endif
284  }
285#  endif //  _LIBCPP_STD_VER >= 26
286
287  _LIBCPP_HIDE_FROM_ABI inline static const char* __make_mdstring(ios_base::openmode __mode) _NOEXCEPT;
288#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
289  _LIBCPP_HIDE_FROM_ABI inline static const wchar_t* __make_mdwstring(ios_base::openmode __mode) _NOEXCEPT;
290#  endif
291
292protected:
293  // 27.9.1.5 Overridden virtual functions:
294  int_type underflow() override;
295  int_type pbackfail(int_type __c = traits_type::eof()) override;
296  int_type overflow(int_type __c = traits_type::eof()) override;
297  basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n) override;
298  pos_type
299  seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override;
300  pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override;
301  int sync() override;
302  void imbue(const locale& __loc) override;
303
304private:
305  char* __extbuf_;
306  const char* __extbufnext_;
307  const char* __extbufend_;
308  char __extbuf_min_[8];
309  size_t __ebs_;
310  char_type* __intbuf_;
311  size_t __ibs_;
312  FILE* __file_;
313  const codecvt<char_type, char, state_type>* __cv_;
314  state_type __st_;
315  state_type __st_last_;
316  ios_base::openmode __om_;
317  // There have been no file operations yet, which allows setting unbuffered
318  // I/O mode.
319  static const ios_base::openmode __no_io_operations = ios_base::trunc;
320  // Unbuffered I/O mode has been requested.
321  static const ios_base::openmode __use_unbuffered_io = ios_base::ate;
322  // Used to track the currently used mode and track whether the output should
323  // be unbuffered.
324  // [filebuf.virtuals]/12
325  //   If setbuf(0, 0) is called on a stream before any I/O has occurred on
326  //   that stream, the stream becomes unbuffered. Otherwise the results are
327  //   implementation-defined.
328  // This allows calling setbuf(0, 0)
329  // - before opening a file,
330  // - after opening a file, before
331  //   - a read
332  //   - a write
333  //   - a seek.
334  // Note that opening a file with ios_base::ate does a seek operation.
335  // Normally underflow, overflow, and sync change this flag to ios_base::in,
336  // ios_base_out, or 0.
337  //
338  // The ios_base::trunc and ios_base::ate flags are not used in __cm_. They
339  // are used to track the state of the unbuffered request. For readability
340  // they have the aliases __no_io_operations and __use_unbuffered_io
341  // respectively.
342  //
343  // The __no_io_operations and __use_unbuffered_io flags are used in the
344  // following way:
345  // - __no_io_operations is set upon construction to indicate the unbuffered
346  //   state can be set.
347  // - When requesting unbuffered output:
348  //   - If the file is open it sets the mode.
349  //   - Else places a request by adding the __use_unbuffered_io flag.
350  // - When a file is opened it checks whether both __no_io_operations and
351  //   __use_unbuffered_io are set. If so switches to unbuffered mode.
352  // - All file I/O operations change the mode effectively clearing the
353  //   __no_io_operations and __use_unbuffered_io flags.
354  ios_base::openmode __cm_;
355  bool __owns_eb_;
356  bool __owns_ib_;
357  bool __always_noconv_;
358
359  bool __read_mode();
360  void __write_mode();
361
362  _LIBCPP_EXPORTED_FROM_ABI friend FILE* __get_ostream_file(ostream&);
363
364  // There are multiple (__)open function, they use different C-API open
365  // function. After that call these functions behave the same. This function
366  // does that part and determines the final return value.
367  _LIBCPP_HIDE_FROM_ABI basic_filebuf* __do_open(FILE* __file, ios_base::openmode __mode) {
368    __file_ = __file;
369    if (!__file_)
370      return nullptr;
371
372    __om_ = __mode;
373    if (__cm_ == (__no_io_operations | __use_unbuffered_io)) {
374      std::setbuf(__file_, nullptr);
375      __cm_ = 0;
376    }
377
378    if (__mode & ios_base::ate) {
379      __cm_ = 0;
380      if (fseek(__file_, 0, SEEK_END)) {
381        fclose(__file_);
382        __file_ = nullptr;
383        return nullptr;
384      }
385    }
386
387    return this;
388  }
389
390  // If the file is already open, switch to unbuffered mode. Otherwise, record
391  // the request to use unbuffered mode so that we use that mode when we
392  // eventually open the file.
393  _LIBCPP_HIDE_FROM_ABI void __request_unbuffered_mode(char_type* __s, streamsize __n) {
394    if (__cm_ == __no_io_operations && __s == nullptr && __n == 0) {
395      if (__file_) {
396        std::setbuf(__file_, nullptr);
397        __cm_ = 0;
398      } else {
399        __cm_ = __no_io_operations | __use_unbuffered_io;
400      }
401    }
402  }
403};
404
405template <class _CharT, class _Traits>
406basic_filebuf<_CharT, _Traits>::basic_filebuf()
407    : __extbuf_(nullptr),
408      __extbufnext_(nullptr),
409      __extbufend_(nullptr),
410      __ebs_(0),
411      __intbuf_(nullptr),
412      __ibs_(0),
413      __file_(nullptr),
414      __cv_(nullptr),
415      __st_(),
416      __st_last_(),
417      __om_(0),
418      __cm_(__no_io_operations),
419      __owns_eb_(false),
420      __owns_ib_(false),
421      __always_noconv_(false) {
422  if (std::has_facet<codecvt<char_type, char, state_type> >(this->getloc())) {
423    __cv_            = &std::use_facet<codecvt<char_type, char, state_type> >(this->getloc());
424    __always_noconv_ = __cv_->always_noconv();
425  }
426  setbuf(nullptr, 4096);
427}
428
429template <class _CharT, class _Traits>
430basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) : basic_streambuf<_CharT, _Traits>(__rhs) {
431  if (__rhs.__extbuf_ == __rhs.__extbuf_min_) {
432    __extbuf_     = __extbuf_min_;
433    __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_);
434    __extbufend_  = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_);
435  } else {
436    __extbuf_     = __rhs.__extbuf_;
437    __extbufnext_ = __rhs.__extbufnext_;
438    __extbufend_  = __rhs.__extbufend_;
439  }
440  __ebs_           = __rhs.__ebs_;
441  __intbuf_        = __rhs.__intbuf_;
442  __ibs_           = __rhs.__ibs_;
443  __file_          = __rhs.__file_;
444  __cv_            = __rhs.__cv_;
445  __st_            = __rhs.__st_;
446  __st_last_       = __rhs.__st_last_;
447  __om_            = __rhs.__om_;
448  __cm_            = __rhs.__cm_;
449  __owns_eb_       = __rhs.__owns_eb_;
450  __owns_ib_       = __rhs.__owns_ib_;
451  __always_noconv_ = __rhs.__always_noconv_;
452  if (__rhs.pbase()) {
453    if (__rhs.pbase() == __rhs.__intbuf_)
454      this->setp(__intbuf_, __intbuf_ + (__rhs.epptr() - __rhs.pbase()));
455    else
456      this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs.epptr() - __rhs.pbase()));
457    this->__pbump(__rhs.pptr() - __rhs.pbase());
458  } else if (__rhs.eback()) {
459    if (__rhs.eback() == __rhs.__intbuf_)
460      this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), __intbuf_ + (__rhs.egptr() - __rhs.eback()));
461    else
462      this->setg((char_type*)__extbuf_,
463                 (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()),
464                 (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback()));
465  }
466  __rhs.__extbuf_     = nullptr;
467  __rhs.__extbufnext_ = nullptr;
468  __rhs.__extbufend_  = nullptr;
469  __rhs.__ebs_        = 0;
470  __rhs.__intbuf_     = 0;
471  __rhs.__ibs_        = 0;
472  __rhs.__file_       = nullptr;
473  __rhs.__st_         = state_type();
474  __rhs.__st_last_    = state_type();
475  __rhs.__om_         = 0;
476  __rhs.__cm_         = 0;
477  __rhs.__owns_eb_    = false;
478  __rhs.__owns_ib_    = false;
479  __rhs.setg(0, 0, 0);
480  __rhs.setp(0, 0);
481}
482
483template <class _CharT, class _Traits>
484inline basic_filebuf<_CharT, _Traits>& basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) {
485  close();
486  swap(__rhs);
487  return *this;
488}
489
490template <class _CharT, class _Traits>
491basic_filebuf<_CharT, _Traits>::~basic_filebuf() {
492#  if _LIBCPP_HAS_EXCEPTIONS
493  try {
494#  endif // _LIBCPP_HAS_EXCEPTIONS
495    close();
496#  if _LIBCPP_HAS_EXCEPTIONS
497  } catch (...) {
498  }
499#  endif // _LIBCPP_HAS_EXCEPTIONS
500  if (__owns_eb_)
501    delete[] __extbuf_;
502  if (__owns_ib_)
503    delete[] __intbuf_;
504}
505
506template <class _CharT, class _Traits>
507void basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) {
508  basic_streambuf<char_type, traits_type>::swap(__rhs);
509  if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) {
510    // Neither *this nor __rhs uses the small buffer, so we can simply swap the pointers.
511    std::swap(__extbuf_, __rhs.__extbuf_);
512    std::swap(__extbufnext_, __rhs.__extbufnext_);
513    std::swap(__extbufend_, __rhs.__extbufend_);
514  } else {
515    ptrdiff_t __ln = __extbufnext_ ? __extbufnext_ - __extbuf_ : 0;
516    ptrdiff_t __le = __extbufend_ ? __extbufend_ - __extbuf_ : 0;
517    ptrdiff_t __rn = __rhs.__extbufnext_ ? __rhs.__extbufnext_ - __rhs.__extbuf_ : 0;
518    ptrdiff_t __re = __rhs.__extbufend_ ? __rhs.__extbufend_ - __rhs.__extbuf_ : 0;
519    if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) {
520      // *this uses the small buffer, but __rhs doesn't.
521      __extbuf_       = __rhs.__extbuf_;
522      __rhs.__extbuf_ = __rhs.__extbuf_min_;
523      std::memmove(__rhs.__extbuf_min_, __extbuf_min_, sizeof(__extbuf_min_));
524    } else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) {
525      // *this doesn't use the small buffer, but __rhs does.
526      __rhs.__extbuf_ = __extbuf_;
527      __extbuf_       = __extbuf_min_;
528      std::memmove(__extbuf_min_, __rhs.__extbuf_min_, sizeof(__extbuf_min_));
529    } else {
530      // Both *this and __rhs use the small buffer.
531      char __tmp[sizeof(__extbuf_min_)];
532      std::memmove(__tmp, __extbuf_min_, sizeof(__extbuf_min_));
533      std::memmove(__extbuf_min_, __rhs.__extbuf_min_, sizeof(__extbuf_min_));
534      std::memmove(__rhs.__extbuf_min_, __tmp, sizeof(__extbuf_min_));
535    }
536    __extbufnext_       = __extbuf_ + __rn;
537    __extbufend_        = __extbuf_ + __re;
538    __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln;
539    __rhs.__extbufend_  = __rhs.__extbuf_ + __le;
540  }
541  std::swap(__ebs_, __rhs.__ebs_);
542  std::swap(__intbuf_, __rhs.__intbuf_);
543  std::swap(__ibs_, __rhs.__ibs_);
544  std::swap(__file_, __rhs.__file_);
545  std::swap(__cv_, __rhs.__cv_);
546  std::swap(__st_, __rhs.__st_);
547  std::swap(__st_last_, __rhs.__st_last_);
548  std::swap(__om_, __rhs.__om_);
549  std::swap(__cm_, __rhs.__cm_);
550  std::swap(__owns_eb_, __rhs.__owns_eb_);
551  std::swap(__owns_ib_, __rhs.__owns_ib_);
552  std::swap(__always_noconv_, __rhs.__always_noconv_);
553  if (this->eback() == (char_type*)__rhs.__extbuf_min_) {
554    ptrdiff_t __n = this->gptr() - this->eback();
555    ptrdiff_t __e = this->egptr() - this->eback();
556    this->setg((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __n, (char_type*)__extbuf_min_ + __e);
557  } else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) {
558    ptrdiff_t __n = this->pptr() - this->pbase();
559    ptrdiff_t __e = this->epptr() - this->pbase();
560    this->setp((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __e);
561    this->__pbump(__n);
562  }
563  if (__rhs.eback() == (char_type*)__extbuf_min_) {
564    ptrdiff_t __n = __rhs.gptr() - __rhs.eback();
565    ptrdiff_t __e = __rhs.egptr() - __rhs.eback();
566    __rhs.setg(
567        (char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __n, (char_type*)__rhs.__extbuf_min_ + __e);
568  } else if (__rhs.pbase() == (char_type*)__extbuf_min_) {
569    ptrdiff_t __n = __rhs.pptr() - __rhs.pbase();
570    ptrdiff_t __e = __rhs.epptr() - __rhs.pbase();
571    __rhs.setp((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __e);
572    __rhs.__pbump(__n);
573  }
574}
575
576template <class _CharT, class _Traits>
577inline _LIBCPP_HIDE_FROM_ABI void swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) {
578  __x.swap(__y);
579}
580
581template <class _CharT, class _Traits>
582inline bool basic_filebuf<_CharT, _Traits>::is_open() const {
583  return __file_ != nullptr;
584}
585
586template <class _CharT, class _Traits>
587const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(ios_base::openmode __mode) _NOEXCEPT {
588  switch (__mode & ~ios_base::ate) {
589  case ios_base::out:
590  case ios_base::out | ios_base::trunc:
591    return "w" _LIBCPP_FOPEN_CLOEXEC_MODE;
592  case ios_base::out | ios_base::app:
593  case ios_base::app:
594    return "a" _LIBCPP_FOPEN_CLOEXEC_MODE;
595  case ios_base::in:
596    return "r" _LIBCPP_FOPEN_CLOEXEC_MODE;
597  case ios_base::in | ios_base::out:
598    return "r+" _LIBCPP_FOPEN_CLOEXEC_MODE;
599  case ios_base::in | ios_base::out | ios_base::trunc:
600    return "w+" _LIBCPP_FOPEN_CLOEXEC_MODE;
601  case ios_base::in | ios_base::out | ios_base::app:
602  case ios_base::in | ios_base::app:
603    return "a+" _LIBCPP_FOPEN_CLOEXEC_MODE;
604  case ios_base::out | ios_base::binary:
605  case ios_base::out | ios_base::trunc | ios_base::binary:
606    return "wb" _LIBCPP_FOPEN_CLOEXEC_MODE;
607  case ios_base::out | ios_base::app | ios_base::binary:
608  case ios_base::app | ios_base::binary:
609    return "ab" _LIBCPP_FOPEN_CLOEXEC_MODE;
610  case ios_base::in | ios_base::binary:
611    return "rb" _LIBCPP_FOPEN_CLOEXEC_MODE;
612  case ios_base::in | ios_base::out | ios_base::binary:
613    return "r+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
614  case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
615    return "w+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
616  case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
617  case ios_base::in | ios_base::app | ios_base::binary:
618    return "a+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
619#  if _LIBCPP_STD_VER >= 23
620  case ios_base::out | ios_base::noreplace:
621  case ios_base::out | ios_base::trunc | ios_base::noreplace:
622    return "wx" _LIBCPP_FOPEN_CLOEXEC_MODE;
623  case ios_base::in | ios_base::out | ios_base::trunc | ios_base::noreplace:
624    return "w+x" _LIBCPP_FOPEN_CLOEXEC_MODE;
625  case ios_base::out | ios_base::binary | ios_base::noreplace:
626  case ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
627    return "wbx" _LIBCPP_FOPEN_CLOEXEC_MODE;
628  case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
629    return "w+bx" _LIBCPP_FOPEN_CLOEXEC_MODE;
630#  endif // _LIBCPP_STD_VER >= 23
631  default:
632    return nullptr;
633  }
634  __libcpp_unreachable();
635}
636
637#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
638template <class _CharT, class _Traits>
639const wchar_t* basic_filebuf<_CharT, _Traits>::__make_mdwstring(ios_base::openmode __mode) _NOEXCEPT {
640  switch (__mode & ~ios_base::ate) {
641  case ios_base::out:
642  case ios_base::out | ios_base::trunc:
643    return L"w";
644  case ios_base::out | ios_base::app:
645  case ios_base::app:
646    return L"a";
647  case ios_base::in:
648    return L"r";
649  case ios_base::in | ios_base::out:
650    return L"r+";
651  case ios_base::in | ios_base::out | ios_base::trunc:
652    return L"w+";
653  case ios_base::in | ios_base::out | ios_base::app:
654  case ios_base::in | ios_base::app:
655    return L"a+";
656  case ios_base::out | ios_base::binary:
657  case ios_base::out | ios_base::trunc | ios_base::binary:
658    return L"wb";
659  case ios_base::out | ios_base::app | ios_base::binary:
660  case ios_base::app | ios_base::binary:
661    return L"ab";
662  case ios_base::in | ios_base::binary:
663    return L"rb";
664  case ios_base::in | ios_base::out | ios_base::binary:
665    return L"r+b";
666  case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
667    return L"w+b";
668  case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
669  case ios_base::in | ios_base::app | ios_base::binary:
670    return L"a+b";
671#    if _LIBCPP_STD_VER >= 23
672  case ios_base::out | ios_base::noreplace:
673  case ios_base::out | ios_base::trunc | ios_base::noreplace:
674    return L"wx";
675  case ios_base::in | ios_base::out | ios_base::trunc | ios_base::noreplace:
676    return L"w+x";
677  case ios_base::out | ios_base::binary | ios_base::noreplace:
678  case ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
679    return L"wbx";
680  case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
681    return L"w+bx";
682#    endif // _LIBCPP_STD_VER >= 23
683  default:
684    return nullptr;
685  }
686  __libcpp_unreachable();
687}
688#  endif
689
690template <class _CharT, class _Traits>
691basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) {
692  if (__file_)
693    return nullptr;
694  const char* __mdstr = __make_mdstring(__mode);
695  if (!__mdstr)
696    return nullptr;
697
698  return __do_open(fopen(__s, __mdstr), __mode);
699}
700
701template <class _CharT, class _Traits>
702inline basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) {
703  if (__file_)
704    return nullptr;
705  const char* __mdstr = __make_mdstring(__mode);
706  if (!__mdstr)
707    return nullptr;
708
709  return __do_open(fdopen(__fd, __mdstr), __mode);
710}
711
712#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
713// This is basically the same as the char* overload except that it uses _wfopen
714// and long mode strings.
715template <class _CharT, class _Traits>
716basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
717  if (__file_)
718    return nullptr;
719  const wchar_t* __mdstr = __make_mdwstring(__mode);
720  if (!__mdstr)
721    return nullptr;
722
723  return __do_open(_wfopen(__s, __mdstr), __mode);
724}
725#  endif
726
727template <class _CharT, class _Traits>
728inline basic_filebuf<_CharT, _Traits>*
729basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
730  return open(__s.c_str(), __mode);
731}
732
733template <class _CharT, class _Traits>
734basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::close() {
735  basic_filebuf<_CharT, _Traits>* __rt = nullptr;
736  if (__file_) {
737    __rt = this;
738    unique_ptr<FILE, int (*)(FILE*)> __h(__file_, fclose);
739    if (sync())
740      __rt = nullptr;
741    if (fclose(__h.release()))
742      __rt = nullptr;
743    __file_ = nullptr;
744    setbuf(0, 0);
745  }
746  return __rt;
747}
748
749template <class _CharT, class _Traits>
750typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::underflow() {
751  if (__file_ == nullptr)
752    return traits_type::eof();
753  bool __initial = __read_mode();
754  char_type __1buf;
755  if (this->gptr() == nullptr)
756    this->setg(&__1buf, &__1buf + 1, &__1buf + 1);
757  const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4);
758  int_type __c            = traits_type::eof();
759  if (this->gptr() == this->egptr()) {
760    std::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
761    if (__always_noconv_) {
762      size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz);
763      __nmemb        = ::fread(this->eback() + __unget_sz, 1, __nmemb, __file_);
764      if (__nmemb != 0) {
765        this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb);
766        __c = traits_type::to_int_type(*this->gptr());
767      }
768    } else {
769      if (__extbufend_ != __extbufnext_) {
770        _LIBCPP_ASSERT_NON_NULL(__extbufnext_ != nullptr, "underflow moving from nullptr");
771        _LIBCPP_ASSERT_NON_NULL(__extbuf_ != nullptr, "underflow moving into nullptr");
772        std::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
773      }
774      __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
775      __extbufend_  = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
776      size_t __nmemb =
777          std::min(static_cast<size_t>(__ibs_ - __unget_sz), static_cast<size_t>(__extbufend_ - __extbufnext_));
778      codecvt_base::result __r;
779      __st_last_  = __st_;
780      size_t __nr = fread((void*)const_cast<char*>(__extbufnext_), 1, __nmemb, __file_);
781      if (__nr != 0) {
782        if (!__cv_)
783          __throw_bad_cast();
784
785        __extbufend_ = __extbufnext_ + __nr;
786        char_type* __inext;
787        __r = __cv_->in(
788            __st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->eback() + __ibs_, __inext);
789        if (__r == codecvt_base::noconv) {
790          this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char*>(__extbufend_));
791          __c = traits_type::to_int_type(*this->gptr());
792        } else if (__inext != this->eback() + __unget_sz) {
793          this->setg(this->eback(), this->eback() + __unget_sz, __inext);
794          __c = traits_type::to_int_type(*this->gptr());
795        }
796      }
797    }
798  } else
799    __c = traits_type::to_int_type(*this->gptr());
800  if (this->eback() == &__1buf)
801    this->setg(nullptr, nullptr, nullptr);
802  return __c;
803}
804
805template <class _CharT, class _Traits>
806typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) {
807  if (__file_ && this->eback() < this->gptr()) {
808    if (traits_type::eq_int_type(__c, traits_type::eof())) {
809      this->gbump(-1);
810      return traits_type::not_eof(__c);
811    }
812    if ((__om_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) {
813      this->gbump(-1);
814      *this->gptr() = traits_type::to_char_type(__c);
815      return __c;
816    }
817  }
818  return traits_type::eof();
819}
820
821template <class _CharT, class _Traits>
822typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) {
823  if (__file_ == nullptr)
824    return traits_type::eof();
825  __write_mode();
826  char_type __1buf;
827  char_type* __pb_save  = this->pbase();
828  char_type* __epb_save = this->epptr();
829  if (!traits_type::eq_int_type(__c, traits_type::eof())) {
830    if (this->pptr() == nullptr)
831      this->setp(&__1buf, &__1buf + 1);
832    *this->pptr() = traits_type::to_char_type(__c);
833    this->pbump(1);
834  }
835  if (this->pptr() != this->pbase()) {
836    if (__always_noconv_) {
837      size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
838      if (std::fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb)
839        return traits_type::eof();
840    } else {
841      char* __extbe = __extbuf_;
842      codecvt_base::result __r;
843      do {
844        if (!__cv_)
845          __throw_bad_cast();
846
847        const char_type* __e;
848        __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe);
849        if (__e == this->pbase())
850          return traits_type::eof();
851        if (__r == codecvt_base::noconv) {
852          size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
853          if (std::fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb)
854            return traits_type::eof();
855        } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) {
856          size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
857          if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
858            return traits_type::eof();
859          if (__r == codecvt_base::partial) {
860            this->setp(const_cast<char_type*>(__e), this->pptr());
861            this->__pbump(this->epptr() - this->pbase());
862          }
863        } else
864          return traits_type::eof();
865      } while (__r == codecvt_base::partial);
866    }
867    this->setp(__pb_save, __epb_save);
868  }
869  return traits_type::not_eof(__c);
870}
871
872template <class _CharT, class _Traits>
873basic_streambuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) {
874  this->setg(nullptr, nullptr, nullptr);
875  this->setp(nullptr, nullptr);
876  __request_unbuffered_mode(__s, __n);
877  if (__owns_eb_)
878    delete[] __extbuf_;
879  if (__owns_ib_)
880    delete[] __intbuf_;
881  __ebs_ = __n;
882  if (__ebs_ > sizeof(__extbuf_min_)) {
883    if (__always_noconv_ && __s) {
884      __extbuf_  = (char*)__s;
885      __owns_eb_ = false;
886    } else {
887      __extbuf_  = new char[__ebs_];
888      __owns_eb_ = true;
889    }
890  } else {
891    __extbuf_  = __extbuf_min_;
892    __ebs_     = sizeof(__extbuf_min_);
893    __owns_eb_ = false;
894  }
895  if (!__always_noconv_) {
896    __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
897    if (__s && __ibs_ > sizeof(__extbuf_min_)) {
898      __intbuf_  = __s;
899      __owns_ib_ = false;
900    } else {
901      __intbuf_  = new char_type[__ibs_];
902      __owns_ib_ = true;
903    }
904  } else {
905    __ibs_     = 0;
906    __intbuf_  = nullptr;
907    __owns_ib_ = false;
908  }
909  return this;
910}
911
912template <class _CharT, class _Traits>
913typename basic_filebuf<_CharT, _Traits>::pos_type
914basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) {
915  if (!__cv_)
916    __throw_bad_cast();
917
918  int __width = __cv_->encoding();
919  if (__file_ == nullptr || (__width <= 0 && __off != 0) || sync())
920    return pos_type(off_type(-1));
921  // __width > 0 || __off == 0
922  int __whence;
923  switch (__way) {
924  case ios_base::beg:
925    __whence = SEEK_SET;
926    break;
927  case ios_base::cur:
928    __whence = SEEK_CUR;
929    break;
930  case ios_base::end:
931    __whence = SEEK_END;
932    break;
933  default:
934    return pos_type(off_type(-1));
935  }
936#  if !_LIBCPP_HAS_OFF_T_FUNCTIONS
937  if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
938    return pos_type(off_type(-1));
939  pos_type __r = ftell(__file_);
940#  else
941  if (::fseeko(__file_, __width > 0 ? __width * __off : 0, __whence))
942    return pos_type(off_type(-1));
943  pos_type __r = ftello(__file_);
944#  endif
945  __r.state(__st_);
946  return __r;
947}
948
949template <class _CharT, class _Traits>
950typename basic_filebuf<_CharT, _Traits>::pos_type
951basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) {
952  if (__file_ == nullptr || sync())
953    return pos_type(off_type(-1));
954#  if !_LIBCPP_HAS_OFF_T_FUNCTIONS
955  if (fseek(__file_, __sp, SEEK_SET))
956    return pos_type(off_type(-1));
957#  else
958  if (::fseeko(__file_, __sp, SEEK_SET))
959    return pos_type(off_type(-1));
960#  endif
961  __st_ = __sp.state();
962  return __sp;
963}
964
965template <class _CharT, class _Traits>
966int basic_filebuf<_CharT, _Traits>::sync() {
967  if (__file_ == nullptr)
968    return 0;
969  if (!__cv_)
970    __throw_bad_cast();
971
972  if (__cm_ & ios_base::out) {
973    if (this->pptr() != this->pbase())
974      if (overflow() == traits_type::eof())
975        return -1;
976    codecvt_base::result __r;
977    do {
978      char* __extbe;
979      __r            = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
980      size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
981      if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
982        return -1;
983    } while (__r == codecvt_base::partial);
984    if (__r == codecvt_base::error)
985      return -1;
986    if (fflush(__file_))
987      return -1;
988  } else if (__cm_ & ios_base::in) {
989    off_type __c;
990    state_type __state = __st_last_;
991    bool __update_st   = false;
992    if (__always_noconv_)
993      __c = this->egptr() - this->gptr();
994    else {
995      int __width = __cv_->encoding();
996      __c         = __extbufend_ - __extbufnext_;
997      if (__width > 0)
998        __c += __width * (this->egptr() - this->gptr());
999      else {
1000        if (this->gptr() != this->egptr()) {
1001          const int __off = __cv_->length(__state, __extbuf_, __extbufnext_, this->gptr() - this->eback());
1002          __c += __extbufnext_ - __extbuf_ - __off;
1003          __update_st = true;
1004        }
1005      }
1006    }
1007#  if !_LIBCPP_HAS_OFF_T_FUNCTIONS
1008    if (fseek(__file_, -__c, SEEK_CUR))
1009      return -1;
1010#  else
1011    if (::fseeko(__file_, -__c, SEEK_CUR))
1012      return -1;
1013#  endif
1014    if (__update_st)
1015      __st_ = __state;
1016    __extbufnext_ = __extbufend_ = __extbuf_;
1017    this->setg(nullptr, nullptr, nullptr);
1018    __cm_ = 0;
1019  }
1020  return 0;
1021}
1022
1023template <class _CharT, class _Traits>
1024void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) {
1025  sync();
1026  __cv_            = &std::use_facet<codecvt<char_type, char, state_type> >(__loc);
1027  bool __old_anc   = __always_noconv_;
1028  __always_noconv_ = __cv_->always_noconv();
1029  if (__old_anc != __always_noconv_) {
1030    this->setg(nullptr, nullptr, nullptr);
1031    this->setp(nullptr, nullptr);
1032    // invariant, char_type is char, else we couldn't get here
1033    if (__always_noconv_) // need to dump __intbuf_
1034    {
1035      if (__owns_eb_)
1036        delete[] __extbuf_;
1037      __owns_eb_ = __owns_ib_;
1038      __ebs_     = __ibs_;
1039      __extbuf_  = (char*)__intbuf_;
1040      __ibs_     = 0;
1041      __intbuf_  = nullptr;
1042      __owns_ib_ = false;
1043    } else // need to obtain an __intbuf_.
1044    {      // If __extbuf_ is user-supplied, use it, else new __intbuf_
1045      if (!__owns_eb_ && __extbuf_ != __extbuf_min_) {
1046        __ibs_     = __ebs_;
1047        __intbuf_  = (char_type*)__extbuf_;
1048        __owns_ib_ = false;
1049        __extbuf_  = new char[__ebs_];
1050        __owns_eb_ = true;
1051      } else {
1052        __ibs_     = __ebs_;
1053        __intbuf_  = new char_type[__ibs_];
1054        __owns_ib_ = true;
1055      }
1056    }
1057  }
1058}
1059
1060template <class _CharT, class _Traits>
1061bool basic_filebuf<_CharT, _Traits>::__read_mode() {
1062  if (!(__cm_ & ios_base::in)) {
1063    this->setp(nullptr, nullptr);
1064    if (__always_noconv_)
1065      this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_);
1066    else
1067      this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
1068    __cm_ = ios_base::in;
1069    return true;
1070  }
1071  return false;
1072}
1073
1074template <class _CharT, class _Traits>
1075void basic_filebuf<_CharT, _Traits>::__write_mode() {
1076  if (!(__cm_ & ios_base::out)) {
1077    this->setg(nullptr, nullptr, nullptr);
1078    if (__ebs_ > sizeof(__extbuf_min_)) {
1079      if (__always_noconv_)
1080        this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1));
1081      else
1082        this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
1083    } else
1084      this->setp(nullptr, nullptr);
1085    __cm_ = ios_base::out;
1086  }
1087}
1088
1089// basic_ifstream
1090
1091template <class _CharT, class _Traits>
1092class _LIBCPP_TEMPLATE_VIS basic_ifstream : public basic_istream<_CharT, _Traits> {
1093public:
1094  typedef _CharT char_type;
1095  typedef _Traits traits_type;
1096  typedef typename traits_type::int_type int_type;
1097  typedef typename traits_type::pos_type pos_type;
1098  typedef typename traits_type::off_type off_type;
1099#  if _LIBCPP_STD_VER >= 26
1100  using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type;
1101#  endif
1102
1103  _LIBCPP_HIDE_FROM_ABI basic_ifstream();
1104  _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in);
1105#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1106  _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
1107#  endif
1108  _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in);
1109#  if _LIBCPP_STD_VER >= 17
1110  template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>>
1111  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
1112      _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const _Tp& __p, ios_base::openmode __mode = ios_base::in)
1113      : basic_ifstream(__p.c_str(), __mode) {}
1114#  endif // _LIBCPP_STD_VER >= 17
1115  _LIBCPP_HIDE_FROM_ABI basic_ifstream(basic_ifstream&& __rhs);
1116  _LIBCPP_HIDE_FROM_ABI basic_ifstream& operator=(basic_ifstream&& __rhs);
1117  _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream& __rhs);
1118
1119  _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
1120#  if _LIBCPP_STD_VER >= 26
1121  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
1122#  endif
1123  _LIBCPP_HIDE_FROM_ABI bool is_open() const;
1124  void open(const char* __s, ios_base::openmode __mode = ios_base::in);
1125#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1126  void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
1127#  endif
1128  void open(const string& __s, ios_base::openmode __mode = ios_base::in);
1129#  if _LIBCPP_STD_VER >= 17
1130  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void
1131  open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in) {
1132    return open(__p.c_str(), __mode);
1133  }
1134#  endif // _LIBCPP_STD_VER >= 17
1135
1136  _LIBCPP_HIDE_FROM_ABI void __open(int __fd, ios_base::openmode __mode);
1137  _LIBCPP_HIDE_FROM_ABI void close();
1138
1139private:
1140  basic_filebuf<char_type, traits_type> __sb_;
1141};
1142
1143template <class _CharT, class _Traits>
1144inline basic_ifstream<_CharT, _Traits>::basic_ifstream()
1145    : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {}
1146
1147template <class _CharT, class _Traits>
1148inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
1149    : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
1150  if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
1151    this->setstate(ios_base::failbit);
1152}
1153
1154#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1155template <class _CharT, class _Traits>
1156inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const wchar_t* __s, ios_base::openmode __mode)
1157    : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
1158  if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
1159    this->setstate(ios_base::failbit);
1160}
1161#  endif
1162
1163// extension
1164template <class _CharT, class _Traits>
1165inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode)
1166    : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
1167  if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
1168    this->setstate(ios_base::failbit);
1169}
1170
1171template <class _CharT, class _Traits>
1172inline basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs)
1173    : basic_istream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1174  this->set_rdbuf(std::addressof(__sb_));
1175}
1176
1177template <class _CharT, class _Traits>
1178inline basic_ifstream<_CharT, _Traits>& basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) {
1179  basic_istream<char_type, traits_type>::operator=(std::move(__rhs));
1180  __sb_ = std::move(__rhs.__sb_);
1181  return *this;
1182}
1183
1184template <class _CharT, class _Traits>
1185inline void basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) {
1186  basic_istream<char_type, traits_type>::swap(__rhs);
1187  __sb_.swap(__rhs.__sb_);
1188}
1189
1190template <class _CharT, class _Traits>
1191inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) {
1192  __x.swap(__y);
1193}
1194
1195template <class _CharT, class _Traits>
1196inline basic_filebuf<_CharT, _Traits>* basic_ifstream<_CharT, _Traits>::rdbuf() const {
1197  return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_));
1198}
1199
1200template <class _CharT, class _Traits>
1201inline bool basic_ifstream<_CharT, _Traits>::is_open() const {
1202  return __sb_.is_open();
1203}
1204
1205template <class _CharT, class _Traits>
1206void basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) {
1207  if (__sb_.open(__s, __mode | ios_base::in))
1208    this->clear();
1209  else
1210    this->setstate(ios_base::failbit);
1211}
1212
1213#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1214template <class _CharT, class _Traits>
1215void basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
1216  if (__sb_.open(__s, __mode | ios_base::in))
1217    this->clear();
1218  else
1219    this->setstate(ios_base::failbit);
1220}
1221#  endif
1222
1223template <class _CharT, class _Traits>
1224void basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
1225  if (__sb_.open(__s, __mode | ios_base::in))
1226    this->clear();
1227  else
1228    this->setstate(ios_base::failbit);
1229}
1230
1231template <class _CharT, class _Traits>
1232inline void basic_ifstream<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) {
1233  if (__sb_.__open(__fd, __mode | ios_base::in))
1234    this->clear();
1235  else
1236    this->setstate(ios_base::failbit);
1237}
1238
1239template <class _CharT, class _Traits>
1240inline void basic_ifstream<_CharT, _Traits>::close() {
1241  if (__sb_.close() == 0)
1242    this->setstate(ios_base::failbit);
1243}
1244
1245// basic_ofstream
1246
1247template <class _CharT, class _Traits>
1248class _LIBCPP_TEMPLATE_VIS basic_ofstream : public basic_ostream<_CharT, _Traits> {
1249public:
1250  typedef _CharT char_type;
1251  typedef _Traits traits_type;
1252  typedef typename traits_type::int_type int_type;
1253  typedef typename traits_type::pos_type pos_type;
1254  typedef typename traits_type::off_type off_type;
1255#  if _LIBCPP_STD_VER >= 26
1256  using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type;
1257#  endif
1258
1259  _LIBCPP_HIDE_FROM_ABI basic_ofstream();
1260  _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out);
1261#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1262  _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
1263#  endif
1264  _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out);
1265
1266#  if _LIBCPP_STD_VER >= 17
1267  template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>>
1268  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
1269      _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const _Tp& __p, ios_base::openmode __mode = ios_base::out)
1270      : basic_ofstream(__p.c_str(), __mode) {}
1271#  endif // _LIBCPP_STD_VER >= 17
1272
1273  _LIBCPP_HIDE_FROM_ABI basic_ofstream(basic_ofstream&& __rhs);
1274  _LIBCPP_HIDE_FROM_ABI basic_ofstream& operator=(basic_ofstream&& __rhs);
1275  _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream& __rhs);
1276
1277  _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
1278#  if _LIBCPP_STD_VER >= 26
1279  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
1280#  endif
1281  _LIBCPP_HIDE_FROM_ABI bool is_open() const;
1282  void open(const char* __s, ios_base::openmode __mode = ios_base::out);
1283#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1284  void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
1285#  endif
1286  void open(const string& __s, ios_base::openmode __mode = ios_base::out);
1287
1288#  if _LIBCPP_STD_VER >= 17
1289  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void
1290  open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) {
1291    return open(__p.c_str(), __mode);
1292  }
1293#  endif // _LIBCPP_STD_VER >= 17
1294
1295  _LIBCPP_HIDE_FROM_ABI void __open(int __fd, ios_base::openmode __mode);
1296  _LIBCPP_HIDE_FROM_ABI void close();
1297
1298private:
1299  basic_filebuf<char_type, traits_type> __sb_;
1300};
1301
1302template <class _CharT, class _Traits>
1303inline basic_ofstream<_CharT, _Traits>::basic_ofstream()
1304    : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {}
1305
1306template <class _CharT, class _Traits>
1307inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
1308    : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
1309  if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
1310    this->setstate(ios_base::failbit);
1311}
1312
1313#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1314template <class _CharT, class _Traits>
1315inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const wchar_t* __s, ios_base::openmode __mode)
1316    : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
1317  if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
1318    this->setstate(ios_base::failbit);
1319}
1320#  endif
1321
1322// extension
1323template <class _CharT, class _Traits>
1324inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode)
1325    : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
1326  if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
1327    this->setstate(ios_base::failbit);
1328}
1329
1330template <class _CharT, class _Traits>
1331inline basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs)
1332    : basic_ostream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1333  this->set_rdbuf(std::addressof(__sb_));
1334}
1335
1336template <class _CharT, class _Traits>
1337inline basic_ofstream<_CharT, _Traits>& basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) {
1338  basic_ostream<char_type, traits_type>::operator=(std::move(__rhs));
1339  __sb_ = std::move(__rhs.__sb_);
1340  return *this;
1341}
1342
1343template <class _CharT, class _Traits>
1344inline void basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) {
1345  basic_ostream<char_type, traits_type>::swap(__rhs);
1346  __sb_.swap(__rhs.__sb_);
1347}
1348
1349template <class _CharT, class _Traits>
1350inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) {
1351  __x.swap(__y);
1352}
1353
1354template <class _CharT, class _Traits>
1355inline basic_filebuf<_CharT, _Traits>* basic_ofstream<_CharT, _Traits>::rdbuf() const {
1356  return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_));
1357}
1358
1359template <class _CharT, class _Traits>
1360inline bool basic_ofstream<_CharT, _Traits>::is_open() const {
1361  return __sb_.is_open();
1362}
1363
1364template <class _CharT, class _Traits>
1365void basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) {
1366  if (__sb_.open(__s, __mode | ios_base::out))
1367    this->clear();
1368  else
1369    this->setstate(ios_base::failbit);
1370}
1371
1372#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1373template <class _CharT, class _Traits>
1374void basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
1375  if (__sb_.open(__s, __mode | ios_base::out))
1376    this->clear();
1377  else
1378    this->setstate(ios_base::failbit);
1379}
1380#  endif
1381
1382template <class _CharT, class _Traits>
1383void basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
1384  if (__sb_.open(__s, __mode | ios_base::out))
1385    this->clear();
1386  else
1387    this->setstate(ios_base::failbit);
1388}
1389
1390template <class _CharT, class _Traits>
1391inline void basic_ofstream<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) {
1392  if (__sb_.__open(__fd, __mode | ios_base::out))
1393    this->clear();
1394  else
1395    this->setstate(ios_base::failbit);
1396}
1397
1398template <class _CharT, class _Traits>
1399inline void basic_ofstream<_CharT, _Traits>::close() {
1400  if (__sb_.close() == nullptr)
1401    this->setstate(ios_base::failbit);
1402}
1403
1404// basic_fstream
1405
1406template <class _CharT, class _Traits>
1407class _LIBCPP_TEMPLATE_VIS basic_fstream : public basic_iostream<_CharT, _Traits> {
1408public:
1409  typedef _CharT char_type;
1410  typedef _Traits traits_type;
1411  typedef typename traits_type::int_type int_type;
1412  typedef typename traits_type::pos_type pos_type;
1413  typedef typename traits_type::off_type off_type;
1414#  if _LIBCPP_STD_VER >= 26
1415  using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type;
1416#  endif
1417
1418  _LIBCPP_HIDE_FROM_ABI basic_fstream();
1419  _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const char* __s,
1420                                               ios_base::openmode __mode = ios_base::in | ios_base::out);
1421#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1422  _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const wchar_t* __s,
1423                                               ios_base::openmode __mode = ios_base::in | ios_base::out);
1424#  endif
1425  _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const string& __s,
1426                                               ios_base::openmode __mode = ios_base::in | ios_base::out);
1427
1428#  if _LIBCPP_STD_VER >= 17
1429  template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>>
1430  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(
1431      const _Tp& __p, ios_base::openmode __mode = ios_base::in | ios_base::out)
1432      : basic_fstream(__p.c_str(), __mode) {}
1433#  endif // _LIBCPP_STD_VER >= 17
1434
1435  _LIBCPP_HIDE_FROM_ABI basic_fstream(basic_fstream&& __rhs);
1436
1437  _LIBCPP_HIDE_FROM_ABI basic_fstream& operator=(basic_fstream&& __rhs);
1438
1439  _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream& __rhs);
1440
1441  _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const;
1442#  if _LIBCPP_STD_VER >= 26
1443  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); }
1444#  endif
1445  _LIBCPP_HIDE_FROM_ABI bool is_open() const;
1446  _LIBCPP_HIDE_FROM_ABI void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
1447#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1448  void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
1449#  endif
1450  _LIBCPP_HIDE_FROM_ABI void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
1451
1452#  if _LIBCPP_STD_VER >= 17
1453  _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void
1454  open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out) {
1455    return open(__p.c_str(), __mode);
1456  }
1457#  endif // _LIBCPP_STD_VER >= 17
1458
1459  _LIBCPP_HIDE_FROM_ABI void close();
1460
1461private:
1462  basic_filebuf<char_type, traits_type> __sb_;
1463};
1464
1465template <class _CharT, class _Traits>
1466inline basic_fstream<_CharT, _Traits>::basic_fstream()
1467    : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {}
1468
1469template <class _CharT, class _Traits>
1470inline basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
1471    : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
1472  if (__sb_.open(__s, __mode) == nullptr)
1473    this->setstate(ios_base::failbit);
1474}
1475
1476#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1477template <class _CharT, class _Traits>
1478inline basic_fstream<_CharT, _Traits>::basic_fstream(const wchar_t* __s, ios_base::openmode __mode)
1479    : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
1480  if (__sb_.open(__s, __mode) == nullptr)
1481    this->setstate(ios_base::failbit);
1482}
1483#  endif
1484
1485template <class _CharT, class _Traits>
1486inline basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode)
1487    : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
1488  if (__sb_.open(__s, __mode) == nullptr)
1489    this->setstate(ios_base::failbit);
1490}
1491
1492// extension
1493template <class _CharT, class _Traits>
1494inline basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs)
1495    : basic_iostream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) {
1496  this->set_rdbuf(std::addressof(__sb_));
1497}
1498
1499template <class _CharT, class _Traits>
1500inline basic_fstream<_CharT, _Traits>& basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) {
1501  basic_iostream<char_type, traits_type>::operator=(std::move(__rhs));
1502  __sb_ = std::move(__rhs.__sb_);
1503  return *this;
1504}
1505
1506template <class _CharT, class _Traits>
1507inline void basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) {
1508  basic_iostream<char_type, traits_type>::swap(__rhs);
1509  __sb_.swap(__rhs.__sb_);
1510}
1511
1512template <class _CharT, class _Traits>
1513inline _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) {
1514  __x.swap(__y);
1515}
1516
1517template <class _CharT, class _Traits>
1518inline basic_filebuf<_CharT, _Traits>* basic_fstream<_CharT, _Traits>::rdbuf() const {
1519  return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_));
1520}
1521
1522template <class _CharT, class _Traits>
1523inline bool basic_fstream<_CharT, _Traits>::is_open() const {
1524  return __sb_.is_open();
1525}
1526
1527template <class _CharT, class _Traits>
1528void basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) {
1529  if (__sb_.open(__s, __mode))
1530    this->clear();
1531  else
1532    this->setstate(ios_base::failbit);
1533}
1534
1535#  if _LIBCPP_HAS_OPEN_WITH_WCHAR
1536template <class _CharT, class _Traits>
1537void basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
1538  if (__sb_.open(__s, __mode))
1539    this->clear();
1540  else
1541    this->setstate(ios_base::failbit);
1542}
1543#  endif
1544
1545template <class _CharT, class _Traits>
1546void basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) {
1547  if (__sb_.open(__s, __mode))
1548    this->clear();
1549  else
1550    this->setstate(ios_base::failbit);
1551}
1552
1553template <class _CharT, class _Traits>
1554inline void basic_fstream<_CharT, _Traits>::close() {
1555  if (__sb_.close() == nullptr)
1556    this->setstate(ios_base::failbit);
1557}
1558
1559#  if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
1560extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>;
1561extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>;
1562extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;
1563#  endif
1564
1565_LIBCPP_END_NAMESPACE_STD
1566
1567#endif // _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
1568
1569_LIBCPP_POP_MACROS
1570
1571#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1572#  include <atomic>
1573#  include <concepts>
1574#  include <cstdlib>
1575#  include <iosfwd>
1576#  include <limits>
1577#  include <mutex>
1578#  include <new>
1579#  include <stdexcept>
1580#  include <type_traits>
1581#endif
1582
1583#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
1584#  include <filesystem>
1585#endif
1586
1587#endif // _LIBCPP_FSTREAM
1588