为什么我不能传递一个值的价值std :: stringstream到函数? [英] Why can't I pass an rvalue std::stringstream by value to a function?
问题描述
为什么此代码无法编译?
Why does this code not compile?
#include <sstream>
void f(std::stringstream) { }
int main() {
f(std::stringstream{});
}
我收到此错误:
error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
f(std::stringstream{});
^
如果我替换 std :: stringstream
与不可复制的另一种类型它工作正常。不应该使用 stringstream
的移动构造函数?
If I replace std::stringstream
with another type that's noncopyable it works fine. Shouldn't this use stringstream
's move constructor?
推荐答案
缺少 stringstream
的移动构造函数是一个已知缺少的在GCC实现的C ++标准库。如果我正确地阅读对该报告的评论,它是故意缺少,因为它将依赖于其他更改,那些其他更改将打破ABI,所以GCC的人已经选择了打破ABI只有一次(如果可能),而时间尚未到来。
The missing move constructor for stringstream
is a known missing feature in GCC's implementation of the C++ standard library. If I'm reading the comments on that report correctly, it is intentionally missing because it would rely on other changes, and those other changes would break the ABI, so the GCC folks have chosen to break the ABI only once (if possible), and that time has not yet come.
这篇关于为什么我不能传递一个值的价值std :: stringstream到函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!