From Jason Turner

[depr.conversions]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpn9wruta3/{from.md → to.md} +0 -290
tmp/tmpn9wruta3/{from.md → to.md} RENAMED
@@ -1,290 +0,0 @@
1
- ## Deprecated convenience conversion interfaces <a id="depr.conversions">[[depr.conversions]]</a>
2
-
3
- ### General <a id="depr.conversions.general">[[depr.conversions.general]]</a>
4
-
5
- The header `<locale>` has the following additions:
6
-
7
- ``` cpp
8
- namespace std {
9
- template<class Codecvt, class Elem = wchar_t,
10
- class WideAlloc = allocator<Elem>,
11
- class ByteAlloc = allocator<char>>
12
- class wstring_convert;
13
-
14
- template<class Codecvt, class Elem = wchar_t,
15
- class Tr = char_traits<Elem>>
16
- class wbuffer_convert;
17
- }
18
- ```
19
-
20
- ### Class template `wstring_convert` <a id="depr.conversions.string">[[depr.conversions.string]]</a>
21
-
22
- Class template `wstring_convert` performs conversions between a wide
23
- string and a byte string. It lets you specify a code conversion facet
24
- (like class template `codecvt`) to perform the conversions, without
25
- affecting any streams or locales.
26
-
27
- [*Example 1*:
28
-
29
- If you want to use the code conversion facet `codecvt_utf8` to output to
30
- `cout` a UTF-8 multibyte sequence corresponding to a wide string, but
31
- you don’t want to alter the locale for `cout`, you can write something
32
- like:
33
-
34
- ``` cpp
35
- wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
36
- std::string mbstring = myconv.to_bytes(L"Hello\n");
37
- std::cout << mbstring;
38
- ```
39
-
40
- — *end example*]
41
-
42
- ``` cpp
43
- namespace std {
44
- template<class Codecvt, class Elem = wchar_t,
45
- class WideAlloc = allocator<Elem>,
46
- class ByteAlloc = allocator<char>>
47
- class wstring_convert {
48
- public:
49
- using byte_string = basic_string<char, char_traits<char>, ByteAlloc>;
50
- using wide_string = basic_string<Elem, char_traits<Elem>, WideAlloc>;
51
- using state_type = typename Codecvt::state_type;
52
- using int_type = typename wide_string::traits_type::int_type;
53
-
54
- wstring_convert() : wstring_convert(new Codecvt) {}
55
- explicit wstring_convert(Codecvt* pcvt);
56
- wstring_convert(Codecvt* pcvt, state_type state);
57
- explicit wstring_convert(const byte_string& byte_err,
58
- const wide_string& wide_err = wide_string());
59
- ~wstring_convert();
60
-
61
- wstring_convert(const wstring_convert&) = delete;
62
- wstring_convert& operator=(const wstring_convert&) = delete;
63
-
64
- wide_string from_bytes(char byte);
65
- wide_string from_bytes(const char* ptr);
66
- wide_string from_bytes(const byte_string& str);
67
- wide_string from_bytes(const char* first, const char* last);
68
-
69
- byte_string to_bytes(Elem wchar);
70
- byte_string to_bytes(const Elem* wptr);
71
- byte_string to_bytes(const wide_string& wstr);
72
- byte_string to_bytes(const Elem* first, const Elem* last);
73
-
74
- size_t converted() const noexcept;
75
- state_type state() const;
76
-
77
- private:
78
- byte_string byte_err_string; // exposition only
79
- wide_string wide_err_string; // exposition only
80
- Codecvt* cvtptr; // exposition only
81
- state_type cvtstate; // exposition only
82
- size_t cvtcount; // exposition only
83
- };
84
- }
85
- ```
86
-
87
- The class template describes an object that controls conversions between
88
- wide string objects of class `basic_string<Elem, char_traits<Elem>,
89
- WideAlloc>` and byte string objects of class `basic_string<char,
90
- char_traits<char>, ByteAlloc>`. The class template defines the types
91
- `wide_string` and `byte_string` as synonyms for these two types.
92
- Conversion between a sequence of `Elem` values (stored in a
93
- `wide_string` object) and multibyte sequences (stored in a `byte_string`
94
- object) is performed by an object of class `Codecvt`, which meets the
95
- requirements of the standard code-conversion facet `codecvt<Elem,
96
- char, mbstate_t>`.
97
-
98
- An object of this class template stores:
99
-
100
- - `byte_err_string` — a byte string to display on errors
101
- - `wide_err_string` — a wide string to display on errors
102
- - `cvtptr` — a pointer to the allocated conversion object (which is
103
- freed when the `wstring_convert` object is destroyed)
104
- - `cvtstate` — a conversion state object
105
- - `cvtcount` — a conversion count
106
-
107
- ``` cpp
108
- size_t converted() const noexcept;
109
- ```
110
-
111
- *Returns:* `cvtcount`.
112
-
113
- ``` cpp
114
- wide_string from_bytes(char byte);
115
- wide_string from_bytes(const char* ptr);
116
- wide_string from_bytes(const byte_string& str);
117
- wide_string from_bytes(const char* first, const char* last);
118
- ```
119
-
120
- *Effects:* The first member function shall convert the single-element
121
- sequence `byte` to a wide string. The second member function shall
122
- convert the null-terminated sequence beginning at `ptr` to a wide
123
- string. The third member function shall convert the sequence stored in
124
- `str` to a wide string. The fourth member function shall convert the
125
- sequence defined by the range \[`first`, `last`) to a wide string.
126
-
127
- In all cases:
128
-
129
- - If the `cvtstate` object was not constructed with an explicit value,
130
- it shall be set to its default value (the initial conversion state)
131
- before the conversion begins. Otherwise it shall be left unchanged.
132
- - The number of input elements successfully converted shall be stored in
133
- `cvtcount`.
134
-
135
- *Returns:* If no conversion error occurs, the member function shall
136
- return the converted wide string. Otherwise, if the object was
137
- constructed with a wide-error string, the member function shall return
138
- the wide-error string. Otherwise, the member function throws an object
139
- of class `range_error`.
140
-
141
- ``` cpp
142
- state_type state() const;
143
- ```
144
-
145
- *Returns:* `cvtstate`.
146
-
147
- ``` cpp
148
- byte_string to_bytes(Elem wchar);
149
- byte_string to_bytes(const Elem* wptr);
150
- byte_string to_bytes(const wide_string& wstr);
151
- byte_string to_bytes(const Elem* first, const Elem* last);
152
- ```
153
-
154
- *Effects:* The first member function shall convert the single-element
155
- sequence `wchar` to a byte string. The second member function shall
156
- convert the null-terminated sequence beginning at `wptr` to a byte
157
- string. The third member function shall convert the sequence stored in
158
- `wstr` to a byte string. The fourth member function shall convert the
159
- sequence defined by the range \[`first`, `last`) to a byte string.
160
-
161
- In all cases:
162
-
163
- - If the `cvtstate` object was not constructed with an explicit value,
164
- it shall be set to its default value (the initial conversion state)
165
- before the conversion begins. Otherwise it shall be left unchanged.
166
- - The number of input elements successfully converted shall be stored in
167
- `cvtcount`.
168
-
169
- *Returns:* If no conversion error occurs, the member function shall
170
- return the converted byte string. Otherwise, if the object was
171
- constructed with a byte-error string, the member function shall return
172
- the byte-error string. Otherwise, the member function shall throw an
173
- object of class `range_error`.
174
-
175
- ``` cpp
176
- explicit wstring_convert(Codecvt* pcvt);
177
- wstring_convert(Codecvt* pcvt, state_type state);
178
- explicit wstring_convert(const byte_string& byte_err,
179
- const wide_string& wide_err = wide_string());
180
- ```
181
-
182
- *Requires:* For the first and second constructors, `pcvt != nullptr`.
183
-
184
- *Effects:* The first constructor shall store `pcvt` in `cvtptr` and
185
- default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
186
- The second constructor shall store `pcvt` in `cvtptr`, `state` in
187
- `cvtstate`, and default values in `byte_err_string` and
188
- `wide_err_string`; moreover the stored state shall be retained between
189
- calls to `from_bytes` and `to_bytes`. The third constructor shall store
190
- `new Codecvt` in `cvtptr`, `state_type()` in `cvtstate`, `byte_err` in
191
- `byte_err_string`, and `wide_err` in `wide_err_string`.
192
-
193
- ``` cpp
194
- ~wstring_convert();
195
- ```
196
-
197
- *Effects:* The destructor shall delete `cvtptr`.
198
-
199
- ### Class template `wbuffer_convert` <a id="depr.conversions.buffer">[[depr.conversions.buffer]]</a>
200
-
201
- Class template `wbuffer_convert` looks like a wide stream buffer, but
202
- performs all its I/O through an underlying byte stream buffer that you
203
- specify when you construct it. Like class template `wstring_convert`, it
204
- lets you specify a code conversion facet to perform the conversions,
205
- without affecting any streams or locales.
206
-
207
- ``` cpp
208
- namespace std {
209
- template<class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>>
210
- class wbuffer_convert : public basic_streambuf<Elem, Tr> {
211
- public:
212
- using state_type = typename Codecvt::state_type;
213
-
214
- wbuffer_convert() : wbuffer_convert(nullptr) {}
215
- explicit wbuffer_convert(streambuf* bytebuf,
216
- Codecvt* pcvt = new Codecvt,
217
- state_type state = state_type());
218
-
219
- ~wbuffer_convert();
220
-
221
- wbuffer_convert(const wbuffer_convert&) = delete;
222
- wbuffer_convert& operator=(const wbuffer_convert&) = delete;
223
-
224
- streambuf* rdbuf() const;
225
- streambuf* rdbuf(streambuf* bytebuf);
226
-
227
- state_type state() const;
228
-
229
- private:
230
- streambuf* bufptr; // exposition only
231
- Codecvt* cvtptr; // exposition only
232
- state_type cvtstate; // exposition only
233
- };
234
- }
235
- ```
236
-
237
- The class template describes a stream buffer that controls the
238
- transmission of elements of type `Elem`, whose character traits are
239
- described by the class `Tr`, to and from a byte stream buffer of type
240
- `streambuf`. Conversion between a sequence of `Elem` values and
241
- multibyte sequences is performed by an object of class `Codecvt`, which
242
- shall meet the requirements of the standard code-conversion facet
243
- `codecvt<Elem, char, mbstate_t>`.
244
-
245
- An object of this class template stores:
246
-
247
- - `bufptr` — a pointer to its underlying byte stream buffer
248
- - `cvtptr` — a pointer to the allocated conversion object (which is
249
- freed when the `wbuffer_convert` object is destroyed)
250
- - `cvtstate` — a conversion state object
251
-
252
- ``` cpp
253
- state_type state() const;
254
- ```
255
-
256
- *Returns:* `cvtstate`.
257
-
258
- ``` cpp
259
- streambuf* rdbuf() const;
260
- ```
261
-
262
- *Returns:* `bufptr`.
263
-
264
- ``` cpp
265
- streambuf* rdbuf(streambuf* bytebuf);
266
- ```
267
-
268
- *Effects:* Stores `bytebuf` in `bufptr`.
269
-
270
- *Returns:* The previous value of `bufptr`.
271
-
272
- ``` cpp
273
- explicit wbuffer_convert(
274
- streambuf* bytebuf,
275
- Codecvt* pcvt = new Codecvt,
276
- state_type state = state_type());
277
- ```
278
-
279
- *Requires:* `pcvt != nullptr`.
280
-
281
- *Effects:* The constructor constructs a stream buffer object,
282
- initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
283
- initializes `cvtstate` to `state`.
284
-
285
- ``` cpp
286
- ~wbuffer_convert();
287
- ```
288
-
289
- *Effects:* The destructor shall delete `cvtptr`.
290
-