From Jason Turner

[conversions]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzggw20_7/{from.md → to.md} +37 -26
tmp/tmpzggw20_7/{from.md → to.md} RENAMED
@@ -17,18 +17,17 @@ template <class charT> charT tolower(charT c, const locale& loc);
17
  ##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
18
 
19
  Class template `wstring_convert` performs conversions between a wide
20
  string and a byte string. It lets you specify a code conversion facet
21
  (like class template `codecvt`) to perform the conversions, without
22
- affecting any streams or locales. Say, for example, you have a code
23
- conversion facet called `codecvt_utf8` that you want to use to output to
24
- `cout` a UTF-8 multibyte sequence corresponding to a wide string, but
25
- you don’t want to alter the locale for `cout`. You can write something
26
- like:
27
 
28
  ``` cpp
29
- wstring_convert<codecvt_utf8<wchar_t>> myconv;
30
  std::string mbstring = myconv.to_bytes(L"Hello\n");
31
  std::cout << mbstring;
32
  ```
33
 
34
  ``` cpp
@@ -40,27 +39,30 @@ template<class Codecvt, class Elem = wchar_t,
40
  typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
41
  typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
42
  typedef typename Codecvt::state_type state_type;
43
  typedef typename wide_string::traits_type::int_type int_type;
44
 
45
- wstring_convert(Codecvt *pcvt = new Codecvt);
46
  wstring_convert(Codecvt* pcvt, state_type state);
47
- wstring_convert(const byte_string& byte_err,
48
  const wide_string& wide_err = wide_string());
49
  ~wstring_convert();
50
 
 
 
 
51
  wide_string from_bytes(char byte);
52
  wide_string from_bytes(const char* ptr);
53
  wide_string from_bytes(const byte_string& str);
54
  wide_string from_bytes(const char* first, const char* last);
55
 
56
  byte_string to_bytes(Elem wchar);
57
  byte_string to_bytes(const Elem* wptr);
58
  byte_string to_bytes(const wide_string& wstr);
59
  byte_string to_bytes(const Elem* first, const Elem* last);
60
 
61
- size_t converted() const;
62
  state_type state() const;
63
  private:
64
  byte_string byte_err_string; // exposition only
65
  wide_string wide_err_string; // exposition only
66
  Codecvt* cvtptr; // exposition only
@@ -73,15 +75,14 @@ template<class Codecvt, class Elem = wchar_t,
73
  The class template describes an object that controls conversions between
74
  wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
75
  Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
76
  char_traits<char>, Byte_alloc>`. The class template defines the types
77
  `wide_string` and `byte_string` as synonyms for these two types.
78
- Conversion between a sequence of `Elem` values (stored in a wide_string
79
- object) and multibyte sequences (stored in a byte_string object) is
80
- performed by an object of class `Codecvt<Elem, char, std::mbstate_t>`,
81
- which meets the requirements of the standard code-conversion facet
82
- `std::codecvt<Elem,
83
  char, std::mbstate_t>`.
84
 
85
  An object of this class template stores:
86
 
87
  - `byte_err_string` — a byte string to display on errors
@@ -90,17 +91,18 @@ An object of this class template stores:
90
  freed when the `wstring_convert` object is destroyed)
91
  - `cvtstate` — a conversion state object
92
  - `cvtcount` — a conversion count
93
 
94
  ``` cpp
95
- typedef std::basic_string<char> byte_string;
96
  ```
97
 
98
- The type shall be a synonym for `std::basic_string<char>`
 
99
 
100
  ``` cpp
101
- size_t converted() const;
102
  ```
103
 
104
  *Returns:* `cvtcount`.
105
 
106
  ``` cpp
@@ -176,22 +178,25 @@ return the converted byte string. Otherwise, if the object was
176
  constructed with a byte-error string, the member function shall return
177
  the byte-error string. Otherwise, the member function shall throw an
178
  object of class `std::range_error`.
179
 
180
  ``` cpp
181
- typedef std::basic_string<Elem> wide_string;
182
  ```
183
 
184
- The type shall be a synonym for `std::basic_string<Elem>`.
 
185
 
186
  ``` cpp
187
- wstring_convert(Codecvt *pcvt = new Codecvt);
188
  wstring_convert(Codecvt* pcvt, state_type state);
189
- wstring_convert(const byte_string& byte_err,
190
  const wide_string& wide_err = wide_string());
