让我们考虑下一个示例:
struct big_type {};
// Return by copy
auto factory() { return big_type{}; }
void any_scope_or_function() {
big_type&& lifetime_extended = factory();
}
在假设 RVO 被禁止或根本不存在并且以任何方式存在的情况下,是否会或可以big_type()
复制?还是将引用直接绑定到return
语句中构造的临时变量?
我想确保在结束big_type
时只调用一次析构函数any_scope_or_function
。
我使用 C++14,以防标准版本之间的某些行为发生了变化。