【发布时间】:2017-04-16 07:10:49
【问题描述】:
This code compiles 但我想知道应该首选哪个版本:
#include <iostream>
#include <tuple>
using namespace std;
tuple<int, int, int> return_tuple1() {
int a = 33;
int b = 22;
int c = 31;
return tie(a, b, c);
}
tuple<int, int, int> return_tuple2() {
int a = 33;
int b = 22;
int c = 31;
return make_tuple(a, b, c);
}
int main() {
auto a = return_tuple1();
auto b = return_tuple2();
return 0;
}
由于该函数按值返回一个元组,因此使用std::tie 应该没有任何问题,对吧? (即没有悬空引用)
【问题讨论】: