【发布时间】:2020-09-04 07:00:36
【问题描述】:
在以下示例中,NRVO(命名返回值优化) 按照this article 应用:
std::string f1()
{
std::string str;
return str; // NVRO applies here!
}
但是,请考虑:
task<std::string> f2()
{
std::string str;
co_return str; // Does NVRO also apply here?
}
【问题讨论】:
-
“NRVO(命名返回值优化)根据这篇文章得到保证:”文章没有说这样的话。
-
请注意,您的文章中不保证 NRVO。它甚至还有注意,尽管编译器有不同的优化能力,但并不能保证在 NRVO 示例代码之后立即应用上述优化。
-
我已经改写了这个问题。
标签: c++ optimization standards c++20 c++-coroutine