Sharg 1.1.2-rc.1
The argument parser for bio-c++ tools.
|
The <charconv> header from C++17's standard library. More...
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:
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.