191
  ```
192
 
 
 
193
  *Effects:* The first constructor shall store `pcvt` in `cvtptr` and
194
  default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
195
  The second constructor shall store `pcvt` in `cvtptr`, `state` in
196
  `cvtstate`, and default values in `byte_err_string` and
197
  `wide_err_string`; moreover the stored state shall be retained between
@@ -221,14 +226,19 @@ template<class Codecvt,
221
  class wbuffer_convert
222
  : public std::basic_streambuf<Elem, Tr> {
223
  public:
224
  typedef typename Codecvt::state_type state_type;
225
 
226
- wbuffer_convert(std::streambuf *bytebuf = 0,
227
  Codecvt* pcvt = new Codecvt,
228
  state_type state = state_type());
229
 
 
 
 
 
 
230
  std::streambuf* rdbuf() const;
231
  std::streambuf* rdbuf(std::streambuf* bytebuf);
232
 
233
  state_type state() const;
234
 
@@ -242,13 +252,12 @@ template<class Codecvt,
242
 
243
  The class template describes a stream buffer that controls the
244
  transmission of elements of type `Elem`, whose character traits are
245
  described by the class `Tr`, to and from a byte stream buffer of type
246
  `std::streambuf`. Conversion between a sequence of `Elem` values and
247
- multibyte sequences is performed by an object of class
248
- `Codecvt<Elem, char, std::mbstate_t>`, which shall meet the requirements
249
- of the standard code-conversion facet
250
  `std::codecvt<Elem, char, std::mbstate_t>`.
251
 
252
  An object of this class template stores:
253
 
254
  - `bufptr` — a pointer to its underlying byte stream buffer
@@ -281,14 +290,16 @@ typedef typename Codecvt::state_type state_type;
281
  ```
282
 
283
  The type shall be a synonym for `Codecvt::state_type`.
284
 
285
  ``` cpp
286
- wbuffer_convert(std::streambuf *bytebuf = 0,
287
  Codecvt* pcvt = new Codecvt, state_type state = state_type());
288
  ```
289
 
 
 
290
  *Effects:* The constructor constructs a stream buffer object,
291
  initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
292
  initializes `cvtstate` to `state`.
293
 
294
  ``` cpp
 
17
  ##### `string` conversions <a id="conversions.string">[[conversions.string]]</a>
18
 
19
  Class template `wstring_convert` performs conversions between a wide
20
  string and a byte string. It lets you specify a code conversion facet
21
  (like class template `codecvt`) to perform the conversions, without
22
+ affecting any streams or locales. If you want to use the code conversion
23
+ facet `codecvt_utf8` to output to `cout` a UTF-8 multibyte sequence
24
+ corresponding to a wide string, but you don’t want to alter the locale
25
+ for `cout`, you can write something like:
 
26
 
27
  ``` cpp
28
+ wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
29
  std::string mbstring = myconv.to_bytes(L"Hello\n");
30
  std::cout << mbstring;
31
  ```
32
 
33
  ``` cpp
 
39
  typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
40
  typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
41
  typedef typename Codecvt::state_type state_type;
42
  typedef typename wide_string::traits_type::int_type int_type;
43
 
44
+ explicit wstring_convert(Codecvt* pcvt = new Codecvt);
45
  wstring_convert(Codecvt* pcvt, state_type state);
46
+ explicit wstring_convert(const byte_string& byte_err,
47
  const wide_string& wide_err = wide_string());
48
  ~wstring_convert();
49
 
50
+ wstring_convert(const wstring_convert&) = delete;
51
+ wstring_convert& operator=(const wstring_convert&) = delete;
52
+
53
  wide_string from_bytes(char byte);
54
  wide_string from_bytes(const char* ptr);
55
  wide_string from_bytes(const byte_string& str);
56
  wide_string from_bytes(const char* first, const char* last);
57
 
58
  byte_string to_bytes(Elem wchar);
59
  byte_string to_bytes(const Elem* wptr);
60
  byte_string to_bytes(const wide_string& wstr);
61
  byte_string to_bytes(const Elem* first, const Elem* last);
62
 
63
+ size_t converted() const noexcept;
64
  state_type state() const;
65
  private:
66
  byte_string byte_err_string; // exposition only
67
  wide_string wide_err_string; // exposition only
68
  Codecvt* cvtptr; // exposition only
 
75
  The class template describes an object that controls conversions between
