I've seen some people talk about the new abstraction of C++17 in for ranged loops, where one can use multiple iterators/values/references:
for(auto&& [output1, output2] : container)
{...}
I've been trying to find an explanation on Google for it, unsuccessfully, since I believe I'm not using the right terminology. In any case I'd be happy if somebody had a link to the cppreference, as well as answer these questions:
1. Are we using "&&" because [output1, output2]
as a whole is an rvalue?
2. Let's assume that output1
and output2
are both of type int
. What is the type of "auto"? In other words, what kind of (rvalue?) object is [output1, output2]
, in case I wanted to not use "auto" and declare it specifically? (Maybe a tuple?)
3. What is happening under the hood? Are two iterators being used behind the scenes (see below)? What would be the non C++17 implementation using real iterator objects?
for(Container::iterator it1 =..., Container::iteratorit2 = ...; it1!=..., it2!=...; ++it1, ++it2)
{...}