This code compiles但我不知道哪个版本应该是首选:的std ::领带VS的std :: make_tuple
#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
对? (即没有悬挂参考)
也'的std :: make_tuple'更好地表达代码的意图。如果我看到调用'std :: tie'的代码,然后将它存储在一个'tuple'中,我可能会认为这是一个错误。 – SirGuy