Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are nested structured bindings possible?

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 */ 
like image 205
Timo Avatar asked Feb 28 '18 17:02

Timo


2 Answers

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.

like image 78
bolov Avatar answered Oct 04 '22 15:10

bolov


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

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

which is close at least.

like image 27
Yakk - Adam Nevraumont Avatar answered Oct 04 '22 16:10

Yakk - Adam Nevraumont