是否可以将现有的变量用作与structured bindings
相关的返回值的目标?
auto f()
{
return std::make_tuple(1,2.2);
}
int main()
{
int x;
double z;
[ x, z ] = f(); // Did not work in gcc 7.1
// structured bindings only work with "new" vars?
auto [a, b] = f(); // works fine
}
答案 0 :(得分:6)
如果您想使用现有变量,那么您可以std::tie
。
std::tie(x, z) = f(); // only works with tuples however
结构化绑定引入了新标识符。不幸的是,对于一般聚合,没有任何内容等同于std::tie
。