From Jason Turner

[char.traits]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpy59wwnl0/{from.md → to.md} +61 -61
tmp/tmpy59wwnl0/{from.md → to.md} RENAMED
@@ -7,21 +7,21 @@ four specializations, `char_traits<char>`, `char_traits<char16_t>`,
7
  requirements.
8
 
9
  Most classes specified in Clauses  [[string.classes]] and 
10
  [[input.output]] need a set of related types and functions to complete
11
  the definition of their semantics. These types and functions are
12
- provided as a set of member typedefs and functions in the template
13
- parameter traits used by each such template. This subclause defines
14
- the semantics of these members.
15
 
16
  To specialize those templates to generate a string or iostream class to
17
  handle a particular character container type `CharT`, that and its
18
  related character traits class `Traits` are passed as a pair of
19
  parameters to the string or iostream template as parameters `charT` and
20
  `traits`. `Traits::char_type` shall be the same as `CharT`.
21
 
22
- This subclause specifies a struct template, `char_traits<charT>`, and
23
  four explicit specializations of it, `char_traits<{}char>`,
24
  `char_traits<char16_t>`, `char_traits<char32_t>`, and
25
  `char_traits<wchar_t>`, all of which appear in the header `<string>` and
26
  satisfy the requirements below.
27
 
@@ -29,36 +29,36 @@ satisfy the requirements below.
29
 
30
  In Table  [[tab:char.traits.require]], `X` denotes a Traits class
31
  defining types and functions for the character container type `CharT`;
32
  `c` and `d` denote values of type `CharT`; `p` and `q` denote values of
33
  type `const CharT*`; `s` denotes a value of type `CharT*`; `n`, `i` and
34
- `j` denote values of type `std::size_t`; `e` and `f` denote values of
35
- type `X::int_type`; `pos` denotes a value of type `X::pos_type`; `state`
36
  denotes a value of type `X::state_type`; and `r` denotes an lvalue of
37
  type `CharT`. Operations on Traits shall not throw exceptions.
38
 
39
- The struct template
40
 
41
  ``` cpp
42
  template<class charT> struct char_traits;
43
  ```
44
 
45
  shall be provided in the header `<string>` as a basis for explicit
46
  specializations.
47
 
48
- ### traits typedefs <a id="char.traits.typedefs">[[char.traits.typedefs]]</a>
49
 
50
  ``` cpp
51
- typedef CHAR_T char_type;
52
  ```
53
 
54
  The type `char_type` is used to refer to the character container type in
55
  the implementation of the library classes defined in  [[string.classes]]
56
  and Clause  [[input.output]].
57
 
58
  ``` cpp
59
- typedef INT_T int_type;
60
  ```
61
 
62
  *Requires:* For a certain character container type `char_type`, a
63
  related container type `INT_T` shall be a type or class which can
64
  represent all of the valid characters converted from the corresponding
@@ -66,25 +66,25 @@ represent all of the valid characters converted from the corresponding
66
  `int_type` represents a character container type which can hold
67
  end-of-file to be used as a return type of the iostream class member
68
  functions.[^1]
69
 
70
  ``` cpp
71
- typedef implementation-defined off_type;
72
- typedef implementation-defined pos_type;
73
  ```
74
 
75
  *Requires:* Requirements for `off_type` and `pos_type` are described
76
  in  [[iostreams.limits.pos]] and [[iostream.forward]].
77
 
78
  ``` cpp
79
- typedef STATE_T state_type;
80
  ```
81
 
82
  *Requires:* `state_type` shall meet the requirements of `CopyAssignable`
83
- (Table  [[copyassignable]]), `CopyConstructible`
84
- (Table  [[copyconstructible]]), and `DefaultConstructible`
85
- (Table  [[defaultconstructible]]) types.
86
 
87
  ### `char_traits` specializations <a id="char.traits.specializations">[[char.traits.specializations]]</a>
88
 
