The type of 0 is int, so using auto here still causes i to be of type int. If you really wanted to, you could write:
Code:
for (decltype(numbers.capacity()) i = 0; i < numbers.capacity(); i++)
But that seems unnecessarily repetitive to me. Maybe:
Code:
auto capacity = numbers.capacity();
for (decltype(capacity) i = 0; i < capacity; ++i)
EDIT:
I might test this later to be sure, but the thought came to mind that you might be able to use generate_n with back_inserter to accomplish this:
Code:
std::generate_n(std::back_inserter(numbers),
numbers.capacity(),
[]() { return rand() % 30; });