|
Sharg 1.2.3-rc.1
The argument parser for bio-c++ tools.
|
The <charconv> header from C++17's standard library. More...
Collaboration diagram for std:Functions | |
|
template<typename value_type > requires std::is_floating_point_v<value_type> | |
| to_chars_result | sharg::contrib::charconv_float::to_chars_floating_point (char *first, char *last, value_type value) noexcept |
| std::to_chars implementation for floating point via a std::stringstream for default base = 10. | |
|
template<typename value_type > requires std::is_floating_point_v<value_type> | |
| from_chars_result | sharg::contrib::charconv_float::from_chars_floating_point (char const *first, char const *last, value_type &value, chars_format fmt=chars_format::general) noexcept |
| Delegates to functions strto[d/f/ld] for floating point value extraction. | |
|
template<typename floating_point_type > requires std::is_floating_point_v<floating_point_type> | |
| to_chars_result | sharg::contrib::charconv_float::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<typename floating_point_type > requires std::is_floating_point_v<floating_point_type> | |
| from_chars_result | sharg::contrib::charconv_float::from_chars (char const *first, char const *last, floating_point_type &value, chars_format fmt=chars_format::general) noexcept |
| Parse a char sequence into an floating point value. | |
The <charconv> header from C++17's standard library.
The following table describes what implementation of std::to_chars and std::from_chars will be used
| stdlib version | __cpp_lib_to_chars | chars_format | to_chars_result | from_chars_result | to_chars (int) | from_chars (int) | to_chars (float) | from_chars (float) |
|---|---|---|---|---|---|---|---|---|
| gcc 10 | undefined and <charconv> header | stdlib | stdlib | stdlib | stdlib | stdlib | shim (ostringstream) | shim (strto[f/d/ld]) |
| gcc 11 | undefined (or 201611) and <charconv> header | stdlib | stdlib | stdlib | stdlib | stdlib | stdlib | stdlib |
Note: gcc 11 implements float too, but does not define __cpp_lib_to_chars
|
inlinenoexcept |
Parse a char sequence into an floating point value.
| floating_point_type | The type to parse the string into; Must model std::is_floating_point_v. |
| [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:
On success, std::from_chars_result::ec is value-initialized and std::from_chars_result::ptr points at the first character not matching the pattern. If no characters match the pattern, std::from_chars_result::ec is std::errc::invalid_argument and std::from_chars_result::ptr is set to first. If the parsed value is not representable in the type of value, std::from_chars_result::ec is std::errc::result_out_of_range and std::from_chars_result::ptr points at the first character not matching the pattern.
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.