89
  ``` cpp
90
  namespace std {
@@ -93,35 +93,35 @@ namespace std {
93
  template<> struct char_traits<char32_t>;
94
  template<> struct char_traits<wchar_t>;
95
  }
96
  ```
97
 
98
- The header `<string>` shall define four specializations of the template
99
- struct `char_traits`: `char_traits<{}char>`, `char_traits<char16_t>`,
100
  `char_traits<char32_t>`, and `char_traits<wchar_t>`.
101
 
102
  The requirements for the members of these specializations are given in
103
  Clause  [[char.traits.require]].
104
 
105
  #### `struct char_traits<char>` <a id="char.traits.specializations.char">[[char.traits.specializations.char]]</a>
106
 
107
  ``` cpp
108
  namespace std {
109
  template<> struct char_traits<char> {
110
- typedef char char_type;
111
- typedef int int_type;
112
- typedef streamoff off_type;
113
- typedef streampos pos_type;
114
- typedef mbstate_t state_type;
115
 
116
- static void assign(char_type& c1, const char_type& c2) noexcept;
117
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
118
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
119
 
120
- static int compare(const char_type* s1, const char_type* s2, size_t n);
121
- static size_t length(const char_type* s);
122
- static const char_type* find(const char_type* s, size_t n,
123
  const char_type& a);
124
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
125
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
126
  static char_type* assign(char_type* s, size_t n, char_type a);
127
 
@@ -151,32 +151,32 @@ the conversion states that can occur in an *implementation-defined* set
151
  of supported multibyte character encoding rules.
152
 
153
  The two-argument member `assign` shall be defined identically to the
154
  built-in operator `=`. The two-argument members `eq` and `lt` shall be
155
  defined identically to the built-in operators `==` and `<` for type
156
- `unsigned` `char`.
157
 
158
  The member `eof()` shall return `EOF`.
159
 
160
  #### `struct char_traits<char16_t>` <a id="char.traits.specializations.char16_t">[[char.traits.specializations.char16_t]]</a>
161
 
162
  ``` cpp
