From Jason Turner

[file.streams]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5ngg5ocj/{from.md → to.md} +110 -139
tmp/tmp5ngg5ocj/{from.md → to.md} RENAMED
@@ -34,13 +34,13 @@ files.
34
  or sink of bytes. In an environment that uses a large character set, the
35
  file typically holds multibyte character sequences and the
36
  `basic_filebuf` object converts those multibyte sequences into wide
37
  character sequences. — *end note*]
38
 
39
- In this subclause, member functions taking arguments of
40
  `const filesystem::path::value_type*` are only be provided on systems
41
- where `filesystem::path::value_type` ([[fs.class.path]]) is not `char`.
42
 
43
  [*Note 2*: These functions enable class `path` support for systems with
44
  a wide native path character type, such as `wchar_t`. — *end note*]
45
 
46
  ### Class template `basic_filebuf` <a id="filebuf">[[filebuf]]</a>
@@ -56,16 +56,16 @@ namespace std {
56
  using off_type = typename traits::off_type;
57
  using traits_type = traits;
58
 
59
  // [filebuf.cons], constructors/destructor
60
  basic_filebuf();
61
- basic_filebuf(const basic_filebuf& rhs) = delete;
62
  basic_filebuf(basic_filebuf&& rhs);
63
  virtual ~basic_filebuf();
64
 
65
  // [filebuf.assign], assign and swap
66
- basic_filebuf& operator=(const basic_filebuf& rhs) = delete;
67
  basic_filebuf& operator=(basic_filebuf&& rhs);
68
  void swap(basic_filebuf& rhs);
69
 
70
  // [filebuf.members], members
71
  bool is_open() const;
@@ -123,45 +123,44 @@ An instance of `basic_filebuf` behaves as described in  [[filebuf]]
123
  provided `traits::pos_type` is `fpos<traits::{}state_type>`. Otherwise
124
  the behavior is undefined.
125
 
126
  In order to support file I/O and multibyte/wide character conversion,
127
  conversions are performed using members of a facet, referred to as
128
- `a_codecvt` in following sections, obtained as if by
129
 
130
  ``` cpp
131
  const codecvt<charT, char, typename traits::state_type>& a_codecvt =
132
  use_facet<codecvt<charT, char, typename traits::state_type>>(getloc());
133
  ```
134
 
135
- #### `basic_filebuf` constructors <a id="filebuf.cons">[[filebuf.cons]]</a>
136
 
137
  ``` cpp
138
  basic_filebuf();
139
  ```
140
 
141
- *Effects:* Constructs an object of class `basic_filebuf<charT, traits>`,
142
- initializing the base class with
143
- `basic_streambuf<charT, traits>()` ([[streambuf.cons]]).
144
 
145
- *Postconditions:* `is_open() == false`.
146
 
147
  ``` cpp
148
  basic_filebuf(basic_filebuf&& rhs);
149
  ```
150
 
151
- *Effects:* Move constructs from the rvalue `rhs`. It is
152
- *implementation-defined* whether the sequence pointers in `*this`
153
- (`eback()`, `gptr()`, `egptr()`, `pbase()`, `pptr()`, `epptr()`) obtain
154
- the values which `rhs` had. Whether they do or not, `*this` and `rhs`
155
- reference separate buffers (if any at all) after the construction.
156
- Additionally `*this` references the file which `rhs` did before the
157
- construction, and `rhs` references no file after the construction. The
158
- openmode, locale and any other state of `rhs` is also copied.
159
 
160
- *Postconditions:* Let `rhs_p` refer to the state of `rhs` just prior to
161
- this construction and let `rhs_a` refer to the state of `rhs` just after
162
- this construction.
163
 
164
  - `is_open() == rhs_p.is_open()`
165
  - `rhs_a.is_open() == false`
166
  - `gptr() - eback() == rhs_p.gptr() - rhs_p.eback()`
167
  - `egptr() - eback() == rhs_p.egptr() - rhs_p.eback()`
@@ -176,16 +175,16 @@ this construction.
176
 
177
  ``` cpp
178
  virtual ~basic_filebuf();
179
  ```
180
 
181
- *Effects:* Destroys an object of class `basic_filebuf<charT, traits>`.
182
- Calls `close()`. If an exception occurs during the destruction of the
183
- object, including the call to `close()`, the exception is caught but not
184
- rethrown (see  [[res.on.exception.handling]]).
185
 
186
- #### Assign and swap <a id="filebuf.assign">[[filebuf.assign]]</a>
187
 
188
  ``` cpp
189
  basic_filebuf& operator=(basic_filebuf&& rhs);
190
  ```
191
 
@@ -205,11 +204,11 @@ void swap(basic_filebuf& rhs);
205
  template<class charT, class traits>
206
  void swap(basic_filebuf<charT, traits>& x,
207
  basic_filebuf<charT, traits>& y);
208
  ```
209
 
210
- *Effects:* As if by `x.swap(y)`.
211
 
212
  #### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
213
 
214
  ``` cpp
215
  bool is_open() const;
@@ -222,19 +221,20 @@ non-null value) and there has been no intervening call to close.
222
  basic_filebuf* open(const char* s, ios_base::openmode mode);
223
  basic_filebuf* open(const filesystem::path::value_type* s,
224
  ios_base::openmode mode); // wide systems only; see [fstream.syn]
