C++ Logo

std-proposals

Advanced search

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

From: tzsz <writing.segfaults_at_[hidden]>
Date: Mon, 13 Jan 2025 21:33:14 +0100
Is std::from_chars significantly faster than stoi?

Am 13.01.25 um 21:30 schrieb Tiago Freire via Std-Proposals:
>
> > > Isn't <charconv> already locale independent?
> > > In what way after C++17 would stoi not be obsolete?
>
> > Seriously?
>
> > Because std::stoi(function_returning_string()) is much simpler than:
>
> > auto str = function_returning_string();
>
> > int i;
>
> > if (auto [ptr, ec] = std::from_chars(str.data(),
> str.data()+str.size(), i); ec)
>
> I’m going to double down on this.
>
> Looks simpler, takes longer.
>
> If you insist having it a one liner, just wrap it up in a function,
> you would still be saving a lot of time.
>
>

Received on 2025-01-13 20:33:18