I am trying to update a variable passed to a function with a structured binding:
#include <iostream>
#include <tuple>
#include <utility>
std::pair<int, double> func(double y)
{
return {1, 1.3+y};
}
int main() {
double y = 1.0;
auto [x, y2] = func(y);
y = y2;
std::cout << "x = " << x << ", y = " << y << '\n';
return 0;
}
Is it possible to avoid the extra assignment y = y2
and using something like
[auto x, y] = func(y); // this does not work
or
std::tie(auto x, y) = func(y); // this does not work