C++ Logo

std-proposals

Advanced search

Re: [std-proposals] string_view support for std::stoi and friends

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Sat, 11 Jan 2025 17:06:26 +0000
On 11 January 2025 16:41:09 GMT, Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> wrote:
>On Saturday 11 January 2025 12:43:59 Brasilia Standard Time Jonathan Wakely
>via Std-Proposals wrote:
>> The original reason for requiring a std::string is that stoi etc are
>> defined in terms of strtoll which requires a null terminated string. A
>> string_view isn't null terminated.
>>
>> The functions would need to be re-specified in terms of std::from_chars.
>
>They can be specified as "behave exactly like strtoll" and not require null
>termination. The difference is mostly the handling of what comes before the
>number: the base prefixes when base == 0, whitespace and the plus sign.

strtoll is also technically locale-dependent, but I don't know what that means in practice. In what locales (if any) is the behavior different?

Lénárd

Received on 2025-01-11 17:06:32