chsvlib
chsv helper source code

◆ from_chars() [2/2]

from_chars_result<CharType> Chusov::String::from_chars ( const CharType *  first,
const CharType *  last,
IntegralType &  value,
int  base = 10 
)
noexcept

Converts a string representation of an integral value to the specified integral representation.

Template Parameters
CharTypeA type of character of the string containing the integral value.
IntegralTypeAn integral type used to hold the numeric representation of data contained within the string.
Parameters
firstA pointer to the first character of the sequence representing the number to convert to IntegralType.
lastA 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]valueAn output parameter to receive the result of conversion.
baseA base for the conversion. Valid values must be from the range \(\left\[\left.2,36\right)\right.\). For bases from 2 to 9 arabic decimal ascii digit will be considered to represent the converted number in the string. For values of base greater or equal to 10, ascii latin characters will also be considered, both capital and lowercase. Unlike functions like ucpstol, from_chars does not accept 0 as base.
Returns
Returns an object of type from_chars_result with the return code and a pointer to the first character within \(\left\[\left.\textrm{first}, \textrm{last}\right)\right.\) which does not match the pattern of an integral number, 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 the minus ('-') sign of the number is accepted at the beginning of the string, and only for signed integral types of value. Other than that, the function behaves identically to the functions like like ucpstol.

If the string does not match the pattern of an integral 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 an integral 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.

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.