The <charconv> header from C++17's standard library. More...
Classes | |
struct | std::from_chars_result |
Result type of std::from_chars. More... | |
struct | std::to_chars_result |
Result type of std::to_chars. More... | |
Enumerations | |
enum | std::chars_format { std::chars_format::scientific = 0x1, std::chars_format::fixed = 0x2, std::chars_format::hex = 0x4, std::chars_format::general = fixed | scientific } |
A BitmaskType used to specify floating-point formatting for std::to_chars and std::from_chars. More... | |
Functions | |
template<seqan3::floating_point floating_point_type> | |
std::from_chars_result | std::from_chars (char const *first, char const *last, floating_point_type &value, std::chars_format fmt=std::chars_format::general) noexcept |
Parse a char sequence into an floating point value. More... | |
template<std::integral value_type> | |
std::from_chars_result | std::from_chars (char const *first, char const *last, value_type &value) noexcept |
std::from_chars overload for integrals with default base = 10. | |
template<std::integral value_type> | |
std::from_chars_result | std::from_chars (char const *first, char const *last, value_type &value, int base) noexcept |
Parse a char sequence into an integral. More... | |
template<seqan3::floating_point floating_point_type> | |
std::to_chars_result | std::to_chars (char *first, char *last, floating_point_type value) noexcept |
std::to_chars overload for floating point via a std::stringstream for default base = 10. | |
template<std::integral value_type> | |
std::to_chars_result | std::to_chars (char *first, char *last, value_type value) noexcept |
std::to_chars overload with default base = 10. | |
template<std::integral value_type> | |
std::to_chars_result | std::to_chars (char *first, char *last, value_type value, int base) noexcept |
Convert an integral into a char sequence. More... | |
The <charconv> header from C++17's standard library.
|
strong |
A BitmaskType used to specify floating-point formatting for std::to_chars and std::from_chars.
|
inlinenoexcept |
Parse a char sequence into an floating point value.
value_type | The type to parse the string into; Must model std::integral. |
[in] | first | The start of the string to parse. |
[in] | last | The end of the string to parse. |
[in,out] | value | The value to store the parsed result in. |
[in] | fmt | The std::chars_format that alters the behaviour of parsing. |
Analyzes the character sequence [first,last) for a pattern described below. If no characters match the pattern or if the value obtained by parsing the matched characters is not representable in the type of value, value is unmodified, otherwise the characters matching the pattern are interpreted as a text representation of an arithmetic value, which is stored in value.
Floating-point parsers: Expects the pattern identical to the one used by std::strtod in the default ("C") locale, except that:
This function is workaround until the function is supported by the compiler. It falls back to use the functions strto[d/f/ld] so the return value is NOT as documented here https://en.cppreference.com/w/cpp/utility/from_chars but:
On success, std::from_chars_result::ec is value-initialized. On error, std::from_chars_result::ec is either an std::errc::invalid_argument if an illegal character or format has been encountered, or std::errc::out_of_range if parsing the value would cause an overflow. The std::from_chars_result::ptr value is always set to last.
std::from_chars is documented to be locale independent. The accepted patterns are identical to the one used by strtod in the defailt ("C") locale.
The functions strto[d/f/ld] used here are locale dependent but setting the locale manually by std::setlocale is not thread safe. So for the time being this workaround is locale dependent.
|
inlinenoexcept |
Parse a char sequence into an integral.
value_type | The type to parse the string into; Must model std::integral. |
[in] | first | The start of the string to parse. |
[in] | last | The end of the string to parse. |
[in,out] | value | The value to store the parsed result in. |
[in] | base | The integer base of the format of the string to parse. Must be a value between 2 and 36 (inclusive). |
Analyzes the character sequence [first,last) for a pattern described below. If no characters match the pattern or if the value obtained by parsing the matched characters is not representable in the type of value, value is unmodified, otherwise the characters matching the pattern are interpreted as a text representation of an arithmetic value, which is stored in value.
Expects the pattern identical to the one used by std::strtol in the default ("C") locale and the given non-zero numeric base, except that "0x" or "0X" prefixes are not recognized for base 16, and that only the minus sign is recognized (not the plus sign), and only for signed integer types of value. Digits in the range 10..35 (inclusive) are represented as lowercase or uppercase characters a..z/A...Z. The library provides overloads for all signed and unsigned integer types and char as the referenced type of the parameter value.
On success, returns a value of type from_chars_result such that ptr points at the first character not matching the pattern, or has the value equal to last if all characters match and ec is value-initialized.
If there is no pattern match, returns a value of type from_chars_result such that ptr equals first and ec equals std::errc::invalid_argument. value is unmodified.
If the pattern was matched, but the parsed value is not in the range representable by the type of value, returns value of type from_chars_result such that ec equals std::errc::result_out_of_range and ptr points at the first character not matching the pattern. value is unmodified.
|
inlinenoexcept |
Convert an integral into a char sequence.
value_type | The type to convert to a char sequence; Must model std::integral. |
[in] | first | The start of the range to fill. |
[in] | last | The end of the range to fill. |
[in,out] | value | The value to store the parsed result in. |
[in] | base | The integer base of the format of the string to parse. Must be a value between 2 and 36 (inclusive). |
Converts value into a character string by successively filling the range [first, last), where [first, last) is required to be a valid range.
value is converted to a string of digits in the given base (with no redundant leading zeroes). Digits in the range 10..35 (inclusive) are represented as lowercase characters a..z. If value is less than zero, the representation starts with a minus sign. The library provides overloads for all signed and unsigned integer types and for the type char as the type of the parameter value.
On success, returns a value of type to_chars_result such that ec equals value-initialized std::errc and ptr is the one-past-the-end pointer of the characters written. Note that the string is not NUL-terminated.
On error, returns a value of type to_chars_result holding std::errc::value_too_large in ec, a copy of the value last in ptr, and leaves the contents of the range [first, last) in unspecified state.