【发布时间】:2015-08-03 17:02:55
【问题描述】:
是否可以在不创建临时对象的情况下分配对的成员?
#include <tuple>
using namespace std;
pair< bool, int > foo()
{
return make_pair( false, 3 );
}
int main()
{
int x;
bool y;
auto z = foo();
x = z.second;
y = z.first;
return 0;
}
在上面的代码中,需要 auto z 对象在剖析它之前“持有”该对,但在实际代码中创建它可能代价高昂。
【问题讨论】: