- tmp/tmp3nv41xgx/{from.md → to.md} +24 -119
tmp/tmp3nv41xgx/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
### The numeric category <a id="category.numeric">[[category.numeric]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
The classes `num_get<>` and `num_put<>` handle numeric formatting and
|
| 4 |
parsing. Virtual functions are provided for several numeric types.
|
| 5 |
Implementations may (but are not required to) delegate extraction of
|
| 6 |
smaller types to extractors for larger types.[^11]
|
| 7 |
|
|
@@ -16,14 +18,16 @@ specifications [[locale.categories]], and to its imbued locale for the
|
|
| 16 |
`numpunct<>` facet to identify all numeric punctuation preferences, and
|
| 17 |
also for the `ctype<>` facet to perform character classification.
|
| 18 |
|
| 19 |
Extractor and inserter members of the standard iostreams use `num_get<>`
|
| 20 |
and `num_put<>` member functions for formatting and parsing numeric
|
| 21 |
-
values
|
| 22 |
|
| 23 |
#### Class template `num_get` <a id="locale.num.get">[[locale.num.get]]</a>
|
| 24 |
|
|
|
|
|
|
|
| 25 |
``` cpp
|
| 26 |
namespace std {
|
| 27 |
template<class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 28 |
class num_get : public locale::facet {
|
| 29 |
public:
|
|
@@ -154,129 +158,27 @@ The details of this operation occur in three stages
|
|
| 154 |
determined in stage 1.
|
| 155 |
- Stage 3: Store results
|
| 156 |
|
| 157 |
The details of the stages are presented below.
|
| 158 |
|
| 159 |
-
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
```
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
``
|
| 169 |
|
| 170 |
-
|
| 171 |
-
conversion specifier as indicated in [[facet.num.get.int]]. The
|
| 172 |
-
table is ordered. That is, the first line whose condition is true
|
| 173 |
-
applies.
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
| State | `stdio` equivalent |
|
| 178 |
-
| ------------------------ | ------------------ |
|
| 179 |
-
| `basefield == oct` | `%o` |
|
| 180 |
-
| `basefield == hex` | `%X` |
|
| 181 |
-
| `basefield == 0` | `%i` `signed` integral type | `%d` |
|
| 182 |
-
| `unsigned` integral type | `%u` |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
For conversions to a floating-point type the specifier is `%g`.
|
| 186 |
-
|
| 187 |
-
For conversions to `void*` the specifier is `%p`.
|
| 188 |
-
|
| 189 |
-
A length modifier is added to the conversion specification, if needed,
|
| 190 |
-
as indicated in [[facet.num.get.length]].
|
| 191 |
-
|
| 192 |
-
**Table: Length modifier** <a id="facet.num.get.length">[facet.num.get.length]</a>
|
| 193 |
-
|
| 194 |
-
| Type | Length modifier |
|
| 195 |
-
| -------------------- | --------------- |
|
| 196 |
-
| `short` | `h` |
|
| 197 |
-
| `unsigned short` | `h` |
|
| 198 |
-
| `long` | `l` |
|
| 199 |
-
| `unsigned long` | `l` |
|
| 200 |
-
| `long long` | `ll` |
|
| 201 |
-
| `unsigned long long` | `ll` |
|
| 202 |
-
| `double` | `l` |
|
| 203 |
-
| `long double` | `L` |
|
| 204 |
-
|
| 205 |
-
- **Stage 2:**
|
| 206 |
-
|
| 207 |
-
If `in == end` then stage 2 terminates. Otherwise a `charT` is taken
|
| 208 |
-
from `in` and local variables are initialized as if by
|
| 209 |
-
|
| 210 |
-
``` cpp
|
| 211 |
-
char_type ct = *in;
|
| 212 |
-
char c = src[find(atoms, atoms + sizeof(src) - 1, ct) - atoms];
|
| 213 |
-
if (ct == use_facet<numpunct<charT>>(loc).decimal_point())
|
| 214 |
-
c = '.';
|
| 215 |
-
bool discard =
|
| 216 |
-
ct == use_facet<numpunct<charT>>(loc).thousands_sep()
|
| 217 |
-
&& use_facet<numpunct<charT>>(loc).grouping().length() != 0;
|
| 218 |
-
```
|
| 219 |
-
|
| 220 |
-
where the values `src` and `atoms` are defined as if by:
|
| 221 |
-
|
| 222 |
-
``` cpp
|
| 223 |
-
static const char src[] = "0123456789abcdefxABCDEFX+-";
|
| 224 |
-
char_type atoms[sizeof(src)];
|
| 225 |
-
use_facet<ctype<charT>>(loc).widen(src, src + sizeof(src), atoms);
|
| 226 |
-
```
|
| 227 |
-
|
| 228 |
-
for this value of `loc`.
|
| 229 |
-
|
| 230 |
-
If `discard` is `true`, then if `’.’` has not yet been accumulated, then
|
| 231 |
-
the position of the character is remembered, but the character is
|
| 232 |
-
otherwise ignored. Otherwise, if `’.’` has already been accumulated, the
|
| 233 |
-
character is discarded and Stage 2 terminates. If it is not discarded,
|
| 234 |
-
then a check is made to determine if `c` is allowed as the next
|
| 235 |
-
character of an input field of the conversion specifier returned by
|
| 236 |
-
Stage 1. If so, it is accumulated.
|
| 237 |
-
|
| 238 |
-
If the character is either discarded or accumulated then `in` is
|
| 239 |
-
advanced by `++in` and processing returns to the beginning of stage 2.
|
| 240 |
-
|
| 241 |
-
- **Stage 3:**
|
| 242 |
-
|
| 243 |
-
The sequence of `char`s accumulated in stage 2 (the field) is converted
|
| 244 |
-
to a numeric value by the rules of one of the functions declared in the
|
| 245 |
-
header `<cstdlib>`:
|
| 246 |
-
|
| 247 |
-
- For a signed integer value, the function `strtoll`.
|
| 248 |
-
|
| 249 |
-
- For an unsigned integer value, the function `strtoull`.
|
| 250 |
-
|
| 251 |
-
- For a `float` value, the function `strtof`.
|
| 252 |
-
|
| 253 |
-
- For a `double` value, the function `strtod`.
|
| 254 |
-
|
| 255 |
-
- For a `long double` value, the function `strtold`.
|
| 256 |
-
|
| 257 |
-
The numeric value to be stored can be one of:
|
| 258 |
-
|
| 259 |
-
- zero, if the conversion function does not convert the entire field.
|
| 260 |
-
|
| 261 |
-
- the most positive (or negative) representable value, if the field to
|
| 262 |
-
be converted to a signed integer type represents a value too large
|
| 263 |
-
positive (or negative) to be represented in `val`.
|
| 264 |
-
|
| 265 |
-
- the most positive representable value, if the field to be converted to
|
| 266 |
-
an unsigned integer type represents a value that cannot be represented
|
| 267 |
-
in `val`.
|
| 268 |
-
|
| 269 |
-
- the converted value, otherwise.
|
| 270 |
-
|
| 271 |
-
The resultant numeric value is stored in `val`. If the conversion
|
| 272 |
-
function does not convert the entire field, or if the field represents a
|
| 273 |
-
value outside the range of representable values, `ios_base::failbit` is
|
| 274 |
-
assigned to `err`.
|
| 275 |
|
| 276 |
Digit grouping is checked. That is, the positions of discarded
|
| 277 |
-
separators
|
| 278 |
`use_facet<numpunct<charT>>(loc).grouping()`. If they are not consistent
|
| 279 |
then `ios_base::failbit` is assigned to `err`.
|
| 280 |
|
| 281 |
In any case, if stage 2 processing was terminated by the test for
|
| 282 |
`in == end` then `err |= ios_base::eofbit` is performed.
|
|
@@ -309,11 +211,11 @@ character successfully matched. If `val` is set, then `err` is set to
|
|
| 309 |
`str.goodbit`; or to `str.eofbit` if, when seeking another character to
|
| 310 |
match, it is found that `(in == end)`. If `val` is not set, then `err`
|
| 311 |
is set to `str.failbit`; or to `(str.failbit|str.eofbit)` if the reason
|
| 312 |
for the failure was that `(in == end)`.
|
| 313 |
|
| 314 |
-
[*Example
|
| 315 |
sequence `"a"` yields `val == true` and `err == str.eofbit`; the input
|
| 316 |
sequence `"abc"` yields `err = str.failbit`, with `in` ending at the
|
| 317 |
`’c’` element. For targets `true`: `"1"` and `false`: `"0"`, the input
|
| 318 |
sequence `"1"` yields `val == true` and `err == str.goodbit`. For empty
|
| 319 |
targets `("")`, any input sequence yields
|
|
@@ -321,10 +223,12 @@ targets `("")`, any input sequence yields
|
|
| 321 |
|
| 322 |
*Returns:* `in`.
|
| 323 |
|
| 324 |
#### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
|
| 325 |
|
|
|
|
|
|
|
| 326 |
``` cpp
|
| 327 |
namespace std {
|
| 328 |
template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 329 |
class num_put : public locale::facet {
|
| 330 |
public:
|
|
@@ -524,24 +428,25 @@ const numpunct<charT>& punct = use_facet<numpunct<charT>>(loc);
|
|
| 524 |
```
|
| 525 |
|
| 526 |
For arithmetic types, `punct.thousands_sep()` characters are inserted
|
| 527 |
into the sequence as determined by the value returned by
|
| 528 |
`punct.do_grouping()` using the method described
|
| 529 |
-
in [[facet.numpunct.virtuals]]
|
| 530 |
|
| 531 |
-
Decimal point characters(.) are replaced by `punct.decimal_point()`
|
| 532 |
|
| 533 |
- **Stage 3:**
|
| 534 |
|
| 535 |
A local variable is initialized as
|
| 536 |
|
| 537 |
``` cpp
|
| 538 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 539 |
```
|
| 540 |
|
| 541 |
-
The location of any padding[^12]
|
| 542 |
-
|
|
|
|
| 543 |
|
| 544 |
**Table: Fill padding** <a id="facet.num.put.fill">[facet.num.put.fill]</a>
|
| 545 |
|
| 546 |
| State | Location |
|
| 547 |
| ------------------------------------------------------------------------------ | ------------------ |
|
|
|
|
| 1 |
### The numeric category <a id="category.numeric">[[category.numeric]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="category.numeric.general">[[category.numeric.general]]</a>
|
| 4 |
+
|
| 5 |
The classes `num_get<>` and `num_put<>` handle numeric formatting and
|
| 6 |
parsing. Virtual functions are provided for several numeric types.
|
| 7 |
Implementations may (but are not required to) delegate extraction of
|
| 8 |
smaller types to extractors for larger types.[^11]
|
| 9 |
|
|
|
|
| 18 |
`numpunct<>` facet to identify all numeric punctuation preferences, and
|
| 19 |
also for the `ctype<>` facet to perform character classification.
|
| 20 |
|
| 21 |
Extractor and inserter members of the standard iostreams use `num_get<>`
|
| 22 |
and `num_put<>` member functions for formatting and parsing numeric
|
| 23 |
+
values [[istream.formatted.reqmts]], [[ostream.formatted.reqmts]].
|
| 24 |
|
| 25 |
#### Class template `num_get` <a id="locale.num.get">[[locale.num.get]]</a>
|
| 26 |
|
| 27 |
+
##### General <a id="locale.num.get.general">[[locale.num.get.general]]</a>
|
| 28 |
+
|
| 29 |
``` cpp
|
| 30 |
namespace std {
|
| 31 |
template<class charT, class InputIterator = istreambuf_iterator<charT>>
|
| 32 |
class num_get : public locale::facet {
|
| 33 |
public:
|
|
|
|
| 158 |
determined in stage 1.
|
| 159 |
- Stage 3: Store results
|
| 160 |
|
| 161 |
The details of the stages are presented below.
|
| 162 |
|
| 163 |
+
[*Example 1*:
|
| 164 |
|
| 165 |
+
Given an input sequence of `"0x1a.bp+07p"`,
|
| 166 |
|
| 167 |
+
- if the conversion specifier returned by Stage 1 is `%d`, `"0"` is
|
| 168 |
+
accumulated;
|
| 169 |
+
- if the conversion specifier returned by Stage 1 is `%i`, `"0x1a"` are
|
| 170 |
+
accumulated;
|
| 171 |
+
- if the conversion specifier returned by Stage 1 is `%g`,
|
| 172 |
+
`"0x1a.bp+07"` are accumulated.
|
| 173 |
|
| 174 |
+
In all cases, the remainder is left in the input.
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
Digit grouping is checked. That is, the positions of discarded
|
| 179 |
+
separators are examined for consistency with
|
| 180 |
`use_facet<numpunct<charT>>(loc).grouping()`. If they are not consistent
|
| 181 |
then `ios_base::failbit` is assigned to `err`.
|
| 182 |
|
| 183 |
In any case, if stage 2 processing was terminated by the test for
|
| 184 |
`in == end` then `err |= ios_base::eofbit` is performed.
|
|
|
|
| 211 |
`str.goodbit`; or to `str.eofbit` if, when seeking another character to
|
| 212 |
match, it is found that `(in == end)`. If `val` is not set, then `err`
|
| 213 |
is set to `str.failbit`; or to `(str.failbit|str.eofbit)` if the reason
|
| 214 |
for the failure was that `(in == end)`.
|
| 215 |
|
| 216 |
+
[*Example 2*: For targets `true`: `"a"` and `false`: `"abb"`, the input
|
| 217 |
sequence `"a"` yields `val == true` and `err == str.eofbit`; the input
|
| 218 |
sequence `"abc"` yields `err = str.failbit`, with `in` ending at the
|
| 219 |
`’c’` element. For targets `true`: `"1"` and `false`: `"0"`, the input
|
| 220 |
sequence `"1"` yields `val == true` and `err == str.goodbit`. For empty
|
| 221 |
targets `("")`, any input sequence yields
|
|
|
|
| 223 |
|
| 224 |
*Returns:* `in`.
|
| 225 |
|
| 226 |
#### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
|
| 227 |
|
| 228 |
+
##### General <a id="locale.nm.put.general">[[locale.nm.put.general]]</a>
|
| 229 |
+
|
| 230 |
``` cpp
|
| 231 |
namespace std {
|
| 232 |
template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
|
| 233 |
class num_put : public locale::facet {
|
| 234 |
public:
|
|
|
|
| 428 |
```
|
| 429 |
|
| 430 |
For arithmetic types, `punct.thousands_sep()` characters are inserted
|
| 431 |
into the sequence as determined by the value returned by
|
| 432 |
`punct.do_grouping()` using the method described
|
| 433 |
+
in [[facet.numpunct.virtuals]].
|
| 434 |
|
| 435 |
+
Decimal point characters(.) are replaced by `punct.decimal_point()`.
|
| 436 |
|
| 437 |
- **Stage 3:**
|
| 438 |
|
| 439 |
A local variable is initialized as
|
| 440 |
|
| 441 |
``` cpp
|
| 442 |
fmtflags adjustfield = (flags & (ios_base::adjustfield));
|
| 443 |
```
|
| 444 |
|
| 445 |
+
The location of any padding[^12]
|
| 446 |
+
|
| 447 |
+
is determined according to [[facet.num.put.fill]].
|
| 448 |
|
| 449 |
**Table: Fill padding** <a id="facet.num.put.fill">[facet.num.put.fill]</a>
|
| 450 |
|
| 451 |
| State | Location |
|
| 452 |
| ------------------------------------------------------------------------------ | ------------------ |
|