tmp/tmpn2qngo47/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Primitive numeric input conversion <a id="charconv.from.chars">[[charconv.from.chars]]</a>
|
| 2 |
+
|
| 3 |
+
All functions named `from_chars` analyze the string \[`first`, `last`)
|
| 4 |
+
for a pattern, where \[`first`, `last`) is required to be a valid range.
|
| 5 |
+
If no characters match the pattern, `value` is unmodified, the member
|
| 6 |
+
`ptr` of the return value is `first` and the member `ec` is equal to
|
| 7 |
+
`errc::invalid_argument`.
|
| 8 |
+
|
| 9 |
+
[*Note 1*: If the pattern allows for an optional sign, but the string
|
| 10 |
+
has no digit characters following the sign, no characters match the
|
| 11 |
+
pattern. — *end note*]
|
| 12 |
+
|
| 13 |
+
Otherwise, the characters matching the pattern are interpreted as a
|
| 14 |
+
representation of a value of the type of `value`. The member `ptr` of
|
| 15 |
+
the return value points to the first character not matching the pattern,
|
| 16 |
+
or has the value `last` if all characters match. If the parsed value is
|
| 17 |
+
not in the range representable by the type of `value`, `value` is
|
| 18 |
+
unmodified and the member `ec` of the return value is equal to
|
| 19 |
+
`errc::result_out_of_range`. Otherwise, `value` is set to the parsed
|
| 20 |
+
value, after rounding according to `round_to_nearest` [[round.style]],
|
| 21 |
+
and the member `ec` is value-initialized.
|
| 22 |
+
|
| 23 |
+
``` cpp
|
| 24 |
+
from_chars_result from_chars(const char* first, const char* last,
|
| 25 |
+
see below& value, int base = 10);
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
*Preconditions:* `base` has a value between 2 and 36 (inclusive).
|
| 29 |
+
|
| 30 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 31 |
+
the `"C"` locale for the given nonzero base, as described for `strtol`,
|
| 32 |
+
except that no `"0x"` or `"0X"` prefix shall appear if the value of
|
| 33 |
+
`base` is 16, and except that `’-’` is the only sign that may appear,
|
| 34 |
+
and only if `value` has a signed type.
|
| 35 |
+
|
| 36 |
+
*Throws:* Nothing.
|
| 37 |
+
|
| 38 |
+
*Remarks:* The implementation shall provide overloads for all signed and
|
| 39 |
+
unsigned integer types and `char` as the referenced type of the
|
| 40 |
+
parameter `value`.
|
| 41 |
+
|
| 42 |
+
``` cpp
|
| 43 |
+
from_chars_result from_chars(const char* first, const char* last, float& value,
|
| 44 |
+
chars_format fmt = chars_format::general);
|
| 45 |
+
from_chars_result from_chars(const char* first, const char* last, double& value,
|
| 46 |
+
chars_format fmt = chars_format::general);
|
| 47 |
+
from_chars_result from_chars(const char* first, const char* last, long double& value,
|
| 48 |
+
chars_format fmt = chars_format::general);
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
*Preconditions:* `fmt` has the value of one of the enumerators of
|
| 52 |
+
`chars_format`.
|
| 53 |
+
|
| 54 |
+
*Effects:* The pattern is the expected form of the subject sequence in
|
| 55 |
+
the `"C"` locale, as described for `strtod`, except that
|
| 56 |
+
|
| 57 |
+
- the sign `’+’` may only appear in the exponent part;
|
| 58 |
+
- if `fmt` has `chars_format::scientific` set but not
|
| 59 |
+
`chars_format::fixed`, the otherwise optional exponent part shall
|
| 60 |
+
appear;
|
| 61 |
+
- if `fmt` has `chars_format::fixed` set but not
|
| 62 |
+
`chars_format::scientific`, the optional exponent part shall not
|
| 63 |
+
appear; and
|
| 64 |
+
- if `fmt` is `chars_format::hex`, the prefix `"0x"` or `"0X"` is
|
| 65 |
+
assumed. \[*Example 1*: The string `0x123` is parsed to have the value
|
| 66 |
+
`0` with remaining characters `x123`. — *end example*]
|
| 67 |
+
|
| 68 |
+
In any case, the resulting `value` is one of at most two floating-point
|
| 69 |
+
values closest to the value of the string matching the pattern.
|
| 70 |
+
|
| 71 |
+
*Throws:* Nothing.
|
| 72 |
+
|
| 73 |
+
See also: ISO C 7.22.1.3, 7.22.1.4
|
| 74 |
+
|