C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 11 Jan 2025 13:41:09 -0300
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.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-01-11 16:41:18