嵌套结构化绑定是否可能?
Are nested structured bindings possible?
假设我有一个
类型的对象
std::map<std::string, std::tuple<int, float>> data;
是否可以像这样以嵌套方式访问元素类型(即在范围 for 循环中使用时)
for (auto [str, [my_int, my_float]] : data) /* do something */
不,不可能。
我清楚地记得在某处读到 C++17 不允许嵌套结构化绑定,但他们正在考虑在未来的标准中允许它。虽然找不到来源。
不,他们不可能;但这是:
for (auto&& [key, value] : data) {
auto&& [my_int, my_float] = value;
}
至少接近。
假设我有一个
类型的对象std::map<std::string, std::tuple<int, float>> data;
是否可以像这样以嵌套方式访问元素类型(即在范围 for 循环中使用时)
for (auto [str, [my_int, my_float]] : data) /* do something */
不,不可能。
我清楚地记得在某处读到 C++17 不允许嵌套结构化绑定,但他们正在考虑在未来的标准中允许它。虽然找不到来源。
不,他们不可能;但这是:
for (auto&& [key, value] : data) {
auto&& [my_int, my_float] = value;
}
至少接近。