Consider the following code example :
#include<iostream>
#include<vector>
#include<typeinfo>
int main(){
std::vector<int> v = {1 ,2,4};
for(auto &i:v) std::cout<<typeid(i).name();
for(auto k = v.begin(); k!=v.end();++k) std::cout<<typeid(k).name();
return 0;
}
The first loop represents range based for-loops , and second one are regular for loops with iterators. I have used regular ones a lot , and from my experience , auto k is of type of iterator , while range based loops had type of auto i as int. Output of above program is:
i & N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEE
Is this normal behavior for range based for loops over collections like vectors ( somewhere mentioned) ? Because someone (like me) would assume range based for loops are just shorthand for regular for loops.