[英]Is there a way to std::move std::string into std::stringstream
In the c++ reference I do not see a std::stringstream
constructor accepting rvalue reference of std::string
.在C ++引用我没有看到
std::stringstream
构造函数接受的右值引用std::string
。 Is there any other helper function to move string to stringstream without an overhead or is there a particular reason behind making such limitation?是否有任何其他辅助函数可以在没有开销的情况下将字符串移动到字符串流,或者是否有特殊原因进行这种限制?
I do not see a
std::stringstream
constructor accepting rvalue reference ofstd::string
我没有看到
std::stringstream
构造函数接受std::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).甚至
str
setter 也不使用移动语义,因此不支持将字符串移动到stringstream
中(不在当前标准中,但希望在下一个标准中)。
You'll be able to move a string into a string-stream in C++20.您将能够在 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()
:也可以在构造后通过调用
str()
来完成:
std::string myString{ "..." };
std::stringstream myStream;
myStream.str(std::move(myString));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.