C++ Logo

std-discussion

Advanced search

Re: add version of std::stoi, std::stol etc that receive std::string_view

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 01 Sep 2020 12:35:20 -0700
On Tuesday, 1 September 2020 08:16:56 PDT Jason McKesson via Std-Discussion
wrote:
> Also, we already have `to_chars` and `from_chars`, which are quite
> fast and do not allocate memory. We've had them since C++17 (though
> standard library implementations took a while).

But they are not the same. std::stoi for example handles base = 0 and
interpreting the prefixes, as it's defined to do the same as strtol does.
std::from_chars, however, does no prefix interpretation and therefore requires
a non-zero base.

This discrepancy is slightly annoying. It moves a set of functions that would
be really useful to the column of "cumbersome to use". Since stoi does the
same as strtol, what's the value?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2020-09-01 14:38:52