76
  wide string objects of class `std::basic_string<Elem, char_traits<Elem>,
77
  Wide_alloc>` and byte string objects of class `std::\\basic_string<char,
78
  char_traits<char>, Byte_alloc>`. The class template defines the types
79
  `wide_string` and `byte_string` as synonyms for these two types.
80
+ Conversion between a sequence of `Elem` values (stored in a
81
+ `wide_string` object) and multibyte sequences (stored in a `byte_string`
82
+ object) is performed by an object of class `Codecvt`, which meets the
83
+ requirements of the standard code-conversion facet `std::codecvt<Elem,
 
84
  char, std::mbstate_t>`.
85
 
86
  An object of this class template stores:
87
 
88
  - `byte_err_string` — a byte string to display on errors
 
91
  freed when the `wstring_convert` object is destroyed)
92
  - `cvtstate` — a conversion state object
93
  - `cvtcount` — a conversion count
94
 
95
  ``` cpp
96
+ typedef std::basic_string<char, char_traits<char>, Byte_alloc> byte_string;
97
  ```
98
 
99
+ The type shall be a synonym for
100
+ `std::basic_string<char, char_traits<char>, Byte_alloc>`
101
 
102
  ``` cpp
103
+ size_t converted() const noexcept;
104
  ```
105
 
106
  *Returns:* `cvtcount`.
107
 
108
  ``` cpp
 
178
  constructed with a byte-error string, the member function shall return
179
  the byte-error string. Otherwise, the member function shall throw an
180
  object of class `std::range_error`.
181
 
182
  ``` cpp
183
+ typedef std::basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
184
  ```
185
 
186
+ The type shall be a synonym for
187
+ `std::basic_string<Elem, char_traits<Elem>, Wide_alloc>`.
188
 
189
  ``` cpp
190
+ explicit wstring_convert(Codecvt* pcvt = new Codecvt);
191
  wstring_convert(Codecvt* pcvt, state_type state);
192
+ explicit wstring_convert(const byte_string& byte_err,
193
  const wide_string& wide_err = wide_string());
194
  ```
195
 
196
+ *Requires:* For the first and second constructors, `pcvt != nullptr`.
197
+
198
  *Effects:* The first constructor shall store `pcvt` in `cvtptr` and
199
  default values in `cvtstate`, `byte_err_string`, and `wide_err_string`.
200
  The second constructor shall store `pcvt` in `cvtptr`, `state` in
201
  `cvtstate`, and default values in `byte_err_string` and
202
  `wide_err_string`; moreover the stored state shall be retained between
 
226
  class wbuffer_convert
227
  : public std::basic_streambuf<Elem, Tr> {
228
  public:
229
  typedef typename Codecvt::state_type state_type;
230
 
231
+ explicit wbuffer_convert(std::streambuf* bytebuf = 0,
232
  Codecvt* pcvt = new Codecvt,
233
  state_type state = state_type());
234
 
235
+ ~wbuffer_convert();
236
+
237
+ wbuffer_convert(const wbuffer_convert&) = delete;
238
+ wbuffer_convert& operator=(const wbuffer_convert&) = delete;
239
+
240
  std::streambuf* rdbuf() const;
241
  std::streambuf* rdbuf(std::streambuf* bytebuf);
242
 
243
  state_type state() const;
244
 
 
252
 
253
  The class template describes a stream buffer that controls the
254
  transmission of elements of type `Elem`, whose character traits are
255
  described by the class `Tr`, to and from a byte stream buffer of type
256
  `std::streambuf`. Conversion between a sequence of `Elem` values and
257
+ multibyte sequences is performed by an object of class `Codecvt`, which
258
+ shall meet the requirements of the standard code-conversion facet
 
259
  `std::codecvt<Elem, char, std::mbstate_t>`.
260
 
261
  An object of this class template stores:
262
 
263
  - `bufptr` — a pointer to its underlying byte stream buffer
 
290
  ```
291
 
292
  The type shall be a synonym for `Codecvt::state_type`.
293
 
294
  ``` cpp
295
+ explicit wbuffer_convert(std::streambuf* bytebuf = 0,
296
  Codecvt* pcvt = new Codecvt, state_type state = state_type());
297
  ```
298
 
299
+ *Requires:* `pcvt != nullptr`.
300
+
301
  *Effects:* The constructor constructs a stream buffer object,
302
  initializes `bufptr` to `bytebuf`, initializes `cvtptr` to `pcvt`, and
303
  initializes `cvtstate` to `state`.
304
 
305
  ``` cpp