最近在学刷题,看到了一个题解上出现了这种形式,实在不理解

auto [m,n] 这是什么意思呀,我只知道auto是自动类型,但这种用法我真的是第一次见,头都大了。我查了一些资料,好像是C++11的用法

C++ 17, Structured binding declaration ,例如以下代码:

int a[2] = {1,2};
 
auto [x,y] = a;

参考: Structured binding declaration (since C++17)

这算什么写法?即使auto代表某种未确定类型,那这个[m,n]好像也不好理解啊

class Solution
{
public:
void wallsAndGates(vector<vector>& rooms)
{
const int INF = 2147483647;
int Row = rooms.size();
if (Row == 0) return ;
int Col = rooms[0].size();
/////////// 多源BFS
queue<tuple<int, int, int>> Q;
for (int r = 0; r < Row; r ++)
{
for (int c = 0; c < Col; c ++)
{
if (rooms[r][c] == 0)
{
//Q.push(tuple<int,int,int> {r, c, 0}); //写起来麻烦,但是清晰
Q.emplace(r, c, 0);
}
}
}
while (Q.size())
{
auto [r,c,dist] = Q.front(); Q.pop(); ???
for (auto [dr,dc] : vector<pair<int,int>>{{0,1}, {1,0}, {0,-1}, {-1,0}})
{
int nr = r + dr;
int nc = c + dc;
if (0 <= nr && nr < Row && 0 <= nc && nc < Col && rooms[nr][nc] == INF) //是个空的房间
{
rooms[nr][nc] = dist + 1;
//Q.push(tuple<int,int,int>{nr, nc, dist + 1}); //写起来麻烦,但是清晰
Q.emplace(nr, nc, dist + 1);
}
}
}
}
};