From Jason Turner

[fstream]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpu24219a0/{from.md → to.md} +151 -19
tmp/tmpu24219a0/{from.md → to.md} RENAMED
@@ -1,40 +1,54 @@
1
- #### Class template `basic_fstream` <a id="fstream">[[fstream]]</a>
2
 
3
  ``` cpp
4
  namespace std {
5
  template <class charT, class traits = char_traits<charT>>
6
- class basic_fstream
7
- : public basic_iostream<charT,traits> {
8
-
9
  public:
10
- typedef charT char_type;
11
- typedef typename traits::int_type int_type;
12
- typedef typename traits::pos_type pos_type;
13
- typedef typename traits::off_type off_type;
14
- typedef traits traits_type;
15
 
16
- // constructors/destructor
17
  basic_fstream();
18
- explicit basic_fstream(const char* s,
 
19
  ios_base::openmode mode = ios_base::in | ios_base::out);
20
- explicit basic_fstream(const string& s,
 
 
 
 
 
 
 
21
  ios_base::openmode mode = ios_base::in | ios_base::out);
22
  basic_fstream(const basic_fstream& rhs) = delete;
23
  basic_fstream(basic_fstream&& rhs);
24
 
25
- // [fstream.assign] Assign/swap:
26
  basic_fstream& operator=(const basic_fstream& rhs) = delete;
27
  basic_fstream& operator=(basic_fstream&& rhs);
28
  void swap(basic_fstream& rhs);
29
 
30
- // Members:
31
  basic_filebuf<charT, traits>* rdbuf() const;
32
  bool is_open() const;
33
- void open(const char* s,
 
34
  ios_base::openmode mode = ios_base::in | ios_base::out);
35
- void open(const string& s,
 
 
 
 
 
 
 
36
  ios_base::openmode mode = ios_base::in | ios_base::out);
37
  void close();
38
 
39
  private:
40
  basic_filebuf<charT, traits> sb; // exposition only
@@ -45,11 +59,129 @@ namespace std {
45
  basic_fstream<charT, traits>& y);
46
  }
47
  ```
48
 
49
  The class template `basic_fstream<charT, traits>` supports reading and
50
- writing from named files. It uses a `basic_filebuf<charT,traits>` object
51
- to control the associated sequences. For the sake of exposition, the
52
- maintained data is presented here as:
53
 
54
  - `sb`, the `basic_filebuf` object.
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class template `basic_fstream` <a id="fstream">[[fstream]]</a>
2
 
3
  ``` cpp
4
  namespace std {
5
  template <class charT, class traits = char_traits<charT>>
6
+ class basic_fstream : public basic_iostream<charT, traits> {
 
 
7
  public:
8
+ using char_type = charT;
9
+ using int_type = typename traits::int_type;
10
+ using pos_type = typename traits::pos_type;
11
+ using off_type = typename traits::off_type;
12
+ using traits_type = traits;
13
 
14
+ // [fstream.cons], constructors
15
  basic_fstream();
16
+ explicit basic_fstream(
17
+ const char* s,
18
  ios_base::openmode mode = ios_base::in | ios_base::out);
19
+ explicit basic_fstream(
20
+ const std::filesystem::path::value_type* s,
21
+ ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
22
+ explicit basic_fstream(
23
+ const string& s,
24
+ ios_base::openmode mode = ios_base::in | ios_base::out);
25
+ explicit basic_fstream(
26
+ const filesystem::path& s,
27
  ios_base::openmode mode = ios_base::in | ios_base::out);
28
  basic_fstream(const basic_fstream& rhs) = delete;
29
  basic_fstream(basic_fstream&& rhs);
30
 
31
+ // [fstream.assign], assign and swap
32
  basic_fstream& operator=(const basic_fstream& rhs) = delete;
33
  basic_fstream& operator=(basic_fstream&& rhs);
34
  void swap(basic_fstream& rhs);
35
 
36
+ // [fstream.members], members
37
  basic_filebuf<charT, traits>* rdbuf() const;
38
  bool is_open() const;
39
+ void open(
40
+ const char* s,
41
  ios_base::openmode mode = ios_base::in | ios_base::out);
42
+ void open(
43
+ const std::filesystem::path::value_type* s,
44
+ ios_base::openmode mode = ios_base::in|ios_base::out); // wide systems only; see [fstream.syn]
45
+ void open(
46
+ const string& s,
47
+ ios_base::openmode mode = ios_base::in | ios_base::out);
48
+ void open(
49
+ const filesystem::path& s,
50
  ios_base::openmode mode = ios_base::in | ios_base::out);
51
  void close();
52
 
53
  private:
54
  basic_filebuf<charT, traits> sb; // exposition only
 
59
  basic_fstream<charT, traits>& y);
60
  }
61
  ```
62
 
63
  The class template `basic_fstream<charT, traits>` supports reading and
64
+ writing from named files. It uses a `basic_filebuf<charT, traits>`
65
+ object to control the associated sequences. For the sake of exposition,
66
+ the maintained data is presented here as:
67
 
