Are nested structured bindings possible?

房东的猫 提交于 2019-12-01 13:41:43

问题


Assume I have an object of type

std::map<std::string, std::tuple<int, float>> data;

Is it possible to access the element types in a nested way (i.e. when used in ranged for loop) like this

for (auto [str, [my_int, my_float]] : data) /* do something */

回答1:


No, it is not possible.

I distinctly remember reading somewhere that nested structured bindings are not allowed for C++17, but they are considering allowing it in a future standard. Can't find the source though.




回答2:


No, they aren't possible; but this is:

for (auto&& [key, value] : data) {
  auto&& [my_int, my_float] = value;
}

which is close at least.



来源:https://stackoverflow.com/questions/49035732/are-nested-structured-bindings-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!