225
  ```
226
 
 
 
227
  *Effects:* If `is_open() != false`, returns a null pointer. Otherwise,
228
- initializes the `filebuf` as required. It then opens a file, if
229
- possible, whose name is the NTBS`s` (as if by calling
230
- `fopen(s, modstr)`). The NTBS`modstr` is determined from
231
- `mode & ~ios_base::ate` as indicated in
232
- Table  [[tab:iostreams.file.open.modes]]. If `mode` is not some
233
- combination of flags shown in the table then the open fails.
234
 
235
- **Table: File open modes** <a id="tab:iostreams.file.open.modes">[tab:iostreams.file.open.modes]</a>
236
 
237
  | `binary` | `in` | `out` | `trunc` | `app` | | `stdio` equivalent |
238
  | -------- | ---- | ----- | ------- | ----- | --- | ------------------ |
239
  | | | + | | | `"w"` |
240
  | | | + | | + | `"a"` |
@@ -253,13 +253,14 @@ combination of flags shown in the table then the open fails.
253
  | + | + | + | + | | `"w+b"` |
254
  | + | + | + | | + | `"a+b"` |
255
  | + | + | | | + | `"a+b"` |
256
 
257
 
258
- If the open operation succeeds and `(mode & ios_base::ate) != 0`,
259
  positions the file to the end (as if by calling
260
- `fseek(file, 0, SEEK_END)`).[^40]
 
261
 
262
  If the repositioning operation fails, calls `close()` and returns a null
263
  pointer to indicate failure.
264
 
265
  *Returns:* `this` if successful, a null pointer otherwise.
@@ -288,20 +289,20 @@ or throws an exception, the function closes the file (as if by calling
288
  these calls throws an exception, the exception is caught and rethrown
289
  after closing the file.
290
 
291
  *Returns:* `this` on success, a null pointer otherwise.
292
 
293
- *Postconditions:* `is_open() == false`.
294
 
295
  #### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
296
 
297
  ``` cpp
298
  streamsize showmanyc() override;
299
  ```
300
 
301
- *Effects:* Behaves the same as
302
- `basic_streambuf::showmanyc()` ([[streambuf.virtuals]]).
303
 
304
  *Remarks:* An implementation might well provide an overriding definition
305
  for this function signature if it can determine that more characters can
306
  be read from the input sequence.
307
 
@@ -358,11 +359,11 @@ sequence, if possible, in one of three ways:
358
  either the input sequence has a putback position available or the
359
  function makes a putback position available, decrements the next
360
  pointer for the input sequence, `gptr()`. Returns:
361
  `traits::not_eof(c)`.
362
 
363
- *Returns:* `traits::eof()` to indicate failure.
364
 
365
  *Remarks:* If `is_open() == false`, the function always fails.
366
 
367
  The function does not put back a character directly to the input
368
  sequence.
@@ -432,13 +433,13 @@ and write any unshift sequence. Next, seek to the new position: if
432
  operation was overflow or the put buffer is non-empty. “Write any
433
  unshift sequence” means, if `width` if less than zero then call
434
  `a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
435
  resulting unshift sequence. The function determines one of three values
436
  for the argument `whence`, of type `int`, as indicated in
437
- Table  [[tab:iostreams.seekoff.effects]].
438
 
439
- **Table: `seekoff` effects** <a id="tab:iostreams.seekoff.effects">[tab:iostreams.seekoff.effects]</a>
440
 
441
  | `way` Value | `stdio` Equivalent |
442
  | ---------------- | ------------------ |
443
  | `basic_ios::beg` | `SEEK_SET` |
444
  | `basic_ios::cur` | `SEEK_CUR` |
@@ -487,13 +488,13 @@ characters to the file, then flushes the file as if by calling
487
 
488
  ``` cpp
489
  void imbue(const locale& loc) override;
490
  ```
491
 
492
- *Requires:* If the file is not positioned at its beginning and the
493
  encoding of the current locale as determined by `a_codecvt.encoding()`
494
- is state-dependent ([[locale.codecvt.virtuals]]) then that facet is the
495
  same as the corresponding facet of `loc`.
496
 
497
  *Effects:* Causes characters inserted or extracted after this call to be
498
  converted according to `loc` until another call of `imbue`.
499
 
@@ -522,15 +523,15 @@ namespace std {
522
  ios_base::openmode mode = ios_base::in);// wide systems only; see [fstream.syn]
523
  explicit basic_ifstream(const string& s,
524
  ios_base::openmode mode = ios_base::in);
525
  explicit basic_ifstream(const filesystem::path& s,
526
  ios_base::openmode mode = ios_base::in);
527
- basic_ifstream(const basic_ifstream& rhs) = delete;
528
  basic_ifstream(basic_ifstream&& rhs);
529
 
530
  // [ifstream.assign], assign and swap
531
- basic_ifstream& operator=(const basic_ifstream& rhs) = delete;
532
  basic_ifstream& operator=(basic_ifstream&& rhs);
533
  void swap(basic_ifstream& rhs);
534
 
535
  // [ifstream.members], members
536
  basic_filebuf<charT, traits>* rdbuf() const;
@@ -557,62 +558,52 @@ files. It uses a `basic_filebuf<{}charT, traits>` object to control the
557
  associated sequence. For the sake of exposition, the maintained data is
558
  presented here as:
559
 
560
  - `sb`, the `filebuf` object.
561
 
562
- #### `basic_ifstream` constructors <a id="ifstream.cons">[[ifstream.cons]]</a>
563
 
564
  ``` cpp
565
  basic_ifstream();
566
  ```
567
 
568
- *Effects:* Constructs an object of class
569
- `basic_ifstream<charT, traits>`, initializing the base class with
570
- `basic_istream(&sb)` and initializing `sb` with
571
- `basic_filebuf<charT, traits>())` ([[istream.cons]], [[filebuf.cons]]).
572
 
573
  ``` cpp
574
  explicit basic_ifstream(const char* s,
575
  ios_base::openmode mode = ios_base::in);
576
  explicit basic_ifstream(const filesystem::path::value_type* s,
577
  ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
578
  ```
579
 
580
- *Effects:* Constructs an object of class `basic_ifstream`, initializing
581
- the base class with `basic_istream(&sb)` and initializing `sb` with
582
- `basic_filebuf<charT, traits>())` ([[istream.cons]], [[filebuf.cons]]),
583
- then calls `rdbuf()->open(s, mode | ios_base::in)`. If that function
584
- returns a null pointer, calls `setstate(failbit)`.
585
 
586
  ``` cpp
587
  explicit basic_ifstream(const string& s,
588
  ios_base::openmode mode = ios_base::in);
589
  explicit basic_ifstream(const filesystem::path& s,
590
  ios_base::openmode mode = ios_base::in);
591
  ```
