Suppose I have 2 (or more) containers I want to iterate through simultaneously - for example, to compute the dot product of two vectors:
std::vector<double> vector1;
std::vector<double> vector2; // identical size to vector1
What is the preferred C++11 way to specify a range-for loop over both (or all) containers simultaneously? Does it involve choosing one container/iterator to write short-hand (i.e. for ( auto i : c )) in a range-for loop, while all other containers/iterators have to be handled long-hand? Is there any reason the syntax in future could not be extended to support short-hand for both/all containers as shown below... which seems really readable:
double dotProduct( 0.0 );
for ( auto const & value1 : vector1, auto const & value2 : vector2 ) // illegal!
{
dotProduct += value1*value2;
}
for ( i=0, j=0, k=0; i < N; i++, j++, k++ )(and still can write it), which is extraordinarily succinct. Why has the comma operator not been extended to allow multiple variable declaration inside the for loop - 1 is permitted, but why only 1?