结构化帮绑定可以作用于3中类型
一、原生数组类型

结果:

备注:绑定到原生数组所需条件仅仅是要求别名的数量于数组元素的个数一致,这里的x,y,z分别绑定到a[0],a[1],a[2]
二、绑定到结构体和类对象


结果:

条件:
1.类或者结构体中的非静态数据成员个数必须和标识列表中的别名个数相同
2.这些数据成员必须是公有的。
3.这些数据成员必须是同一个类或者基类中
4.绑定的类和结构体中不能存在匿名联合体
三、绑定到元组和类元组的对象


结果:

int main()
{
//3.绑定到一个std::pair
std::map<int, string> maptest{ {1,"aaa"},{2,"bbb"},{3,"cccc"} };
for (auto &item:maptest)
{
printf("%d-%s\n",item.first,item.second.c_str());
}
cout << "-----------------\n";
for (auto&[id,str]:maptest)
{
printf("%d-%s\n",id,str.c_str());
}
system("pause");
return 0;
}
结果:


















![[Everything] 文件搜索工具的下载及详细安装使用过程(附有下载文件)](https://i-blog.csdnimg.cn/direct/05ec5519d3944e5c9f0d51bbabf0e679.png)

