Be very careful with std::tie. Returning a is tielogically equivalent to returning a link with all the caveats that come with it.
Logically, these three are equivalent:
int& foo();
std::reference_wrapper<int> foo();
std::tuple<int&> foo();
and this:
int a = 10;
return std::tie(a);
equivalent to this:
int a = 10;
return std::ref(a);
because it returns one of the following values:
std::tuple<int&>
. auto :
#include <iostream>
#include <tuple>
using namespace std;
auto return_tuple1() {
int a = 33;
int b = 22;
int c = 31;
return tie(a, b, c);
}
auto 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();
std::get<0>(a);
std::get<0>(b);
return 0;
}