Is there a way to write a variant of std::tie
in c++11/1y that ties deeply into a tuple. That is, one in which tie((x,y),z) = make_tuple(make_tuple(1,2),3)
binds x, y, z
to 1, 2 and 3
, respectively as in the following example. It would be nice. Thanks.
#include <tuple>
#include <iostream>
using namespace std;
int main() {
int x, y ,z;
auto t = make_tuple(1,2);
std::tie(y,x)= t;
//std::tie((x,y),z) = make_tuple(t,3); //not working
cout << x << y << z << endl;
return 0;
}
You can go:
std::forward_as_tuple
works very similarly tostd::tie
, except that unlike it it will not rejectstd::tie(x, y)
as an argument.