SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
charconv

The <charconv> header from C++17's standard library. More...

+ Collaboration diagram for charconv:

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...
 

Detailed Description

The <charconv> header from C++17's standard library.

Enumeration Type Documentation

◆ chars_format

enum std::chars_format
strong

A BitmaskType used to specify floating-point formatting for std::to_chars and std::from_chars.

Enumerator
scientific 

Scientific notation, e.g. 3.991E-0003.

fixed 

Fixed number of digits for precision.

hex 

Hexadecimal notation. Ff specified in from_chars, prefix 0x,0X,x is not allowed.

general 

General use case.

Function Documentation

◆ from_chars() [1/2]

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 
)
inlinenoexcept

Parse a char sequence into an floating point value.

Template Parameters
value_typeThe type to parse the string into; Must model std::integral.
Parameters
[in]firstThe start of the string to parse.
[in]lastThe end of the string to parse.
[in,out]valueThe value to store the parsed result in.
[in]fmtThe std::chars_format that alters the behaviour of parsing.
Returns
A std::from_char_result. See detail section return value for more information.

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:

Attention
This implementation is a workaround until the function is supported by the compiler. It falls back to use the functions strto[d/f/ld] before checking the above limitations

Return value

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.

The locale issue

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.

See also
https://en.cppreference.com/w/cpp/utility/from_chars

◆ from_chars() [2/2]

template<std::integral value_type>
std::from_chars_result std::from_chars ( char const *  first,
char const *  last,
value_type &  value,
int  base 
)
inlinenoexcept

Parse a char sequence into an integral.

Template Parameters
value_typeThe type to parse the string into; Must model std::integral.
Parameters
[in]firstThe start of the string to parse.
[in]lastThe end of the string to parse.
[in,out]valueThe value to store the parsed result in.
[in]baseThe integer base of the format of the string to parse. Must be a value between 2 and 36 (inclusive).
Returns
A std::from_char_result. See detail section return value for more information.

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.

Return 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.

See also
https://en.cppreference.com/w/cpp/utility/from_chars

◆ to_chars()

template<std::integral value_type>
std::to_chars_result std::to_chars ( char *  first,
char *  last,
value_type  value,
int  base 
)
inlinenoexcept

Convert an integral into a char sequence.

Template Parameters
value_typeThe type to convert to a char sequence; Must model std::integral.
Parameters
[in]firstThe start of the range to fill.
[in]lastThe end of the range to fill.
[in,out]valueThe value to store the parsed result in.
[in]baseThe integer base of the format of the string to parse. Must be a value between 2 and 36 (inclusive).
Returns
A std::to_char_result. See detail section return value for more information.

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.

Return 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.

See also
https://en.cppreference.com/w/cpp/utility/to_chars