C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Optimise stringstream to plunder a string

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 15 Dec 2022 12:39:11 +0000
Hi,

On 15 December 2022 12:14:22 GMT, Pavel Vazharov via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> I think istringstream should have an optimised method to assimilate an
>> Rvalue string:
>>
>> We have such constructor already -
>https://en.cppreference.com/w/cpp/io/basic_istringstream/basic_istringstream
>(6)
>
>This code compiles and the program returns 1.
>
>#include <string>
>#include <sstream>
>
>int main()
>{
> std::string str = "this is a very long string";
> std::istringstream sstream(std::move(str));
> return str.empty();
>}

The `str() &&` overload is also notable, so you can move out the string from a stringstream as well.

Cheers,
Lénárd

Received on 2022-12-15 12:39:15