163
  namespace std {
164
  template<> struct char_traits<char16_t> {
165
- typedef char16_t char_type;
166
- typedef uint_least16_t int_type;
167
- typedef streamoff off_type;
168
- typedef u16streampos pos_type;
169
- typedef mbstate_t state_type;
170
 
171
- static void assign(char_type& c1, const char_type& c2) noexcept;
172
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
173
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
174
 
175
- static int compare(const char_type* s1, const char_type* s2, size_t n);
176
- static size_t length(const char_type* s);
177
- static const char_type* find(const char_type* s, size_t n,
178
  const char_type& a);
179
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
180
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
181
  static char_type* assign(char_type* s, size_t n, char_type a);
182
 
@@ -188,12 +188,12 @@ namespace std {
188
  };
189
  }
190
  ```
191
 
192
  The type `u16streampos` shall be an *implementation-defined* type that
193
- satisfies the requirements for pos_type in  [[iostreams.limits.pos]] and
194
- [[iostream.forward]].
195
 
196
  The two-argument members `assign`, `eq`, and `lt` shall be defined
197
  identically to the built-in operators `=`, `==`, and `<` respectively.
198
 
199
  The member `eof()` shall return an *implementation-defined* constant
@@ -202,23 +202,23 @@ that cannot appear as a valid UTF-16 code unit.
202
  #### `struct char_traits<char32_t>` <a id="char.traits.specializations.char32_t">[[char.traits.specializations.char32_t]]</a>
203
 
204
  ``` cpp
205
  namespace std {
206
  template<> struct char_traits<char32_t> {
207
- typedef char32_t char_type;
208
- typedef uint_least32_t int_type;
209
- typedef streamoff off_type;
210
- typedef u32streampos pos_type;
211
- typedef mbstate_t state_type;
212
 
213
- static void assign(char_type& c1, const char_type& c2) noexcept;
214
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
215
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
216
 
217
- static int compare(const char_type* s1, const char_type* s2, size_t n);
218
- static size_t length(const char_type* s);
219
- static const char_type* find(const char_type* s, size_t n,
220
  const char_type& a);
221
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
222
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
223
  static char_type* assign(char_type* s, size_t n, char_type a);
224
 
@@ -230,12 +230,12 @@ namespace std {
230
  };
231
  }
232
  ```
233
 
234
  The type `u32streampos` shall be an *implementation-defined* type that
235
- satisfies the requirements for pos_type in  [[iostreams.limits.pos]] and
236
- [[iostream.forward]].
237
 
238
  The two-argument members `assign`, `eq`, and `lt` shall be defined
239
  identically to the built-in operators `=`, `==`, and `<` respectively.
240
 
241
  The member `eof()` shall return an *implementation-defined* constant
@@ -244,23 +244,23 @@ that cannot appear as a Unicode code point.
244
  #### `struct char_traits<wchar_t>` <a id="char.traits.specializations.wchar.t">[[char.traits.specializations.wchar.t]]</a>
245
 
246
  ``` cpp
247
  namespace std {
248
  template<> struct char_traits<wchar_t> {
249
- typedef wchar_t char_type;
250
- typedef wint_t int_type;
251
- typedef streamoff off_type;
252
- typedef wstreampos pos_type;
253
- typedef mbstate_t state_type;
254
 
255
- static void assign(char_type& c1, const char_type& c2) noexcept;
256
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
257
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
258
 
259
- static int compare(const char_type* s1, const char_type* s2, size_t n);
260
- static size_t length(const char_type* s);
261
- static const char_type* find(const char_type* s, size_t n,
262
  const char_type& a);
263
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
264
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
265
  static char_type* assign(char_type* s, size_t n, char_type a);
266
 
@@ -275,12 +275,12 @@ namespace std {
275
 
276
  The defined types for `int_type`, `pos_type`, and `state_type` shall be
277
  `wint_t`, `wstreampos`, and `mbstate_t` respectively.
278
 
279
  The type `wstreampos` shall be an *implementation-defined* type that
280
- satisfies the requirements for pos_type in  [[iostreams.limits.pos]] and
281
- [[iostream.forward]].
282
 
283
  The type `mbstate_t` is defined in `<cwchar>` and can represent any of
284
  the conversion states that can occur in an *implementation-defined* set
285
  of supported multibyte character encoding rules.
286
 
 
7
  requirements.
8
 
9
  Most classes specified in Clauses  [[string.classes]] and 
10
  [[input.output]] need a set of related types and functions to complete
11
  the definition of their semantics. These types and functions are
12
+ provided as a set of member *typedef-name*s and functions in the
13
+ template parameter `traits` used by each such template. This subclause
14
+ defines the semantics of these members.
15
 
16
  To specialize those templates to generate a string or iostream class to
17
  handle a particular character container type `CharT`, that and its
18
  related character traits class `Traits` are passed as a pair of
19
  parameters to the string or iostream template as parameters `charT` and
20
  `traits`. `Traits::char_type` shall be the same as `CharT`.
21
 
22
+ This subclause specifies a class template, `char_traits<charT>`, and
23
  four explicit specializations of it, `char_traits<{}char>`,
24
  `char_traits<char16_t>`, `char_traits<char32_t>`, and
25
  `char_traits<wchar_t>`, all of which appear in the header `<string>` and
26
  satisfy the requirements below.
27
 
 
29
 
30
  In Table  [[tab:char.traits.require]], `X` denotes a Traits class
31
  defining types and functions for the character container type `CharT`;
32
  `c` and `d` denote values of type `CharT`; `p` and `q` denote values of
33
  type `const CharT*`; `s` denotes a value of type `CharT*`; `n`, `i` and
34
+ `j` denote values of type `size_t`; `e` and `f` denote values of type
35
+ `X::int_type`; `pos` denotes a value of type `X::pos_type`; `state`
36
  denotes a value of type `X::state_type`; and `r` denotes an lvalue of
37
  type `CharT`. Operations on Traits shall not throw exceptions.
38
 
39
+ The class template
40
 
41
  ``` cpp
42
  template<class charT> struct char_traits;
43
  ```
44
 
45
  shall be provided in the header `<string>` as a basis for explicit
46
  specializations.
47
 
48
+ ### Traits typedefs <a id="char.traits.typedefs">[[char.traits.typedefs]]</a>
49
 
50
  ``` cpp
51
+ using char_type = CHAR_T;
52
  ```
53
 
54
  The type `char_type` is used to refer to the character container type in
55
  the implementation of the library classes defined in  [[string.classes]]
56
  and Clause  [[input.output]].
57
 
58
  ``` cpp
59
+ using int_type = INT_T;
60
  ```
61
 
62
  *Requires:* For a certain character container type `char_type`, a
63
  related container type `INT_T` shall be a type or class which can
64
  represent all of the valid characters converted from the corresponding
 
66
  `int_type` represents a character container type which can hold
67
  end-of-file to be used as a return type of the iostream class member
68
  functions.[^1]
69
 
70
  ``` cpp
71
+ using off_type = implementation-defined;
72
+ using pos_type = implementation-defined;
73
  ```
74
 
75
  *Requires:* Requirements for `off_type` and `pos_type` are described
76
  in  [[iostreams.limits.pos]] and [[iostream.forward]].
77
 
78
  ``` cpp
79
+ using state_type = STATE_T;
80
  ```
81
 
82
  *Requires:* `state_type` shall meet the requirements of `CopyAssignable`
83
+ (Table  [[tab:copyassignable]]), `CopyConstructible`
84
+ (Table  [[tab:copyconstructible]]), and `DefaultConstructible`
85
+ (Table  [[tab:defaultconstructible]]) types.
86
 
87
  ### `char_traits` specializations <a id="char.traits.specializations">[[char.traits.specializations]]</a>
88
 
89
  ``` cpp
90
  namespace std {
 
93
  template<> struct char_traits<char32_t>;
94
  template<> struct char_traits<wchar_t>;
95
  }
96
  ```
97
 
98
+ The header `<string>` shall define four specializations of the class
99
+ template `char_traits`: `char_traits<{}char>`, `char_traits<char16_t>`,
100
  `char_traits<char32_t>`, and `char_traits<wchar_t>`.
101
 
102
  The requirements for the members of these specializations are given in
103
  Clause  [[char.traits.require]].
104
 
105
  #### `struct char_traits<char>` <a id="char.traits.specializations.char">[[char.traits.specializations.char]]</a>
106
 
107
  ``` cpp
108
  namespace std {
109
  template<> struct char_traits<char> {
110
+ using char_type = char;
111
+ using int_type = int;
112
+ using off_type = streamoff;
113
+ using pos_type = streampos;
114
+ using state_type = mbstate_t;
115
 
116
+ static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
117
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
118
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
119
 
120
+ static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
121
+ static constexpr size_t length(const char_type* s);
122
+ static constexpr const char_type* find(const char_type* s, size_t n,
123
  const char_type& a);
124
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
125
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
126
  static char_type* assign(char_type* s, size_t n, char_type a);
127
 
 
151
  of supported multibyte character encoding rules.
152
 
153
  The two-argument member `assign` shall be defined identically to the
154
  built-in operator `=`. The two-argument members `eq` and `lt` shall be
155
  defined identically to the built-in operators `==` and `<` for type
156
+ `unsigned char`.
157
 
158
  The member `eof()` shall return `EOF`.
159
 
160
  #### `struct char_traits<char16_t>` <a id="char.traits.specializations.char16_t">[[char.traits.specializations.char16_t]]</a>
161
 
162
  ``` cpp
163
  namespace std {
164
  template<> struct char_traits<char16_t> {
165
+ using char_type = char16_t;
166
+ using int_type = uint_least16_t;
167
+ using off_type = streamoff;
168
+ using pos_type = u16streampos;
169
+ using state_type = mbstate_t;
170
 
171
+ static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
172
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
173
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
174
 
175
+ static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
176
+ static constexpr size_t length(const char_type* s);
177
+ static constexpr const char_type* find(const char_type* s, size_t n,
178
  const char_type& a);
179
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
180
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
181
  static char_type* assign(char_type* s, size_t n, char_type a);
182
 
 
188
  };
189
  }
190
  ```
191
 
192
  The type `u16streampos` shall be an *implementation-defined* type that
193
+ satisfies the requirements for `pos_type` in  [[iostreams.limits.pos]]
194
+ and [[iostream.forward]].
195
 
196
  The two-argument members `assign`, `eq`, and `lt` shall be defined
197
  identically to the built-in operators `=`, `==`, and `<` respectively.
198
 
199
  The member `eof()` shall return an *implementation-defined* constant
 
202
  #### `struct char_traits<char32_t>` <a id="char.traits.specializations.char32_t">[[char.traits.specializations.char32_t]]</a>
203
 
204
  ``` cpp
205
  namespace std {
206
  template<> struct char_traits<char32_t> {
207
+ using char_type = char32_t;
208
+ using int_type = uint_least32_t;
209
+ using off_type = streamoff;
210
+ using pos_type = u32streampos;
211
+ using state_type = mbstate_t;
212
 
213
+ static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
214
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
215
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
216
 
217
+ static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
218
+ static constexpr size_t length(const char_type* s);
219
+ static constexpr const char_type* find(const char_type* s, size_t n,
220
  const char_type& a);
221
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
222
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
223
  static char_type* assign(char_type* s, size_t n, char_type a);
224
 
 
230
  };
231
  }
232
  ```
233
 
234
  The type `u32streampos` shall be an *implementation-defined* type that
235
+ satisfies the requirements for `pos_type` in  [[iostreams.limits.pos]]
236
+ and [[iostream.forward]].
237
 
238
  The two-argument members `assign`, `eq`, and `lt` shall be defined
239
  identically to the built-in operators `=`, `==`, and `<` respectively.
240
 
241
  The member `eof()` shall return an *implementation-defined* constant
 
244
  #### `struct char_traits<wchar_t>` <a id="char.traits.specializations.wchar.t">[[char.traits.specializations.wchar.t]]</a>
245
 
246
  ``` cpp
247
  namespace std {
248
  template<> struct char_traits<wchar_t> {
249
+ using char_type = wchar_t;
250
+ using int_type = wint_t;
251
+ using off_type = streamoff;
252
+ using pos_type = wstreampos;
253
+ using state_type = mbstate_t;
254
 
255
+ static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
256
  static constexpr bool eq(char_type c1, char_type c2) noexcept;
257
  static constexpr bool lt(char_type c1, char_type c2) noexcept;
258
 
259
+ static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
260
+ static constexpr size_t length(const char_type* s);
261
+ static constexpr const char_type* find(const char_type* s, size_t n,
262
  const char_type& a);
263
  static char_type* move(char_type* s1, const char_type* s2, size_t n);
264
  static char_type* copy(char_type* s1, const char_type* s2, size_t n);
265
  static char_type* assign(char_type* s, size_t n, char_type a);
266
 
 
275
 
276
  The defined types for `int_type`, `pos_type`, and `state_type` shall be
277
  `wint_t`, `wstreampos`, and `mbstate_t` respectively.
278
 
279
  The type `wstreampos` shall be an *implementation-defined* type that
280
+ satisfies the requirements for `pos_type` in  [[iostreams.limits.pos]]
281
+ and [[iostream.forward]].
282
 
283
  The type `mbstate_t` is defined in `<cwchar>` and can represent any of
284
  the conversion states that can occur in an *implementation-defined* set
285
  of supported multibyte character encoding rules.
286