I was interested in the new modern C ++ standards. Because of this, I replaced all of my old for loops with new ranges for loops, where applicable.
I recently came across something that doesn't seem to work. Although I would have thought that it would be a simple extension of what was done. I'm just wondering if I'm missing something?
My problem: I have 2 identical vector sizes of information that store HTTP headers from one of our 3d party components. I need to loop both of these files to add headers to my http client.
I currently have code similar to the following:
auto iter1 = vec1.begin(); auto iter2 = vec2.begin(); while (iter1 != vec1.end()) { http_client.add_header(*iter1, *iter2); ++iter1; ++iter2; }
So that I can be available:
for (auto header, value : vec1, vec2) { http_client.add_header(header, value); }
I would think that then I explicitly declare that both of my vectors should have the same length, and therefore the checks can be performed automatically. but also the fact that this could be implemented in the most efficient way (after all, Iβm sure that my current code contains many hidden holes in it). not only that, but I think the multi-range declaration for the loop is much clearer.
Is there something like this already available or am I just missing the point completely?
source share