I have been interested in the new modern C++ standards. Because of that I have been replacing all my old for loops with the new range-based for loops where applicable.
I have recently however come up against something that does not seem to work. Although I would have thought that it would be a simple expansion on what has been done. I was just wondering if I am missing something?
My problem: I have 2 equally sized vectors of information which store HTTP headers from one of our 3d party components. I need to loop both of these to add the headers to my http client.
Currently I have code that is similar to the following:
auto iter1 = vec1.begin();
auto iter2 = vec2.begin();
while (iter1 != vec1.end())
{
http_client.add_header(*iter1, *iter2);
++iter1;
++iter2;
}
What I though might have been available:
for (auto header, value : vec1, vec2)
{
http_client.add_header(header, value);
}
I would have thought that this would then explicitly declare that both my vectors must be the same length and thus checks could be done automatically. but also that this could be implemented in the most efficient way possible (after all I am sure my current code has many hidden holes in it). not only that but I think the multi-range for loop declaration is much clearer to understand.
Is there something like this already available or am I just missing the point completely?