592
 
593
- *Effects:* The same as `basic_ifstream(s.c_str(), mode)`.
594
 
595
  ``` cpp
596
  basic_ifstream(basic_ifstream&& rhs);
597
  ```
598
 
599
- *Effects:* Move constructs from the rvalue `rhs`. This is accomplished
600
- by move constructing the base class, and the contained `basic_filebuf`.
601
- Next `basic_istream<charT, traits>::set_rdbuf(&sb)` is called to install
602
- the contained `basic_filebuf`.
603
 
604
- #### Assign and swap <a id="ifstream.assign">[[ifstream.assign]]</a>
605
-
606
- ``` cpp
607
- basic_ifstream& operator=(basic_ifstream&& rhs);
608
- ```
609
-
610
- *Effects:* Move assigns the base and members of `*this` from the base
611
- and corresponding members of `rhs`.
612
-
613
- *Returns:* `*this`.
614
 
615
  ``` cpp
616
  void swap(basic_ifstream& rhs);
617
  ```
618
 
@@ -623,19 +614,19 @@ void swap(basic_ifstream& rhs);
623
  template<class charT, class traits>
624
  void swap(basic_ifstream<charT, traits>& x,
625
  basic_ifstream<charT, traits>& y);
626
  ```
627
 
628
- *Effects:* As if by `x.swap(y)`.
629
 
630
  #### Member functions <a id="ifstream.members">[[ifstream.members]]</a>
631
 
632
  ``` cpp
633
  basic_filebuf<charT, traits>* rdbuf() const;
634
  ```
635
 
636
- *Returns:* `const_cast<basic_filebuf<charT, traits>*>(&sb)`.
637
 
638
  ``` cpp
639
  bool is_open() const;
640
  ```
641
 
@@ -647,12 +638,12 @@ void open(const filesystem::path::value_type* s,
647
  ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
648
  ```
649
 
650
  *Effects:* Calls `rdbuf()->open(s, mode | ios_base::in)`. If that
651
  function does not return a null pointer calls `clear()`, otherwise calls
652
- `setstate(failbit)` (which may throw `ios_base::failure`)
653
- ([[iostate.flags]]).
654
 
655
  ``` cpp
656
  void open(const string& s, ios_base::openmode mode = ios_base::in);
657
  void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
658
  ```
@@ -663,11 +654,11 @@ void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
663
  void close();
664
  ```
665
 
666
  *Effects:* Calls `rdbuf()->close()` and, if that function returns a null
667
  pointer, calls `setstate(failbit)` (which may throw
668
- `ios_base::failure`) ([[iostate.flags]]).
669
 
670
  ### Class template `basic_ofstream` <a id="ofstream">[[ofstream]]</a>
671
 
672
  ``` cpp
