Is there a way to std::move std::string into std::stringstream
I do not see a
std::stringstream
constructor accepting rvalue reference ofstd::string
That's right. Even the str
setter doesn't utilize move semantics, so moving a string into stringstream
is not supported (not in the current standard, but hopefully in the next one).
You'll be able to move a string into a string-stream in C++20.
Move semantics are supported by the constructor:
std::string myString{ "..." };
std::stringstream myStream{ std::move(myString) };
It can also be done after construction by calling str()
:
std::string myString{ "..." };
std::stringstream myStream;
myStream.str(std::move(myString));