68
  - `sb`, the `basic_filebuf` object.
69
 
70
+ #### `basic_fstream` constructors <a id="fstream.cons">[[fstream.cons]]</a>
71
+
72
+ ``` cpp
73
+ basic_fstream();
74
+ ```
75
+
76
+ *Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
77
+ initializing the base class with `basic_iostream(&sb)` and initializing
78
+ `sb` with `basic_filebuf<charT, traits>()`.
79
+
80
+ ``` cpp
81
+ explicit basic_fstream(
82
+ const char* s,
83
+ ios_base::openmode mode = ios_base::in | ios_base::out);
84
+ explicit basic_fstream(
85
+ const filesystem::path::value_type* s,
86
+ ios_base::openmode mode = ios_base::in | ios_base::out); // wide systems only; see [fstream.syn]
87
+ ```
88
+
89
+ *Effects:* Constructs an object of class `basic_fstream<charT, traits>`,
90
+ initializing the base class with `basic_iostream(&sb)` and initializing
91
+ `sb` with `basic_filebuf<charT, traits>()`. Then calls
92
+ `rdbuf()->open(s, mode)`. If that function returns a null pointer, calls
93
+ `setstate(failbit)`.
94
+
95
+ ``` cpp
96
+ explicit basic_fstream(
97
+ const string& s,
98
+ ios_base::openmode mode = ios_base::in | ios_base::out);
99
+ explicit basic_fstream(
100
+ const filesystem::path& s,
101
+ ios_base::openmode mode = ios_base::in | ios_base::out);
102
+ ```
103
+
104
+ *Effects:* The same as `basic_fstream(s.c_str(), mode)`.
105
+
106
+ ``` cpp
107
+ basic_fstream(basic_fstream&& rhs);
108
+ ```
109
+
110
+ *Effects:* Move constructs from the rvalue `rhs`. This is accomplished
111
+ by move constructing the base class, and the contained `basic_filebuf`.
112
+ Next `basic_istream<charT, traits>::set_rdbuf(&sb)` is called to install
113
+ the contained `basic_filebuf`.
114
+
115
+ #### Assign and swap <a id="fstream.assign">[[fstream.assign]]</a>
116
+
117
+ ``` cpp
118
+ basic_fstream& operator=(basic_fstream&& rhs);
119
+ ```
120
+
121
+ *Effects:* Move assigns the base and members of `*this` from the base
122
+ and corresponding members of `rhs`.
123
+
124
+ *Returns:* `*this`.
125
+
126
+ ``` cpp
127
+ void swap(basic_fstream& rhs);
128
+ ```
129
+
130
+ *Effects:* Exchanges the state of `*this` and `rhs` by calling
131
+ `basic_iostream<charT,traits>::swap(rhs)` and `sb.swap(rhs.sb)`.
132
+
133
+ ``` cpp
134
+ template <class charT, class traits>
135
+ void swap(basic_fstream<charT, traits>& x,
136
+ basic_fstream<charT, traits>& y);
137
+ ```
138
+
139
+ *Effects:* As if by `x.swap(y)`.
140
+
141
+ #### Member functions <a id="fstream.members">[[fstream.members]]</a>
142
+
143
+ ``` cpp
144
+ basic_filebuf<charT, traits>* rdbuf() const;
145
+ ```
146
+
147
+ *Returns:* `const_cast<basic_filebuf<charT, traits>*>(&sb)`.
148
+
149
+ ``` cpp
150
+ bool is_open() const;
151
+ ```
152
+
153
+ *Returns:* `rdbuf()->is_open()`.
154
+
155
+ ``` cpp
156
+ void open(
157
+ const char* s,
158
+ ios_base::openmode mode = ios_base::in | ios_base::out);
159
+ void open(
160
+ const filesystem::path::value_type* s,
161
+ ios_base::openmode mode = ios_base::in | ios_base::out); // wide systems only; see [fstream.syn]
162
+ ```
163
+
164
+ *Effects:* Calls `rdbuf()->open(s, mode)`. If that function does not
165
+ return a null pointer calls `clear()`, otherwise calls
166
+ `setstate(failbit)` (which may throw
167
+ `ios_base::failure`) ([[iostate.flags]]).
168
+
169
+ ``` cpp
170
+ void open(
171
+ const string& s,
172
+ ios_base::openmode mode = ios_base::in | ios_base::out);
173
+ void open(
174
+ const filesystem::path& s,
175
+ ios_base::openmode mode = ios_base::in | ios_base::out);
176
+ ```
177
+
178
+ *Effects:* Calls `open(s.c_str(), mode)`.
179
+
180
+ ``` cpp
181
+ void close();
182
+ ```
183
+
184
+ *Effects:* Calls `rdbuf()->close()` and, if that function returns a null
185
+ pointer, calls `setstate(failbit)` (which may throw
186
+ `ios_base::failure`) ([[iostate.flags]]).
187
+