|
noexcept |
Converts a string representation of a floating-point value to the specified numeric representation. .
CharType | A type of character of the string containing the floating-point value. |
FloatingPointType | A type used to hold the numeric representation of data contained within the string. |
first | A pointer to the first character of the sequence representing the number to convert to FloatingPointType . | |
last | A pointer to the first character after the last element of the sequence. No reads from beyond and including last will be performed by the function. | |
[out] | value | An output parameter to receive the result of conversion. |
fmt | A bitmask specifying the expected format of the string representation of the floating-point number to convert. See details below. |
fmt
, or last
if there is no such a character.The function does not accept prefixes (i.e. "0x" or "0X" for the base 16) nor does it accept the plus ('+') sign - only an optional minus ('-') character is accepted at the beginning of the pattern to specify a negative significand (exponent specification can start with both plus and minus).
If fmt
includes chars_format::scientific, but does not include chars_format::fixed, then the explicit exponent specification is required, or the function will fail with std::errc::invalid_argument code.
If fmt
includes chars_format::fixed, but does not include chars_format::scientific, then exponent is not allowed and will be discarded, if one is present in the input, i.e. only the "1.23" part of the "1.23E+5" will match the pattern.
If both chars_format::fixed and chars_format::scientific are specified by fmt
(i.e. fmt
specifies chars_format::general), then the exponent is optional.
fmt
must include either chars_format::fixed or chars_format::scientific or both.
if fmt
also includes chars_format::hex, the string-representation of the floating-point number is expected to be in hexadecimal form, i.e. use hexadecimal digits and point to specify mantissa, the 'P' or 'p' (not 'E' or 'e') character to start the exponential part, and integral decimal value of a binary exponent.
If the string does not match the pattern of a floating-point number the return code (the ec
field of the return value) is std::errc::invalid_argument, and value
remains unchanged.
Otherwise, if the conversion yields a floating-point overflow, the return code is std::errc::result_out_of_range. Likewise, value
remains unchanged.
Otherwise, if the functions succeeds, the return code is a value-initialized std::errc code.
If a floating-point underflow happens, the returned value is rounded to zero.
This is an implementation of the C++17 std::from_chars functions using means of C++14 and supporting strings of characters other than just char
.