673
  namespace std {
@@ -682,21 +673,21 @@ namespace std {
682
 
683
  // [ofstream.cons], constructors
684
  basic_ofstream();
685
  explicit basic_ofstream(const char* s,
686
  ios_base::openmode mode = ios_base::out);
687
- explicit basic_ofstream(const filesystem::path::value_type* s,
688
- ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
689
  explicit basic_ofstream(const string& s,
690
  ios_base::openmode mode = ios_base::out);
691
  explicit basic_ofstream(const filesystem::path& s,
692
  ios_base::openmode mode = ios_base::out);
693
- basic_ofstream(const basic_ofstream& rhs) = delete;
694
  basic_ofstream(basic_ofstream&& rhs);
695
 
696
  // [ofstream.assign], assign and swap
697
- basic_ofstream& operator=(const basic_ofstream& rhs) = delete;
698
  basic_ofstream& operator=(basic_ofstream&& rhs);
699
  void swap(basic_ofstream& rhs);
700
 
701
  // [ofstream.members], members
702
  basic_filebuf<charT, traits>* rdbuf() const;
@@ -723,63 +714,52 @@ files. It uses a `basic_filebuf<{}charT, traits>` object to control the
723
  associated sequence. For the sake of exposition, the maintained data is
724
  presented here as:
725
 
726
  - `sb`, the `filebuf` object.
727
 
728
- #### `basic_ofstream` constructors <a id="ofstream.cons">[[ofstream.cons]]</a>
729
 
730
  ``` cpp
731
  basic_ofstream();
732
  ```
733
 
734
- *Effects:* Constructs an object of class
735
- `basic_ofstream<charT, traits>`, initializing the base class with
736
- `basic_ostream(&sb)` and initializing `sb` with
737
- `basic_filebuf<charT, traits>())` ([[ostream.cons]], [[filebuf.cons]]).
738
 
739
  ``` cpp
740
  explicit basic_ofstream(const char* s,
741
  ios_base::openmode mode = ios_base::out);
742
  explicit basic_ofstream(const filesystem::path::value_type* s,
743
  ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
744
  ```
745
 
746
- *Effects:* Constructs an object of class
747
- `basic_ofstream<charT, traits>`, initializing the base class with
748
- `basic_ostream(&sb)` and initializing `sb` with
749
- `basic_filebuf<charT, traits>())` ([[ostream.cons]], [[filebuf.cons]]),
750
- then calls `rdbuf()->open(s, mode | ios_base::out)`. If that function
751
- returns a null pointer, calls `setstate(failbit)`.
752
 
753
  ``` cpp
754
  explicit basic_ofstream(const string& s,
755
  ios_base::openmode mode = ios_base::out);
756
  explicit basic_ofstream(const filesystem::path& s,
757
  ios_base::openmode mode = ios_base::out);
758
  ```
759
 
760
- *Effects:* The same as `basic_ofstream(s.c_str(), mode)`.
761
 
762
  ``` cpp
763
  basic_ofstream(basic_ofstream&& rhs);
764
  ```
765
 
766
- *Effects:* Move constructs from the rvalue `rhs`. This is accomplished
767
- by move constructing the base class, and the contained `basic_filebuf`.
768
- Next `basic_ostream<charT, traits>::set_rdbuf(&sb)` is called to install
769
- the contained `basic_filebuf`.
770
 
771
- #### Assign and swap <a id="ofstream.assign">[[ofstream.assign]]</a>
772
-
773
- ``` cpp
774
- basic_ofstream& operator=(basic_ofstream&& rhs);
775
- ```
776
-
777
- *Effects:* Move assigns the base and members of `*this` from the base
778
- and corresponding members of `rhs`.
779
-
780
- *Returns:* `*this`.
781
 
782
  ``` cpp
783
  void swap(basic_ofstream& rhs);
784
  ```
785
 
@@ -790,19 +770,19 @@ void swap(basic_ofstream& rhs);
790
  template<class charT, class traits>
791
  void swap(basic_ofstream<charT, traits>& x,
792
  basic_ofstream<charT, traits>& y);
793
  ```
794
 
795
- *Effects:* As if by `x.swap(y)`.
796
 
797
  #### Member functions <a id="ofstream.members">[[ofstream.members]]</a>
798
 
799
  ``` cpp
800
  basic_filebuf<charT, traits>* rdbuf() const;
801
  ```
802
 
803
- *Returns:* `const_cast<basic_filebuf<charT, traits>*>(&sb)`.
804
 
805
  ``` cpp
806
  bool is_open() const;
807
  ```
808
 
@@ -814,20 +794,20 @@ void open(const filesystem::path::value_type* s,
814
  ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
815
  ```
816
 
817
  *Effects:* Calls `rdbuf()->open(s, mode | ios_base::out)`. If that
818
  function does not return a null pointer calls `clear()`, otherwise calls
819
- `setstate(failbit)` (which may throw `ios_base::failure`)
820
- ([[iostate.flags]]).
821
 
822
  ``` cpp
823
  void close();
824
  ```
825
 
826
  *Effects:* Calls `rdbuf()->close()` and, if that function fails (returns
827
  a null pointer), calls `setstate(failbit)` (which may throw
828
- `ios_base::failure`) ([[iostate.flags]]).
829
 
830
  ``` cpp
831
  void open(const string& s, ios_base::openmode mode = ios_base::out);
832
  void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
833
  ```
@@ -851,34 +831,34 @@ namespace std {
851
  basic_fstream();
852
  explicit basic_fstream(
853
  const char* s,
854
  ios_base::openmode mode = ios_base::in | ios_base::out);
855
  explicit basic_fstream(
856
- const std::filesystem::path::value_type* s,
857
  ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
858
  explicit basic_fstream(
859
  const string& s,
860
  ios_base::openmode mode = ios_base::in | ios_base::out);
861
  explicit basic_fstream(
862
  const filesystem::path& s,
863
  ios_base::openmode mode = ios_base::in | ios_base::out);
864
- basic_fstream(const basic_fstream& rhs) = delete;
865
  basic_fstream(basic_fstream&& rhs);
866
 
867
  // [fstream.assign], assign and swap
868
- basic_fstream& operator=(const basic_fstream& rhs) = delete;
869
  basic_fstream& operator=(basic_fstream&& rhs);
870
  void swap(basic_fstream& rhs);
871
 
872
  // [fstream.members], members
873
  basic_filebuf<charT, traits>* rdbuf() const;
874
  bool is_open() const;
875
  void open(
876
  const char* s,
877
  ios_base::openmode mode = ios_base::in | ios_base::out);
878
  void open(
879
- const std::filesystem::path::value_type* s,
880
  ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
881
  void open(
882
  const string& s,
883
  ios_base::openmode mode = ios_base::in | ios_base::out);
884
  void open(
@@ -901,18 +881,18 @@ writing from named files. It uses a `basic_filebuf<charT, traits>`
901
  object to control the associated sequences. For the sake of exposition,
902
  the maintained data is presented here as:
903
 
904
  - `sb`, the `basic_filebuf` object.
905
 
906
- #### `basic_fstream` constructors <a id="fstream.cons">[[fstream.cons]]</a>
907
 
908
  ``` cpp
909
  basic_fstream();
910
  ```
911
 
912
- *Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
913
- initializing the base class with `basic_iostream(&sb)` and initializing
914
  `sb` with `basic_filebuf<charT, traits>()`.
915
 
916
  ``` cpp
917
  explicit basic_fstream(
918
  const char* s,
@@ -920,12 +900,12 @@ explicit basic_fstream(
920
  explicit basic_fstream(
921
  const filesystem::path::value_type* s,
922
  ios_base::openmode mode = ios_base::in | ios_base::out); // wide systems only; see [fstream.syn]
923
  ```
924
 
925
- *Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
926
- initializing the base class with `basic_iostream(&sb)` and initializing
927
  `sb` with `basic_filebuf<charT, traits>()`. Then calls
928
  `rdbuf()->open(s, mode)`. If that function returns a null pointer, calls
929
  `setstate(failbit)`.
930
 
931
  ``` cpp
@@ -935,31 +915,22 @@ explicit basic_fstream(
935
  explicit basic_fstream(
936
  const filesystem::path& s,
937
  ios_base::openmode mode = ios_base::in | ios_base::out);
938
  ```
939
 
940
- *Effects:* The same as `basic_fstream(s.c_str(), mode)`.
941
 
942
  ``` cpp
943
  basic_fstream(basic_fstream&& rhs);
944
  ```
945
 
946
- *Effects:* Move constructs from the rvalue `rhs`. This is accomplished
947
- by move constructing the base class, and the contained `basic_filebuf`.
948
- Next `basic_istream<charT, traits>::set_rdbuf(&sb)` is called to install
949
- the contained `basic_filebuf`.
950
 
951
- #### Assign and swap <a id="fstream.assign">[[fstream.assign]]</a>
952
-
953
- ``` cpp
954
- basic_fstream& operator=(basic_fstream&& rhs);
955
- ```
956
-
957
- *Effects:* Move assigns the base and members of `*this` from the base
958
- and corresponding members of `rhs`.
959
-
960
- *Returns:* `*this`.
961
 
962
  ``` cpp
963
  void swap(basic_fstream& rhs);
964
  ```
965
 
@@ -970,19 +941,19 @@ void swap(basic_fstream& rhs);
970
  template<class charT, class traits>
971
  void swap(basic_fstream<charT, traits>& x,
972
  basic_fstream<charT, traits>& y);
973
  ```
974
 
975
- *Effects:* As if by `x.swap(y)`.
976
 
977
  #### Member functions <a id="fstream.members">[[fstream.members]]</a>
978
 
979
  ``` cpp
980
  basic_filebuf<charT, traits>* rdbuf() const;
981
  ```
982
 
983
- *Returns:* `const_cast<basic_filebuf<charT, traits>*>(&sb)`.
984
 
985
  ``` cpp
986
  bool is_open() const;
987
  ```
988
 
@@ -998,11 +969,11 @@ void open(
998
  ```
999
 
1000
  *Effects:* Calls `rdbuf()->open(s, mode)`. If that function does not
1001
  return a null pointer calls `clear()`, otherwise calls
1002
  `setstate(failbit)` (which may throw
1003
- `ios_base::failure`) ([[iostate.flags]]).
1004
 
1005
  ``` cpp
1006
  void open(
1007
  const string& s,
1008
  ios_base::openmode mode = ios_base::in | ios_base::out);
@@ -1017,7 +988,7 @@ void open(
1017
  void close();
1018
  ```
1019
 
1020
  *Effects:* Calls `rdbuf()->close()` and, if that function returns a null
1021
  pointer, calls `setstate(failbit)` (which may throw
1022
- `ios_base::failure`) ([[iostate.flags]]).
1023
 
 
34
  or sink of bytes. In an environment that uses a large character set, the
35
  file typically holds multibyte character sequences and the
36
  `basic_filebuf` object converts those multibyte sequences into wide
37
  character sequences. — *end note*]
38
 
39
+ In subclause  [[file.streams]], member functions taking arguments of
40
  `const filesystem::path::value_type*` are only be provided on systems
41
+ where `filesystem::path::value_type` [[fs.class.path]] is not `char`.
42
 
43
  [*Note 2*: These functions enable class `path` support for systems with
44
  a wide native path character type, such as `wchar_t`. — *end note*]
45
 
46
  ### Class template `basic_filebuf` <a id="filebuf">[[filebuf]]</a>
 
56
  using off_type = typename traits::off_type;
57
  using traits_type = traits;
58
 
59
  // [filebuf.cons], constructors/destructor
60
  basic_filebuf();
61
+ basic_filebuf(const basic_filebuf&) = delete;
62
  basic_filebuf(basic_filebuf&& rhs);
63
  virtual ~basic_filebuf();
64
 
65
  // [filebuf.assign], assign and swap
66
+ basic_filebuf& operator=(const basic_filebuf&) = delete;
67
  basic_filebuf& operator=(basic_filebuf&& rhs);
68
  void swap(basic_filebuf& rhs);
69
 
70
  // [filebuf.members], members
71
  bool is_open() const;
 
123
  provided `traits::pos_type` is `fpos<traits::{}state_type>`. Otherwise
124
  the behavior is undefined.
125
 
126
  In order to support file I/O and multibyte/wide character conversion,
127
  conversions are performed using members of a facet, referred to as
128
+ `a_codecvt` in following subclauses, obtained as if by
129
 
130
  ``` cpp
131
  const codecvt<charT, char, typename traits::state_type>& a_codecvt =
132
  use_facet<codecvt<charT, char, typename traits::state_type>>(getloc());
133
  ```
134
 
135
+ #### Constructors <a id="filebuf.cons">[[filebuf.cons]]</a>
136
 
137
  ``` cpp
138
  basic_filebuf();
139
  ```
140
 
141
+ *Effects:* Initializes the base class with
142
+ `basic_streambuf<charT, traits>()` [[streambuf.cons]].
 
143
 
144
+ *Ensures:* `is_open() == false`.
145
 
146
  ``` cpp
147
  basic_filebuf(basic_filebuf&& rhs);
148
  ```
149
 
150
+ *Effects:* It is *implementation-defined* whether the sequence pointers
151
+ in `*this` (`eback()`, `gptr()`, `egptr()`, `pbase()`, `pptr()`,
152
+ `epptr()`) obtain the values which `rhs` had. Whether they do or not,
153
+ `*this` and `rhs` reference separate buffers (if any at all) after the
154
+ construction. Additionally `*this` references the file which `rhs` did
155
+ before the construction, and `rhs` references no file after the
156
+ construction. The openmode, locale and any other state of `rhs` is also
157
+ copied.
158
 
159
+ *Ensures:* Let `rhs_p` refer to the state of `rhs` just prior to this
160
+ construction and let `rhs_a` refer to the state of `rhs` just after this
161
+ construction.
162
 
163
  - `is_open() == rhs_p.is_open()`
164
  - `rhs_a.is_open() == false`
165
  - `gptr() - eback() == rhs_p.gptr() - rhs_p.eback()`
166
  - `egptr() - eback() == rhs_p.egptr() - rhs_p.eback()`
 
175
 
176
  ``` cpp
177
  virtual ~basic_filebuf();
178
  ```
179
 
180
+ *Effects:* Calls `close()`. If an exception occurs during the
181
+ destruction of the object, including the call to `close()`, the
182
+ exception is caught but not rethrown
183
+ (see  [[res.on.exception.handling]]).
184
 
185
+ #### Assignment and swap <a id="filebuf.assign">[[filebuf.assign]]</a>
186
 
187
  ``` cpp
188
  basic_filebuf& operator=(basic_filebuf&& rhs);
189
  ```
190
 
 
204
  template<class charT, class traits>
205
  void swap(basic_filebuf<charT, traits>& x,
206
  basic_filebuf<charT, traits>& y);
207
  ```
208
 
209
+ *Effects:* Equivalent to: `x.swap(y)`.
210
 
211
  #### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
212
 
213
  ``` cpp
214
  bool is_open() const;
 
221
  basic_filebuf* open(const char* s, ios_base::openmode mode);
222
  basic_filebuf* open(const filesystem::path::value_type* s,
223
  ios_base::openmode mode); // wide systems only; see [fstream.syn]
224
  ```
225
 
226
+ *Preconditions:* `s` points to a NTCTS [[defns.ntcts]].
227
+
228
  *Effects:* If `is_open() != false`, returns a null pointer. Otherwise,
229
+ initializes the `filebuf` as required. It then opens the file to which
230
+ `s` resolves, if possible, as if by a call to `fopen` with the second
231
+ argument determined from `mode & ~ios_base::ate` as indicated in
232
+ [[filebuf.open.modes]]. If `mode` is not some combination of flags shown
233
+ in the table then the open fails.
 
234
 
235
+ **Table: File open modes** <a id="filebuf.open.modes">[filebuf.open.modes]</a>
236
 
237
  | `binary` | `in` | `out` | `trunc` | `app` | | `stdio` equivalent |
238
  | -------- | ---- | ----- | ------- | ----- | --- | ------------------ |
239
  | | | + | | | `"w"` |
240
  | | | + | | + | `"a"` |
 
253
  | + | + | + | + | | `"w+b"` |
254
  | + | + | + | | + | `"a+b"` |
255
  | + | + | | | + | `"a+b"` |
256
 
257
 
258
+ If the open operation succeeds and `ios_base::ate` is set in `mode`,
259
  positions the file to the end (as if by calling
260
+ `fseek(file, 0, SEEK_END)`, where `file` is the pointer returned by
261
+ calling `fopen`). [^40]
262
 
263
  If the repositioning operation fails, calls `close()` and returns a null
264
  pointer to indicate failure.
265
 
266
  *Returns:* `this` if successful, a null pointer otherwise.
 
289
  these calls throws an exception, the exception is caught and rethrown
290
  after closing the file.
291
 
292
  *Returns:* `this` on success, a null pointer otherwise.
293
 
294
+ *Ensures:* `is_open() == false`.
295
 
296
  #### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
297
 
298
  ``` cpp
299
  streamsize showmanyc() override;
300
  ```
301
 
302
+ *Effects:* Behaves the same as `basic_streambuf::showmanyc()`
303
+ [[streambuf.virtuals]].
304
 
305
  *Remarks:* An implementation might well provide an overriding definition
306
  for this function signature if it can determine that more characters can
307
  be read from the input sequence.
308
 
 
359
  either the input sequence has a putback position available or the
360
  function makes a putback position available, decrements the next
361
  pointer for the input sequence, `gptr()`. Returns:
362
  `traits::not_eof(c)`.
363
 
364
+ *Returns:* As specified above, or `traits::eof()` to indicate failure.
365
 
366
  *Remarks:* If `is_open() == false`, the function always fails.
367
 
368
  The function does not put back a character directly to the input
369
  sequence.
 
433
  operation was overflow or the put buffer is non-empty. “Write any
434
  unshift sequence” means, if `width` if less than zero then call
435
  `a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
436
  resulting unshift sequence. The function determines one of three values
437
  for the argument `whence`, of type `int`, as indicated in
438
+ [[filebuf.seekoff]].
439
 
440
+ **Table: `seekoff` effects** <a id="filebuf.seekoff">[filebuf.seekoff]</a>
441
 
442
  | `way` Value | `stdio` Equivalent |
443
  | ---------------- | ------------------ |
444
  | `basic_ios::beg` | `SEEK_SET` |
445
  | `basic_ios::cur` | `SEEK_CUR` |
 
488
 
489
  ``` cpp
490
  void imbue(const locale& loc) override;
491
  ```
492
 
493
+ *Preconditions:* If the file is not positioned at its beginning and the
494
  encoding of the current locale as determined by `a_codecvt.encoding()`
495
+ is state-dependent [[locale.codecvt.virtuals]] then that facet is the
496
  same as the corresponding facet of `loc`.
497
 
498
  *Effects:* Causes characters inserted or extracted after this call to be
499
  converted according to `loc` until another call of `imbue`.
500
 
 
523
  ios_base::openmode mode = ios_base::in);// wide systems only; see [fstream.syn]
524
  explicit basic_ifstream(const string& s,
525
  ios_base::openmode mode = ios_base::in);
526
  explicit basic_ifstream(const filesystem::path& s,
527
  ios_base::openmode mode = ios_base::in);
528
+ basic_ifstream(const basic_ifstream&) = delete;
529
  basic_ifstream(basic_ifstream&& rhs);
530
 
531
  // [ifstream.assign], assign and swap
532
+ basic_ifstream& operator=(const basic_ifstream&) = delete;
533
  basic_ifstream& operator=(basic_ifstream&& rhs);
534
  void swap(basic_ifstream& rhs);
535
 
536
  // [ifstream.members], members
537
  basic_filebuf<charT, traits>* rdbuf() const;
 
558
  associated sequence. For the sake of exposition, the maintained data is
559
  presented here as:
560
 
561
  - `sb`, the `filebuf` object.
562
 
563
+ #### Constructors <a id="ifstream.cons">[[ifstream.cons]]</a>
564
 
565
  ``` cpp
566
  basic_ifstream();
567
  ```
568
 
569
+ *Effects:* Initializes the base class with
570
+ `basic_istream<charT, traits>(addressof(sb))` [[istream.cons]] and `sb`
571
+ with `basic_filebuf<charT, traits>()` [[filebuf.cons]].
 
572
 
573
  ``` cpp
574
  explicit basic_ifstream(const char* s,
575
  ios_base::openmode mode = ios_base::in);
576
  explicit basic_ifstream(const filesystem::path::value_type* s,
577
  ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
578
  ```
579
 
580
+ *Effects:* Initializes the base class with
581
+ `basic_istream<charT, traits>(addressof(sb))` [[istream.cons]] and `sb`
582
+ with `basic_filebuf<charT, traits>()` [[filebuf.cons]], then calls
583
+ `rdbuf()->open(s, mode | ios_base::in)`. If that function returns a null
584
+ pointer, calls `setstate(failbit)`.
585
 
586
  ``` cpp
587
  explicit basic_ifstream(const string& s,
588
  ios_base::openmode mode = ios_base::in);
589
  explicit basic_ifstream(const filesystem::path& s,
590
  ios_base::openmode mode = ios_base::in);
591
  ```
592
 
593
+ *Effects:* Equivalent to: `basic_ifstream(s.c_str(), mode)`.
594
 
595
  ``` cpp
596
  basic_ifstream(basic_ifstream&& rhs);
597
  ```
598
 
599
+ *Effects:* Move constructs the base class, and the contained
600
+ `basic_filebuf`. Then calls
601
+ `basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
602
+ contained `basic_filebuf`.
603
 
604
+ #### Assignment and swap <a id="ifstream.assign">[[ifstream.assign]]</a>
 
 
 
 
 
 
 
 
 
605
 
606
  ``` cpp
607
  void swap(basic_ifstream& rhs);
608
  ```
609
 
 
614
  template<class charT, class traits>
615
  void swap(basic_ifstream<charT, traits>& x,
616
  basic_ifstream<charT, traits>& y);
617
  ```
618
 
619
+ *Effects:* Equivalent to: `x.swap(y)`.
620
 
621
  #### Member functions <a id="ifstream.members">[[ifstream.members]]</a>
622
 
623
  ``` cpp
624
  basic_filebuf<charT, traits>* rdbuf() const;
625
  ```
626
 
627
+ *Returns:* `const_cast<basic_filebuf<charT, traits>*>(addressof(sb))`.
628
 
629
  ``` cpp
630
  bool is_open() const;
631
  ```
632
 
 
638
  ios_base::openmode mode = ios_base::in); // wide systems only; see [fstream.syn]
639
  ```
640
 
641
  *Effects:* Calls `rdbuf()->open(s, mode | ios_base::in)`. If that
642
  function does not return a null pointer calls `clear()`, otherwise calls
643
+ `setstate(failbit)` (which may throw
644
+ `ios_base::failure`) [[iostate.flags]].
645
 
646
  ``` cpp
647
  void open(const string& s, ios_base::openmode mode = ios_base::in);
648
  void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in);
649
  ```
 
654
  void close();
655
  ```
656
 
657
  *Effects:* Calls `rdbuf()->close()` and, if that function returns a null
658
  pointer, calls `setstate(failbit)` (which may throw
659
+ `ios_base::failure`) [[iostate.flags]].
660
 
661
  ### Class template `basic_ofstream` <a id="ofstream">[[ofstream]]</a>
662
 
663
  ``` cpp
664
  namespace std {
 
673
 
674
  // [ofstream.cons], constructors
675
  basic_ofstream();
676
  explicit basic_ofstream(const char* s,
677
  ios_base::openmode mode = ios_base::out);
678
+ explicit basic_ofstream(const filesystem::path::value_type* s, // wide systems only; see [fstream.syn]
679
+ ios_base::openmode mode = ios_base::out);
680
  explicit basic_ofstream(const string& s,
681
  ios_base::openmode mode = ios_base::out);
682
  explicit basic_ofstream(const filesystem::path& s,
683
  ios_base::openmode mode = ios_base::out);
684
+ basic_ofstream(const basic_ofstream&) = delete;
685
  basic_ofstream(basic_ofstream&& rhs);
686
 
687
  // [ofstream.assign], assign and swap
688
+ basic_ofstream& operator=(const basic_ofstream&) = delete;
689
  basic_ofstream& operator=(basic_ofstream&& rhs);
690
  void swap(basic_ofstream& rhs);
691
 
692
  // [ofstream.members], members
693
  basic_filebuf<charT, traits>* rdbuf() const;
 
714
  associated sequence. For the sake of exposition, the maintained data is
715
  presented here as:
716
 
717
  - `sb`, the `filebuf` object.
718
 
719
+ #### Constructors <a id="ofstream.cons">[[ofstream.cons]]</a>
720
 
721
  ``` cpp
722
  basic_ofstream();
723
  ```
724
 
725
+ *Effects:* Initializes the base class with
726
+ `basic_ostream<charT, traits>(addressof(sb))` [[ostream.cons]] and `sb`
727
+ with `basic_filebuf<charT, traits>()` [[filebuf.cons]].
 
728
 
729
  ``` cpp
730
  explicit basic_ofstream(const char* s,
731
  ios_base::openmode mode = ios_base::out);
732
  explicit basic_ofstream(const filesystem::path::value_type* s,
733
  ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
734
  ```
735
 
736
+ *Effects:* Initializes the base class with
737
+ `basic_ostream<charT, traits>(addressof(sb))` [[ostream.cons]] and `sb`
738
+ with `basic_filebuf<charT, traits>()` [[filebuf.cons]], then calls
739
+ `rdbuf()->open(s, mode | ios_base::out)`. If that function returns a
740
+ null pointer, calls `setstate(failbit)`.
 
741
 
742
  ``` cpp
743
  explicit basic_ofstream(const string& s,
744
  ios_base::openmode mode = ios_base::out);
745
  explicit basic_ofstream(const filesystem::path& s,
746
  ios_base::openmode mode = ios_base::out);
747
  ```
748
 
749
+ *Effects:* Equivalent to: `basic_ofstream(s.c_str(), mode)`.
750
 
751
  ``` cpp
752
  basic_ofstream(basic_ofstream&& rhs);
753
  ```
754
 
755
+ *Effects:* Move constructs the base class, and the contained
756
+ `basic_filebuf`. Then calls
757
+ `basic_ostream<charT, traits>::set_rdbuf(addressof(sb))` to install the
758
+ contained `basic_filebuf`.
759
 
760
+ #### Assignment and swap <a id="ofstream.assign">[[ofstream.assign]]</a>
 
 
 
 
 
 
 
 
 
761
 
762
  ``` cpp
763
  void swap(basic_ofstream& rhs);
764
  ```
765
 
 
770
  template<class charT, class traits>
771
  void swap(basic_ofstream<charT, traits>& x,
772
  basic_ofstream<charT, traits>& y);
773
  ```
774
 
775
+ *Effects:* Equivalent to: `x.swap(y)`.
776
 
777
  #### Member functions <a id="ofstream.members">[[ofstream.members]]</a>
778
 
779
  ``` cpp
780
  basic_filebuf<charT, traits>* rdbuf() const;
781
  ```
782
 
783
+ *Returns:* `const_cast<basic_filebuf<charT, traits>*>(addressof(sb))`.
784
 
785
  ``` cpp
786
  bool is_open() const;
787
  ```
788
 
 
794
  ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
795
  ```
796
 
797
  *Effects:* Calls `rdbuf()->open(s, mode | ios_base::out)`. If that
798
  function does not return a null pointer calls `clear()`, otherwise calls
799
+ `setstate(failbit)` (which may throw
800
+ `ios_base::failure`) [[iostate.flags]].
801
 
802
  ``` cpp
803
  void close();
804
  ```
805
 
806
  *Effects:* Calls `rdbuf()->close()` and, if that function fails (returns
807
  a null pointer), calls `setstate(failbit)` (which may throw
808
+ `ios_base::failure`) [[iostate.flags]].
809
 
810
  ``` cpp
811
  void open(const string& s, ios_base::openmode mode = ios_base::out);
812
  void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);
813
  ```
 
831
  basic_fstream();
832
  explicit basic_fstream(
833
  const char* s,
834
  ios_base::openmode mode = ios_base::in | ios_base::out);
835
  explicit basic_fstream(
836
+ const filesystem::path::value_type* s,
837
  ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
838
  explicit basic_fstream(
839
  const string& s,
840
  ios_base::openmode mode = ios_base::in | ios_base::out);
841
  explicit basic_fstream(
842
  const filesystem::path& s,
843
  ios_base::openmode mode = ios_base::in | ios_base::out);
844
+ basic_fstream(const basic_fstream&) = delete;
845
  basic_fstream(basic_fstream&& rhs);
846
 
847
  // [fstream.assign], assign and swap
848
+ basic_fstream& operator=(const basic_fstream&) = delete;
849
  basic_fstream& operator=(basic_fstream&& rhs);
850
  void swap(basic_fstream& rhs);
851
 
852
  // [fstream.members], members
853
  basic_filebuf<charT, traits>* rdbuf() const;
854
  bool is_open() const;
855
  void open(
856
  const char* s,
857
  ios_base::openmode mode = ios_base::in | ios_base::out);
858
  void open(
859
+ const filesystem::path::value_type* s,
860
  ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
861
  void open(
862
  const string& s,
863
  ios_base::openmode mode = ios_base::in | ios_base::out);
864
  void open(
 
881
  object to control the associated sequences. For the sake of exposition,
882
  the maintained data is presented here as:
883
 
884
  - `sb`, the `basic_filebuf` object.
885
 
886
+ #### Constructors <a id="fstream.cons">[[fstream.cons]]</a>
887
 
888
  ``` cpp
889
  basic_fstream();
890
  ```
891
 
892
+ *Effects:* Initializes the base class with
893
+ `basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
894
  `sb` with `basic_filebuf<charT, traits>()`.
895
 
896
  ``` cpp
897
  explicit basic_fstream(
898
  const char* s,
 
900
  explicit basic_fstream(
901
  const filesystem::path::value_type* s,
902
  ios_base::openmode mode = ios_base::in | ios_base::out); // wide systems only; see [fstream.syn]
903
  ```
904
 
905
+ *Effects:* Initializes the base class with
906
+ `basic_iostream<charT, traits>(addressof(sb))` [[iostream.cons]] and
907
  `sb` with `basic_filebuf<charT, traits>()`. Then calls
908
  `rdbuf()->open(s, mode)`. If that function returns a null pointer, calls
909
  `setstate(failbit)`.
910
 
911
  ``` cpp
 
915
  explicit basic_fstream(
916
  const filesystem::path& s,
917
  ios_base::openmode mode = ios_base::in | ios_base::out);
918
  ```
919
 
920
+ *Effects:* Equivalent to: `basic_fstream(s.c_str(), mode)`.
921
 
922
  ``` cpp
923
  basic_fstream(basic_fstream&& rhs);
924
  ```
925
 
926
+ *Effects:* Move constructs the base class, and the contained
927
+ `basic_filebuf`. Then calls
928
+ `basic_istream<charT, traits>::set_rdbuf(addressof(sb))` to install the
929
+ contained `basic_filebuf`.
930
 
931
+ #### Assignment and swap <a id="fstream.assign">[[fstream.assign]]</a>
 
 
 
 
 
 
 
 
 
932
 
933
  ``` cpp
934
  void swap(basic_fstream& rhs);
935
  ```
936
 
 
941
  template<class charT, class traits>
942
  void swap(basic_fstream<charT, traits>& x,
943
  basic_fstream<charT, traits>& y);
944
  ```
945
 
946
+ *Effects:* Equivalent to: `x.swap(y)`.
947
 
948
  #### Member functions <a id="fstream.members">[[fstream.members]]</a>
949
 
950
  ``` cpp
951
  basic_filebuf<charT, traits>* rdbuf() const;
952
  ```
953
 
954
+ *Returns:* `const_cast<basic_filebuf<charT, traits>*>(addressof(sb))`.
955
 
956
  ``` cpp
957
  bool is_open() const;
958
  ```
959
 
 
969
  ```
970
 
971
  *Effects:* Calls `rdbuf()->open(s, mode)`. If that function does not
972
  return a null pointer calls `clear()`, otherwise calls
973
  `setstate(failbit)` (which may throw
974
+ `ios_base::failure`) [[iostate.flags]].
975
 
976
  ``` cpp
977
  void open(
978
  const string& s,
979
  ios_base::openmode mode = ios_base::in | ios_base::out);
 
988
  void close();
989
  ```
990
 
991
  *Effects:* Calls `rdbuf()->close()` and, if that function returns a null
992
  pointer, calls `setstate(failbit)` (which may throw
993
+ `ios_base::failure`) [[iostate.flags]].
994