Given two vectors of different types but same length, what should be the type of the index to iterate over both in sync?
Consider the following code:
#include <iostream>
#include <string>
#include <vector>
int main(void)
{
std::vector<std::string> words = {"foo", "bar"};
std::vector<double> values = {42, 314};
std::vector<std::string>::size_type i = 0;
std::vector<double>::size_type j = 0;
while (i < words.size() && j < values.size()) {
std::string w = words[i];
double v = values[j];
// do something with w and v
++i;
++j;
}
return 0;
}
If I wanted to use a single index, say i
, to iterate over both words
and values
, what should be its type? Should it be size_t
?