C++ Logo

std-proposals

Advanced search

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

From: Jeremy Rifkin <rifkin.jer_at_[hidden]>
Date: Mon, 13 Jan 2025 15:15:42 -0600
> Not saying that you can’t do that. But the standard is big enough as it
is, you don’t need to duplicate the same algorithms to the same thing in a
different way.

You can use from_chars, but this is such a simple and common task there
should be an easy way to do it without having to work around string_view
ergonomics issues.

This is a simple one-liner in just about every other language, it would
look silly if the idiomatic solution in C++ was dealing with from_chars.

Cheers,
Jeremy

On Mon, Jan 13, 2025 at 14:59 Tiago Freire via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> > Why not change std::stoi to be that one-liner, which is almost what's
> being proposed?
>
>
>
> Not saying that you can’t do that. But the standard is big enough as it
> is, you don’t need to duplicate the same algorithms to the same thing in a
> different way.
>
>
>
> <charconv> already covers almost all cases, you can use it with a view, it
> covers more int types than stoi/stoull family does, it covers floats.
>
> The only thing that it doesn’t cover as a use case is buffer size
> estimates (which nothing in the standard does).
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-01-13 21:15:55