Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 标准库类型的赋值运算符的ref限定符_C++_Stl_Assignment Operator_C++ Standard Library_Ref Qualifier - Fatal编程技术网

C++ 标准库类型的赋值运算符的ref限定符

C++ 标准库类型的赋值运算符的ref限定符,c++,stl,assignment-operator,c++-standard-library,ref-qualifier,C++,Stl,Assignment Operator,C++ Standard Library,Ref Qualifier,我想知道,标准类型的赋值运算符不符合左值ref条件有什么原因吗?他们都不是 因此,我们可以这样写: std::string{} = "42"; std::string s = "hello " + std::string{"world"} = "oops!"; std::vector<int> v = { 1,2,3 }; std::move(v) = { 4,5,6 }; std::string{}=“42”; std::string s=“hello”+std::string

我想知道,标准类型的赋值运算符不符合左值ref条件有什么原因吗?他们都不是

因此,我们可以这样写:

std::string{} = "42";
std::string s = "hello " + std::string{"world"} = "oops!";

std::vector<int> v = { 1,2,3 };
std::move(v) = { 4,5,6 };
std::string{}=“42”;
std::string s=“hello”+std::string{“world”}=“oops!”;
向量v={1,2,3};
std::move(v)={4,5,6};
如果赋值运算符是左值ref限定的,则所有这些示例都不会编译

是不是因为有很多东西需要修改(但noexcept也是如此),而且没有人为其编写提案?我不认为人们会编写这样的代码,但库的设计是否应该使它甚至不允许这样做呢?

你的建议被拒绝了,并最终在当年的法兰克福被拒绝

这将是一个突破性的变化,我们不喜欢这些

现有的禁止为内置类型的右值赋值的禁令实际上只具有有限的实际价值,因此可能破坏现有代码的成本是有限的


如果我们一清二楚,图书馆是否会以这种方式设计?也许吧。

Bah,把它擦掉,等6年,然后杀了它。99/100的使用将成为bug。我明白了。但它会打破什么呢?“除了一些利基案例还有什么吗?@MariusBancila不,差不多就是这样,亚当是对的。但仍然如此。在我看来,这似乎是一个完美的候选人,“我们当时认为这不值得接下来几年发生的意外灾难”的情况。我想,不要修复那些没有完全损坏的东西。