Named Return Value Optimization (NRVO) 是一种编译器优化技术,可以避免在函数返回时创建临时对象和调用拷贝构造函数。它的条件是函数返回的对象有一个名字,而且和目标对象的类型相同。例如:
class A {
public:
A();
A(const A&);
};
A f() {
A a; // a is a named object
return a; // NRVO may apply
}
int main() {
A x = f(); // x is constructed directly from a
}
标签:Named,Return,对象,Value,NRVO,Optimization
From: https://www.cnblogs.com/asagi/p/17429054.html