xml*_*lmx 7 c++ rvalue-reference move-semantics rvo c++11
#include <vector>
using namespace std;
struct A
{
A(const vector<int>&) {}
A(vector<int>&&) {}
};
A f()
{
vector<int> coll;
return A{ coll }; // Which constructor of A will be called as per C++11?
}
int main()
{
f();
}
Run Code Online (Sandbox Code Playgroud)
是coll一个xvalue在return A{ coll };?
返回A(vector<int>&&)时是否会调用C++ 11保证f?
Nic*_*las 11
C++ 11不允许coll移动.它只允许在return语句中隐式移动return <identifier>,其中<identifier>是局部变量的名称.任何比这更复杂的表达都不会隐式移动.
而比这更复杂的表达不会经历任何形式的省略.
| 归档时间: |
|
| 查看次数: |
496 次 |
| 最近记录: |